The Light Sensor Tracking a line Richard McMullin fllcoach.broadacres@gmail.com Oakville Robotics Symposium 22-Oct-2011 Introduction – Richard McMullin › Leader in IT • • • › Entrepreneur • • › 4th year coaching FLL Tournaments: Toronto West, Provincial Championships FRC Volunteer • • 2 Started several technology companies Finance, Medicine FLL Coach • • › Engineer, University of Waterloo – Systems Design Technical Leader at National Bank of Canada Changing hearts and minds to improve effectiveness of over 300 people Tournament setup Field Referee Oakville Robotics Symposium – The Light Sensor 22-Oct-2011 Agenda 1. Attaching the light sensor(s) a. b. 2. Testing the light sensor a. 3. 3 Left right method Program Tracking a line a. b. 6. Programming blocks that use the light sensor Stopping on a line – Program Walking a line a. b. 5. Built-in program on the robot Controlling the light sensor a. b. 4. Placement on the Robot Attaching to the ports (default port 3) Line tracking method Program Questions Oakville Robotics Symposium – The Light Sensor 22-Oct-2011 Attaching the light sensor › Light Sensor Placement on the Robot • • • • • › Attaching to the Ports • • 4 Facing down towards the mat Better if forward of the wheels (for steering) Allow a gap for the light to be reflected (not touching the mat) Place somewhere stable (consistent readings) Place somewhere protected (avoids contact and external light sources) Default port is port 3. Any port can be used, but always check that the program is set for the correct port. Oakville Robotics Symposium – The Light Sensor 22-Oct-2011 Testing the light sensor › Built in testing • • › Programs exist on the Robot to test the attached light sensor But they just make sounds Here is a program to show the light sensor value White value = 60 Black value = 34 5 Oakville Robotics Symposium – The Light Sensor 22-Oct-2011 Controlling the light sensor › 6 Programming blocks that use the light sensor • Read the light sensor • Wait for a light sensor value Oakville Robotics Symposium – The Light Sensor • Branch on a light sensor • Loop until a light sensor value 22-Oct-2011 Program Example – stopping on a line › Steps in the program • • • 7 Go forward forever Wait until the line is detected Stop Oakville Robotics Symposium – The Light Sensor 22-Oct-2011 Program Example – Walk a line › Steps in the program • • › 8 If the sensor senses white, steer to the right If the sensor senses black, steer to the left Bounded unstable program Oakville Robotics Symposium – The Light Sensor 22-Oct-2011 Advanced – Track a line › General idea • • • • › Math • • • Assume the following values: Black: 36, White 60. Ideal ‘grey’ value is (60+36)/2 = 48 • In order to find out the amount to steer, take the current sensor value and subtract it from the ideal ‘grey’ value. Steering value = 48 – sensor value Max white steering = 48 – 60 = - 12 (left turn) Max black steering = 48 – 36 = + 12 (right turn) Grey steering = 48 – 48 = 0 (go straight) • • • • 9 Track along the ‘grey’ value between black and white. Use the difference between the current value and the ideal ‘grey’ value to tell the robot how hard to turn. The more ‘white’ the value is, the harder you steer to the left The more ‘black’ the value is, the harder you steer to the right. Oakville Robotics Symposium – The Light Sensor 22-Oct-2011 Advanced – Track a line › The simple program Read the light sensor 10 Subtract from 48 Use the result to set the steering Oakville Robotics Symposium – The Light Sensor 22-Oct-2011 Program Example – Track a Line › Use additional math blocks to set the sensitivity of the turning. • • • • 11 Whole number math only available with multiplication and division In order to multiply by .75, multiply by 3 then divide the result by 4. Always do the multiplication first to keep the highest accuracy Use a second light sensor to stop the walk along the line Oakville Robotics Symposium – The Light Sensor 22-Oct-2011 Questions › Contact Info: › › Richard McMullin fllcoach.broadacres@gmail.com 12 Oakville Robotics Symposium – The Light Sensor 22-Oct-2011