3 Minute Line Follower - The Roboticist · The single sensor line follower uses a ‘Z’ pattern...

27
3 Minute Line Follower Saturday, September 8, 12

Transcript of 3 Minute Line Follower - The Roboticist · The single sensor line follower uses a ‘Z’ pattern...

3 Minute Line Follower

Saturday, September 8, 12

Saturday, September 8, 12

Saturday, September 8, 12

Saturday, September 8, 12

LEGO NXT MOTORSInstructing the robot to move and turn is accomplished by the NXT motors, which rotate in a predetermined direction.

B"#"Motor!

C"#"Motor!

Note: the LEGO NXT motors are a combination of motor and rotation sensor. Try avoiding turning the axel plate to much by hand, as not to damage the rotation sensor long-term.

Saturday, September 8, 12

Moving a LEGO robotNXT Motors have a built-in rotation Sensors that continuously measures and monitors the

number of degrees /rotations where it is moving forward or backwards.

You can manipulate the motors using the MOTOR, MOVE and ROTATION SENSOR Blocks

MOTOR BLOCKControls one motor No SynchronizationNo Acceleration

MOVE BLOCKControls 2 motors Synchronize motor

movement to ensure robot moves straight

Automatically corrects errors

Applies power gradually (accelerate)

Slows down (decelerate)

ROTATION SENSOR BLOCK

Counts the number of motor degrees (one full rotation is 360 degrees) that your motor turns.

Used to reset the rotation counter to 0.

Saturday, September 8, 12

Turning a Robot

• Understanding how to turn a robot in a precise manner is key to navigating a course accurately.

• Knowing the motor rotation values in degrees for your wheel type and robot for 90 degree, 180 degree turn are critical in being successful.

• Two methods: the math method (see earlier slides) and the experimental method.

Saturday, September 8, 12

Turns versus SpinTo make 180 degree right turn using a single motor

Start Position End Position

To make 180 degree right turn using two motors (spin in place)

End PositionStart Position

B

B

B

B C

C

C

C

Note the distance travelled is shorter (exactly half) when using both two motors.

Saturday, September 8, 12

Turning a robot

B C

ExperimentalB Turning ratio tool: Create a board with a solid line and a dashed line on it as shown below. Position the Robot so that the axels of the drive wheels are aligned with the solid line and the inside turn wheel is at the intersection of the dashed and solid line.

Now program the robot to make a turn using just ONE motor block - in this case MOTOR “B” - start with say 180 degrees for the rotation value, observe and increase/decrease until you achieve the right turn.

Repeat the test a few times, to ensure it is consistent.

Saturday, September 8, 12

Turning a RobotB

C

B

C

Pivot Turn

Gentle Turn

Note: put a stop motor block after the turn to make sure both motors complete the pivot fully and in ‘sync’

Saturday, September 8, 12

Light Sensor Value Test Program

Saturday, September 8, 12

Light Value ReaderTo easily learn the various light sensor values on the course, you can use a simple program like this to display the light sensor reading on a scale of 0% - 100% - where 0% is black and 100% is white

Saturday, September 8, 12

Black Line Detection

Saturday, September 8, 12

Black Line DetectionThe ability to locate a black line on a course, can be very useful, as to then use this line to more accurately maneuver to an object.

The robot will drive forward using both motors “B” & “C” using a LOOP. The loop will terminate when it detects ‘black’ (the line). Both motors have their duration set to ‘infinity - unlimited’ in effect meaning they move forward in a very small increment. This causes the loop many times per second to read the light sensor, and make it seem as the robot is smoothly following its path.

LOOPLight SensorLoop Control

Amount of light (or lack there of) triggering a ‘black line’ event

Loop control set to Sensor -- light sensor in this case

Saturday, September 8, 12

Line FollowerSingle Sensor Line Follower

Saturday, September 8, 12

Black line

B&W Sensor

The single sensor line follower uses a ‘Z’ pattern to hug the outside of the black line it tries to follow. The robot is in essence continuously turning into and away from the line.

Saturday, September 8, 12

The line following program is relatively simple and consists of three key elements:

1 -- a infinite drive control loop2 -- a switch statement using a light sensor to detect black3 -- a two motor control block to either turn left or right

There are various ways to influence the ‘Z’ pattern:1 -- drive motor ‘b’ and ‘c’ in opposite directions rather then one stopped2 -- vary the motor speed3 -- placement of sensor further or closer to the robots natural pivoting point

Saturday, September 8, 12

The light sensor is set to detect black -- a typical good sensitivity setting is 40% or less

The motors are set to unlimited and typical motor power is set to 75% for the driving motor

Saturday, September 8, 12

Black Line DetectionStep 9: -- Follow black line, ensure we do not get stuck in ‘crossing line’ by driving just towards it using rotation sensor to measure distant travelled

Reset rotation sensor for clean count from Zero

Control loop with rotation sensor, when reaching 320 degrees of motor axel travel, break form loop.

Saturday, September 8, 12

Line FollowerTwo Sensor Line Follower

withAbility to stop on ‘T’ intersection

Saturday, September 8, 12

! ! ! !

L - Black R - WhiteL - White R - White L - Black R - BlackL - White R - Black

1. 2. 3. 4.

There are 4 potential scenarios of the line following two sensor robot

Saturday, September 8, 12

!

Saturday, September 8, 12

Light Sensor on the left is connected to port #1Light Sensor on the right is connected to port #2

Drive onto the line out of the ‘starting box’

Saturday, September 8, 12

Stop Line Following - Special ConditionBoth Sensor read BLACK

1 -- Set a semaphore flag -- Set FALSE

2 -- Set a semaphore flag to TRUE if special condition occurs. In this case a black cross line (detecting a ‘T’) both sensors see black.

3 -- If semaphore is TRUE - break out of line following loop

Saturday, September 8, 12

Simple Color ReaderDetecting Colors and using it to control your Robot

Saturday, September 8, 12

Trick: Build a simple little program like below and read out the color values as the sensor detects them.

The following Color Values will be transmitted on the Detected Color data port:

1 – Black

2 – Blue

3 – Green

4 – Yellow

5 – Red

6 – White

These Numeric values can then be used to create switch conditions of our switch and allow us to execute different code based on which color we have detected.

Saturday, September 8, 12

Note: The switch Statement has ‘flat view’ un-checked

In this case the switch statement has multiple path’s based on the color number transmitted by the sensor. So for example if it sees green it will do one action, if it sees red an other etc

Saturday, September 8, 12