CxD Archive
Code: Robotics
Code: Robotics
  • Code Introduction
  • TUTORIALS
    • A. Meet Your Robot
      • A-1 Circuit Board
      • A-2 Motors and Wheels
      • A-3 Other Components
    • B. Hello World Test
      • B-1 Arduino Code Editor
      • B-2 New App Template
      • B-3 Global Variable
      • B-4 Setup Function
      • B-5 Loop Function
      • B-6 Upload App to Robot
      • B-7 Add Sound
      • B-8 Use Button
    • C. Driving and Turning
      • C-1 Driving
      • C-2 Turns (Pivoting)
      • C-3 Test Wheel Encoders
      • C-4 Drive for Specific Distance
      • C-5 Pivot By Specific Angle
      • C-6 Drive Straight Continuously
    • D. Detect Objects in Path
      • D-1 Test Mechanical Bumpers
      • D-2 Detect Collisions
      • D-3 Test Ultrasonic Sensor
      • D-4 Avoid Collisions
    • E. Detect Lines on Surface
      • E-1 Test IR Line Sensors
      • E-2 Follow Line
      • E-3 Avoid Line
      • E-4 Count Lines Crossed
      • E-5 Follow and Count Lines
    • F. Detect Other Conditions
      • F-1 Detect Surface Drop-Off
      • F-2 Test Accelerometer
      • F-3 Detect If Upside-Down
      • F-4 Detect If Bumped
  • REFERENCES
    • Arduino Language
    • Arduino Code Editor
      • Create New App
      • Save and Rename App
      • Include RedBot Library
      • Verify App Code
      • Upload App to Robot
      • Download Copy of App
      • Use Serial Monitor to View Data
      • Robot Demo App Template
    • Physical Inputs
      • Push Button (D12)
      • Mechanical Bumpers
      • IR Line Sensors
      • Wheel Encoders
      • Accelerometer
      • Ultrasonic Sensor *
    • Physical Outputs
      • LED Light (D13)
      • Speaker (Buzzer)
      • Motors
    • Robot Behaviors
      • Producing Alerts
      • Driving
      • Turning
      • Detecting Objects
      • Detecting Lines
      • Detecting Other Conditions
    • Navigation Modes
      • Distance Navigation
      • Line Counting Navigation
      • Line Following + Counting Navigation
      • Autonomous Navigation
  • LINKS
    • Robotics Project Guidebook
    • Arduino Create Web Editor
    • Arduino Language Reference
    • RedBot Experiment Guide
  • ELEGOO Experiments
    • Getting the Arduino IDE
    • Starting with the `techCar` Template
    • Template Code for techCar.ino
    • Template Experiments
    • Reinstall the Original Remote App Functionality, If Needed
Powered by GitBook
On this page
  • Example Task Scenario
  • Example Code
Export as PDF
  1. REFERENCES
  2. Navigation Modes

Line Counting Navigation

PreviousDistance NavigationNextLine Following + Counting Navigation

Last updated 6 years ago

When using line counting navigation, the robot drives straight while counting line markers it crosses, and then turns at a specific line number to start driving on a new path. The robot's path is programmed as an ordered sequence of specific line counts and turns.

  • ADVANTAGE: You only have to place line markers for stops or turns along a path (instead of the entire path).

  • DISADVANTAGE: The robot can only stop or turn at a line marker. The robot's turns may not be perfectly accurate every time. If the robot were to get too far off-course from its intended path, it might not drive over the line markers (and won't detect them).

Line counting navigation is similar to the directions that a person might give you to get to a destination in a city (such as "Go straight for two more blocks. Then turn left...").

Example Task Scenario

In this task scenario, a store robot will navigate through the store aisles (red rectangles are cardboard boxes representing store shelves) to a specific location (Shelf B in Aisle 2), deliver a box of items to be stocked (simulated step), and then drive back to the stockroom (labeled as "Start"). The black lines and "plus signs" are line markers that the robot will use for navigation.

For the purposes of the demonstration, the distances traveled are much shorter than what would be required in an actual store environment.

Example Code

Here is a possible way to code a custom function to perform this task scenario:

void task1() {
  // Example of Line Counting Navigation

  // Deliver box to Shelf B in Aisle 2, and return to start

  // drive from Start to Aisle 2
  countLine(2); // Start line + lower right line (Aisle 0)
  pivotAngle(-90); // turn left
  countLine(2); // Aisle 1 line + Aisle 2 line

  // drive to Shelf B
  pivotAngle(-90); // turn left
  countLine(2); // A line + B line
  pivotAngle(-90); // turn left to face Shelf B

  // Simulated Step: deliver box of items to be stocked
  pauseRobot(); // wait until button pressed

  // return to Start
  pivotAngle(-90); // turn left to exit Aisle 2
  countLine(2); // A line + Aisle 2 line
  pivotAngle(90); // turn right
  countLine(2); // Aisle 1 line + lower right line
  pivotAngle(90); // turn right
  countLine(1); // next line is Start
  pivotAngle(180); // turn around
  doubleBeep();

  // at end of this task, reset for next task
  started = false;
  nextTask = 2;
}