SlidePub
Home
Categories
Login
Register
Home
Technology
Robotics ES MS 222 Practice Presentation.pptx.pptx
Robotics ES MS 222 Practice Presentation.pptx.pptx
pehej35441
6 views
60 slides
Oct 23, 2025
Slide
1
of 60
Previous
Next
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
About This Presentation
robotics
Size:
2.09 MB
Language:
en
Added:
Oct 23, 2025
Slides:
60 pages
Slide Content
Slide 1
MES ROBOTICS UNIT 6: ADVANCED PROGRAMMING This lesson uses SPIKE 3 software
Slide 2
MOVING OBJECTS & STALL DETECTION This lesson uses SPIKE 3 software
Slide 3
SINGLE MOTOR FUNCTIONS (ACTIONS) To use single motor functions, import the motor module: import motor Each motor function inputs the motor port as a parameter. To run for a certain duration, use the following methods (see Knowledge Base for more info). These functions are asynchronous so use await if you want to wait for them to complete. run_for_degrees ( port, d egrees , velocity ) run_for_time ( seconds , duration , velocity ) To start running the motors, until stopped at a later spot run ( port, velocity ) stop () To run the motor to a specific position run_to_relative position ( port, position , velocity ) run_to_absolute_position ( port, position , velocity , direction=motor.SHORTEST_PATH ) Direction options are CLOCKWISE, COUNTERCLOCKWISE, LONGEST_PATH These functions are asynchronous so use await if you want to wait for them to complete. Copyright © 2021 Prime Lessons (primelessons.org) CC-BY-NC-SA. (Last edit: 09/23/2023) ‹#›
Slide 4
SINGLE MOTOR FUNCTIONS (MEASUREMENTS/SETTINGS) The rotation sensor in the motor can be used to tell the number of degrees the motor has turned To do this, use reset_relative_position ( port, position ) and relative_position ( port ) Just like motor pairs, you can use parameters to change motor behavior Set the stop action (BRAKE, COAST etc.) Set acceleration, velocity etc. You can also read different measurement methods associated with the motor velocity ( port ) relative_position ( port ) a bsolute_position ( port ) Copyright © 2021 Prime Lessons (primelessons.org) CC-BY-NC-SA. (Last edit: 09/23/2023) ‹#›
Slide 5
NEGATIVE VALUES You can enter negative values for velocity or degrees This will make the robot move backwards If you negate two values (e.g., velocity and degrees or degrees and backwards direction), the robot will move forward. Copyright © 2021 Prime Lessons (primelessons.org) CC-BY-NC-SA. (Last edit: 09/23/2023) ‹#› Negative Power = Backwards Positive Power = Forward
Slide 6
STALL DETECTION Often, you program the motor to move a particular amount. However, the motor gets stuck before it reaches that amount. Stall Detection allows your program to automatically move on to the next line in the code when a particular motor command is stuck (unable to complete its move) SPIKE Prime has a built-in Stall Detection By default, Stall Detection is on when using single motor functions As of version 3.4, SP3 does not allow stall detection to be changed or queried Copyright © 2021 Prime Lessons (primelessons.org) CC-BY-NC-SA. (Last edit: 09/23/2023) ‹#›
Slide 7
CHALLENGE 1: LEARN ABOUT STALL WITH DB1 Write a program to turn the attachment motor E by1000 degrees. Add a beeping sound after the motor command. Hold the motor with your hand to prevent it from completing 1000 degrees. Hold for a couple of seconds. Will the sound play? Copyright © 2021 Prime Lessons (primelessons.org) CC-BY-NC-SA. (Last edit: 09/23/2023) ‹#› Cause a stall by holding the motor blue part and preventing it from turning
Slide 8
CHALLENGE 1 SOLUTION Stall detection allowed the code to move on to the next line even when the motor got stuck. The beep played even though the motor did not finish completing its command. Copyright © 2021 Prime Lessons (primelessons.org) CC-BY-NC-SA. (Last edit: 09/23/2023) ‹#› from hub import port, sound import motor, runloop, sys async def main () : # Start the motor await motor.run_for_degrees ( port.E, 1000 , 100 ) await sound.beep () sys.exit ( "Stopping" ) runloop.run ( main ())
Slide 9
CHALLENGE 2: GRAB OBJECT (DB2 CHALLENGE) Build the attachment part of DB2 Drive forward, grab a marker and drag it back to the start and release it. Marker is about 15cm from the front magenta-and-cyan panel. Copyright © 2021 Prime Lessons (primelessons.org) CC-BY-NC-SA. (Last edit: 09/23/2023) ‹#› 15cm
Slide 10
CHALLENGE 2 SOLUTION Copyright © 2021 Prime Lessons (primelessons.org) CC-BY-NC-SA. (Last edit: 09/23/2023) ‹#› from hub import port import motor, motor_pair, runloop, sys # Constants for Drive Base 1, adjust for your robot motor_pair.pair ( motor_pair.PAIR_1, port.C, port.D ) WHEEL_CIRCUMFERENCE = 17.5 # cm # See lesson on More Accurate Turns for explanation of math def degrees_for_distance ( distance_cm ) : return int (( distance_cm/WHEEL_CIRCUMFERENCE ) * 360 ) async def main () : # Move forward 14.5cm await motor_pair.move_for_degrees ( motor_pair.PAIR_1, degrees_for_distance ( 14.5 ) , ) # lower the arm await motor.run_for_degrees ( port.E, -90 , 100 ) # move backward await motor_pair.move_for_degrees ( motor_pair.PAIR_1, degrees_for_distance ( -14.5 ) , ) # raise the arm await motor.run_for_degrees ( port.E, 90 , 100 ) sys.exit ( "Done" ) runloop.run ( main ())
Slide 11
EXTENSIONS Think about situations in FIRST LEGO League when stall detection would be helpful When might the robot get stuck? Copyright © 2021 Prime Lessons (primelessons.org) CC-BY-NC-SA. (Last edit: 09/23/2023) ‹#›
Slide 12
SQUARING ON LINES This lesson uses SPIKE 3 software
Slide 13
LESSON OBJECTIVES Learn how to get your robot to square up (straighten out) when it comes to a line Learn how squaring (also known as aligning on a line) can help the robot navigate Learn how to improve initial code for aligning by repeating a technique Practice creating a useful async function with parameters Practice having the runloop run multiple async functions concurrently Copyright © 2020 Prime Lessons (primelessons.org) CC-BY-NC-SA. (Last edit: 09/23/2023) ‹#›
Slide 14
REVIEW Move Steering lets you control both motors at the same time What if you want to move or stop one motor at a time? Use the Single Motor Commands See the Knowledge base for the available commands Copyright © 2020 Prime Lessons (primelessons.org) CC-BY-NC-SA. (Last edit: 09/23/2023) ‹#›
Slide 15
WHY ALIGN/SQUARE ON A LINE? Aligning on a line helps the robot navigate Robots get angled as they travel farther or turn (the error accumulates) Aligning on a line can straighten out a robot. Aligning can tell a robot where it is when it has to travel far Example Goal: Your robot must deliver an object only inside a small END area. The distance between start and end is 8 feet (~2.5m) Do you think your robot can travel 8 feet and continue to be straight? Copyright © 2020 Prime Lessons (primelessons.org) CC-BY-NC-SA. (Last edit: 09/23/2023) ‹#› End Start 8ft
Slide 16
THREE EASY STEPS TO ALIGN Challenge: Make the robot straighten out (align/square up) STEP 1: Start both motors and a loop STEP 2: Stop one motor when the sensor on the corresponding side sees the line STEP 3: Stop moving the second motor when the sensor on that side sees the line STEP 4: Exit the loop Hints: Use an async function with parameters, Single Motors and a loop Copyright © 2020 Prime Lessons (primelessons.org) CC-BY-NC-SA. (Last edit: 09/23/2023) ‹#›
Slide 17
NOTES ON THE SOLUTION The robot used is Drive Base 1 with 2 color sensors Our solution uses 2 Color Sensors (connected in ports A and B). Our solution assumes that the color sensor on port A is next to the wheel on motor port C and color sensor on port B is next to the wheel on motor port D. You should adjust the ports as needed Your color sensors should NOT be placed right next to each other Copyright © 2020 Prime Lessons (primelessons.org) CC-BY-NC-SA. (Last edit: 09/23/2023) ‹#›
Slide 18
BASIC SOLUTION: MOVE UNTIL LINE Copyright © 2020 Prime Lessons (primelessons.org) CC-BY-NC-SA. (Last edit: 09/23/2023) ‹#› from hub import port import motor, color_sensor, runloop, sys async def main () : # Start the motors motor.run ( port.C, -200 ) motor.run ( port.D, 200 ) foundC = False foundD = False # wait for color sensors to detect black and stop motors while ( not foundC or not foundD ) : if ( color_sensor.reflection ( port.A ) < 50 ) : motor.stop ( port.C ) foundC = True if ( color_sensor.reflection ( port.B ) < 50 ) : motor.stop ( port.D ) foundD = True sys.exit ( "Stopping" ) runloop.run ( main ())
Slide 19
ALTERNATE SOLUTION: USING CONCURRENT FUNCTIONS Copyright © 2020 Prime Lessons (primelessons.org) CC-BY-NC-SA. (Last edit: 09/23/2023) ‹#› from hub import port import motor, color_sensor, runloop, sys async def all_done () : return ( motor.velocity ( port.C ) is and motor.velocity ( port.D ) is ) # Function to move motor until the sensor in front of it senses black # Parameters: # motor_port: The port of the motor # sensor_port: port of the color sensor in front of the motor # direction: 1 for clockwise, -1 for counterclockwise async def move_until_black ( motor_port, color_port, direction ) : motor.run ( motor_port, 200 * direction ) while color_sensor.reflection ( color_port ) > 50 : await runloop.sleep_ms ( 50 ) motor.stop ( motor_port ) async def main () : # create two async functions to send to the runloop a = move_until_black ( port.C, port.A, -1 ) b = move_until_black ( port.D, port.B, 1 ) # run both the functions together runloop.run ( * [ a,b ]) # wait until both motors have stopped await runloop.until ( all_done ) sys.exit ( "Stopping" ) runloop.run ( main ())
Slide 20
IMPROVING YOUR CODE What do you notice about the solution we just presented? The robot is not always perfectly straight (aligned) at the end of it. Both color sensors are on the line, but the robot stops at an angle if you started at a sharp angle Challenge Continued: Think about how you can improve this code so that the robot ends straighter Solution: repeat the align except look for white this time Copyright © 2020 Prime Lessons (primelessons.org) CC-BY-NC-SA. (Last edit: 09/23/2023) ‹#›
Slide 21
PROPORTIONAL LINE FOLLOWER This lesson uses SPIKE 3 software
Slide 22
LESSON OBJECTIVES Learn to create a proportional line follower Learn how to calculate error and correction Learn how to use variables and math blocks Copyright © 2021 Prime Lessons (primelessons.org) CC-BY-NC-SA. (Last edit: 09/23/2023) ‹#›
Slide 23
HOW FAR IS THE ROBOT FROM THE LINE? Reflected light sensor readings show how “dark” the measured area is on average Calibrated readings should range from 100 (on just white) to 0 (on just black) For following the right side of a black line (i.e. Black-White edge): Copyright © 2021 Prime Lessons (primelessons.org) CC-BY-NC-SA. (Last edit: 09/23/2023) ‹#› Light Sensor Measured Area: Line Reading = 100 Reading = 0 Reading = 50 Reading = 25 Reading = 75 Drive Base 1
Slide 24
LINE FOLLOWING Computing an error - how far is the robot from a target Robots follow the edge of line - target should be a sensor reading of 50 Error should indicate how far the sensor’s value is from a reading of 50 Making a correction - make the robot take an action that is proportional to the error. You must multiply the error by a scaling factor to determine the correction. To follow a line a robot must turn towards the edge of the line The robot must turn more sharply if it is far from a line How do you do this: You must adjust steering input on move block Copyright © 2021 Prime Lessons (primelessons.org) CC-BY-NC-SA. (Last edit: 09/23/2023) ‹#›
Slide 25
HOW DO YOU MAKE A PROPORTIONAL LINE FOLLOWER? Pseudocode: Compute the error = Distance from line = (Light sensor reading - Target Reading) Scale the error to determine a correction amount. Adjust your scaling factor to make you robot follow the line more smoothly. Use the Correction value (computed in Step 2) to adjust the robot’s turn towards the line. Copyright © 2021 Prime Lessons (primelessons.org) CC-BY-NC-SA. (Last edit: 09/23/2023) ‹#›
Slide 26
CHALLENGE Copyright © 2021 Prime Lessons (primelessons.org) CC-BY-NC-SA. (Last edit: 09/23/2023) ‹#› Compute Error Distance from line = (Light sensor reading - Target Reading) Compute Correction Scale the error to determine a correction amount. Use this to adjust power input on move block. Apply Correction Use the correction to steer the motor pair. You can also use it (scaled appropriately) to adjust the base velocity of each motor, if using tank mode. Error error = 50 - color_sensor.reflection ( port ) The maximum absolute value of error is 50 correction = int(error * 0.5) The int function converts the result to an integer to use in the move function. Since the maximum absolute value of error is 50, the correction ranges from -25 to 25 motor_pair.move ( motor_pair.PAIR_1, correction, velocity = 300 ) For following a Black-White edge:
Slide 27
PROPORTIONAL LINE FOLLOWER Copyright © 2021 Prime Lessons (primelessons.org) CC-BY-NC-SA. (Last edit: 09/23/2023) ‹#› from hub import port import motor, motor_pair, color_sensor, runloop, sys # Constants for Drive Base 1 motor_pair.pair ( motor_pair.PAIR_1, port.C, port.D ) # Follow the right side of black line (Black-White edge). # To follow a White-Black edge, change the error condition to (reflection - 50) async def line_follow_forever () : while ( True ) : # Compute the error error = 50 - color_sensor.reflection ( port.A ) # Compute the correction by multiplying the error # by a Constant of Proportionality correction = int ( error * 0.5 ) motor_pair.move ( motor_pair.PAIR_1, correction, velocity = 300 ) async def main () : await line_follow_forever () runloop.run ( main ())
Slide 28
KEY STEP: TUNING THE CONSTANT Note, the 0.5 constant in the previous slide is specific to our robot (Drive Base 1 design). It is a good start, but you may need to tune this value for your specific robot. This constant is called the Proportional Constant, or Constant of Proportionality The most common way to tune your constant is trial and error. This can take time. Here are some tips: Start with a value of 0.5 and adjust ±0.05 for fine tuning If you are using the steering method, try to keep the correction value from -30 to 30. Adjust to a point where the controller is pretty smooth Copyright © 2021 Prime Lessons (primelessons.org) CC-BY-NC-SA. (Last edit: 09/23/2023) ‹#›
Slide 29
CHALLENGE Copyright © 2021 Prime Lessons (primelessons.org) CC-BY-NC-SA. (Last edit: 09/23/2023) ‹#› Convert the example programs in the Basic line follower lesson to use a proportional line follower: Line follow until second sensor sees black Line follow for approximate distance
Slide 30
PID LINE FOLLOWER This lesson uses SPIKE 3 software
Slide 31
What would a human do? On line - go straight On white - turn left Moving across line - turn right On white - turn left Getting further from line - turn even more! What would proportional control do? On line - go straight On white - turn left Moving across line - go straight! On white - turn left Getting further from line - turn left the same amount! ‹#› WHEN DOES PROPORTIONAL CONTROL HAVE TROUBLE? LIGHT READING = 50% 100% Note: the following few slides are animated. Use PowerPoint presentation mode to view them Copyright © 2020 Prime Lessons (primelessons.org) CC-BY-NC-SA. (Last edit: 09/23/2020)
Slide 32
What would a human do? Turning left/on line 🡪 turn right Getting further from line 🡪 turn even more! What would proportional control do? Turning left/on line 🡪 go straight! Getting further from line 🡪 turn left the same amount! ‹#› HOW CAN WE FIX PROPORTIONAL CONTROL? 1. Predict what the next sensor reading will be 2. Has past steering fixes helped reduce error? Copyright © 2020 Prime Lessons (primelessons.org) CC-BY-NC-SA. (Last edit: 09/23/2020)
Slide 33
If readings are: 75, 65, 55 - what do you think the next reading will be? What if the readings were 57, 56, 55… What information did you use to guess? Derivative - the rate at which a value is changing When the correction is working well, what does error readings look like? +5, -6, +4 -3…. i.e. bouncing around 0 When steering is not working, what does error look like? +5, +5, +6, +5… i.e. always on one side of 0 How can we detect this easily? Hint: look at the sum of all past errors What is an ideal value for this sum? What does it mean if the sum is large? Integral - the “sum” of values ‹#› INTEGRALS AND DERIVATIVES 1. Predict what the next sensor reading will be? 2. Have past steering fixes helped reduce error? Copyright © 2020 Prime Lessons (primelessons.org) CC-BY-NC-SA. (Last edit: 09/23/2020)
Slide 34
WHAT IS PID? P roportional [Error] : How bad is the situation now? I ntegral : Have my past fixes helped fix things? D erivative : How is the situation changing? PID control : combine the error, integral and derivative values to decide how to steer the robot ‹#› Copyright © 2020 Prime Lessons (primelessons.org) CC-BY-NC-SA. (Last edit: 09/23/2020)
Slide 35
ERROR Solid line represents what you have seen, dotted line is the future At time 20, you see light reading = 40 and error = -10 (red X ) ‹#› Subtract target (50) Copyright © 2020 Prime Lessons (primelessons.org) CC-BY-NC-SA. (Last edit: 09/23/2020)
Slide 36
INTEGRAL Looks at past history of line follower Sum of past error Like area under the curve in graph (integral) Green = positive area Red = negative area ‹#› Copyright © 2020 Prime Lessons (primelessons.org) CC-BY-NC-SA. (Last edit: 09/23/2020)
Slide 37
DERIVATIVE How quickly is position changing? Predicts where the robot will be in the immediate future Same as how fast is error changing Can be measured using tangent line to measurements: derivative Approximated using two nearby points on graph ‹#› Tangent line Copyright © 2020 Prime Lessons (primelessons.org) CC-BY-NC-SA. (Last edit: 09/23/2020)
Slide 38
PSEUDOCODE Take a new light sensor reading Compute the “error” Scale error to determine contribution to steering update (proportional control) Use error to update integral (sum of all past errors) Scale integral to determine contribution to steering update (integral control) Use error to update derivative (difference from last error) Scale derivative to determine contribution to steering update (derivative control) Combine P, I, and D feedback and steer robot ‹#› Copyright © 2020 Prime Lessons (primelessons.org) CC-BY-NC-SA. (Last edit: 09/23/2020)
Slide 39
CODE - PROPORTIONAL This is the same as the proportional control code, and follows a Black-White edge (right side of a black line) ‹#› Error = distance from line = target - reading Correction (P_fix) = Error scaled by proportional constant (K p ) = 0.5 error = 50 - color_sensor.reflection ( port.A ) P_fix = error * 0.5 Copyright © 2020 Prime Lessons (primelessons.org) CC-BY-NC-SA. (Last edit: 09/23/2020)
Slide 40
CODE - INTEGRAL This section calculates the integral. It adds the current error to a variable that has the sum of all the previous errors. The scaling constant is usually small since Integral can be large ‹#› Integral = sum of all past errors = last integral + newest error Correction (I_fix) = Integral scaled by proportional constant (K i ) = 0.001 integral = integral + error # or integral+=error I_fix = integral * 0.001 Copyright © 2020 Prime Lessons (primelessons.org) CC-BY-NC-SA. (Last edit: 09/23/2020)
Slide 41
CODE - DERIVATIVE This section of code calculates the derivative. It subtracts the current error from the past error to find the change in error. ‹#› Derivative = rate of change of error = current error – last error Correction (D_fix) = Derivative scaled by proportional constant (K d ) = 1.0 derivative = error - lastError lastError = error D_fix = derivative * 1 Copyright © 2020 Prime Lessons (primelessons.org) CC-BY-NC-SA. (Last edit: 09/23/2020)
Slide 42
PUTTING IT ALL TOGETHER Each of the components have already been scaled. At this point we can simply add them together. Add the three fixes for P, I, and D together. This will compute the final correction NOTE : Use the correction as steering after clamping it from -100 to 100 because SP3 does not appear to do it internally. i.e., it will accept values out of bounds (e.g. –250) and do unpredictable things. ‹#› correction = min(100, max(-100, int(P_fix + I_fix + D_fix))) motor_pair.move ( motor_pair.PAIR_1, correction, velocity = 300 ) Copyright © 2020 Prime Lessons (primelessons.org) CC-BY-NC-SA. (Last edit: 09/23/2020)
Slide 43
FULL CODE ‹#› Copyright © 2020 Prime Lessons (primelessons.org) CC-BY-NC-SA. (Last edit: 09/23/2020) from hub import port import motor, motor_pair, color_sensor, runloop, sys # Constants for Drive Base 1 motor_pair.pair ( motor_pair.PAIR_1, port.C, port.D ) # Follow the right side of black line (Black-White edge). # To follow a White-Black edge, change the error condition to (reflection - 50). async def pid_line_follow_forever () : integral = lastError = while ( True ) : # Compute the error. error = 50 - color_sensor.reflection ( port.A ) P_fix = error * 0.5 integral = integral + error I_fix = integral * 0.001 derivative = error - lastError lastError = error D_fix = derivative * 1 # clamp the correction from -100 to 100 because SP3 doesn’t seem to do it internally. correction = min ( 100 , max ( -100 , int ( P_fix + I_fix + D_fix ))) # use the correction as the steering motor_pair.move ( motor_pair.PAIR_1, correction, velocity = 300 ) async def main () : await pid_line_follow_forever () runloop.run ( main ())
Slide 44
KEY STEP: TUNING THE PID CONSTANTS The most common way to tune your PID constants is trial and error. This can take time. Here are some tips: Disable everything but the proportional part (set the other constants to zero). Adjust just the proportional constant until robot follows the line well. Then, enable the integral and adjust until it provides good performance on a range of lines. Finally, enable the derivative and adjust until you are satisfied with the line following. When enabling each segment, here are some good numbers to start with for the constants: P: 1.0 adjust by ±0.5 initially and ±0.1 for fine tuning I: 0.05 adjust by ±0.01 initially and ±0.005 for fine tuning D: 1.0 adjust by ±0.5 initially and ±0.1 for fine tuning ‹#› Copyright © 2020 Prime Lessons (primelessons.org) CC-BY-NC-SA. (Last edit: 09/23/2020)
Slide 45
Proportional Uses the “P” in PID Makes proportional turns Works well on both straight and curved lines Good for intermediate to advanced teams - need to know math blocks PID It is better than proportional control on a very curved line, as the robot adapts to the curviness However, for FIRST LEGO League, which mostly has straight lines, proportional control can be sufficient ‹#› EVALUATING LINE FOLLOWERS Copyright © 2020 Prime Lessons (primelessons.org) CC-BY-NC-SA. (Last edit: 09/23/2020)
Slide 46
GYRO MOVE STRAIGHT This lesson uses SPIKE 3 software
Slide 47
LESSON OBJECTIVES Learn to apply proportional control to get your robot to move straight Learn to apply proportional control to the Gyro sensor move at a particular angle You must go through the Proportional Line Follower Lesson before you complete this lesson You must also complete the Turning With Gyro Lesson Copyright © 2020 Prime Lessons (primelessons.org) CC-BY-NC-SA. (Last edit: 09/23/2023) ‹#›
Slide 48
WHAT IS GYRO MOVE STRAIGHT? Imagine that you want to drive for 200 cm straight As you travel, your robot gets bumped by something A gyro move straight program helps the robot correct itself back to straight, but offset by how much it was bumped Copyright © 2020 Prime Lessons (primelessons.org) CC-BY-NC-SA. (Last edit: 09/23/2023) ‹#›
Slide 49
HOW IT WORKS A proportional line follower and a gyro move straight code share similar properties To write a gyro move straight program, you must first think about what the error is and what the correction needs to be Copyright © 2020 Prime Lessons (primelessons.org) CC-BY-NC-SA. (Last edit: 09/23/2023) ‹#› Application Objective Error Correction Gyro Straight Make the robot at a constant heading/angle How far you are from that heading/angle Turn sharper based on how far you are from that angle Line Follower Stay on the edge of the line How far are our light readings from those at line edge (current_light – target_light) Turn sharper based on distance from line
Slide 50
PSEUDOCODE Set motor pair Reset your yaw value to 0 In a loop, compute the error and apply the correction Part 1: Compute Error (How far from target angle) To move straight: Target yaw angle=0 (Note: Assuming a horizontal hub placement, we must look at the yaw direction for the angle offset. This may be different for your setup) Distance from target angle is just current yaw reading Part 2: Compute a Correction that is proportional to the error Multiply the Error from Part 1 by a constant (that you must experiment and discover for your robot) Plug the value from Part 2 into a move block with each motor adjusted proportionally Exit loop as required by changing loop block NOTE: If your robot is built in a way that the Front of the hub is not the Front of the Robot, you may have to make some adjustments. See discussion guide item 2. The code was tested on Drive Base 1. Copyright © 2020 Prime Lessons (primelessons.org) CC-BY-NC-SA. (Last edit: 09/23/2023) ‹#›
Slide 51
SOLUTION: GYRO MOVE STRAIGHT Copyright © 2020 Prime Lessons (primelessons.org) CC-BY-NC-SA. (Last edit: 09/23/2023) ‹#› from hub import port, motion_sensor import runloop, motor_pair async def main () : motor_pair.pair ( motor_pair.PAIR_1, port.C, port.D ) # Reset the yaw angle and wait for it to stabilize motion_sensor.reset_yaw ( ) await runloop.until ( motion_sensor.stable ) while True : # compute the error in degrees. See Turning with Gyro for explanation. error = motion_sensor.tilt_angles ()[ ] * -0.1 # correction is an integer which is the negative of the error correction = int ( error * -2 ) # apply steering to correct the error motor_pair.move ( motor_pair.PAIR_1, correction, velocity= 200 ) runloop.run ( main ())
Slide 52
DISCUSSION GUIDE Compare the proportional line follower code with the proportional move straight code. What similarities and differences do you see? Ans. The code is almost the same. The one difference is how the error is calculated. The error is calculated using the gyro sensor. The correction is identical. What if you wanted to travel at a particular angle (not just straight)? How would the code look different? Ans. In Part 1 of the solution code, there is no subtraction block because we were just subtracting “0” since our target heading is moving straight. You would have to subtract your current angle from the target angle if you wanted to move at some other angle. Copyright © 2020 Prime Lessons (primelessons.org) CC-BY-NC-SA. (Last edit: 09/23/2023) ‹#› Target angle = 5 degrees error = motion_sensor.tilt_angles ()[ ] * -0.1 - 5 correction = int (error * -2)
Slide 53
RELIABILITY TECHNIQUES
Slide 54
WHY DISCUSS RELIABILITY? While working on the Challenges lesson, you might have experienced frustration because the robot did not behave the same way or move as expected. These types of frustrations are common in competitions such as FIRST LEGO League as well. This lesson introduces the reliability issues faced by FIRST LEGO League teams. Many concepts are applicable to non-competition situations, but the terminology in the lesson and the main focus is for competition robots. Copyright © 2020 Prime Lessons (primelessons.org) CC-BY-NC-SA. (Last edit: 12/14/2020) ‹#› Visit FLLTutorials.com for a series of lessons on being more reliable in FIRST LEGO League.
Slide 55
SOURCES OF PROBLEMS Problem Impact Starting alignment varies from launch to launch Each launch is different and missions sometimes do not work. Robots do not travel straight for long or turn exactly the same amount It is hard to predict the robot location exactly. Errors accumulate as you travel Long missions tend to fail. It is hard to do missions far from Launch/Home Battery levels impact motor performance Tweaks that work today fail tomorrow Copyright © 2020 Prime Lessons (primelessons.org) CC-BY-NC-SA. (Last edit: 12/14/2020) ‹#›
Slide 56
STARTING POINTS IN LAUNCH ARE CRITICAL In FIRST LEGO League, teams need to figure out where to start in the launch area Jigs: a LEGO ruler/wall that your robot can align against them in base (the red triangle is an example of a jig) Same start each time: pick one spot and start there no matter what the mission for easy starts Grid/Radial Lines: Use the grid lines to pick a starting spot for each run Words: Launch has a FIRST LEGO League logo. You can use letters in the logo or the border for the image to line up Even better…try to find a way to align the robot using other techniques (see slide 6) Copyright © 2020 Prime Lessons (primelessons.org) CC-BY-NC-SA. (Last edit: 12/14/2020) ‹#› Use a jig Use grid lines or logo border
Slide 57
ERRORS ACCUMULATE OVER TIME By the time you get to the far side of the table, you are no longer in the right position Solution: Repeat alignment techniques multiple times in a run for better reliability (see slide 7) Copyright © 2020 Prime Lessons (primelessons.org) CC-BY-NC-SA. (Last edit: 12/14/2020) ‹#› Mission Model 1 Mission Model 2 A E A E
Slide 58
WHERE ARE YOU ON THE COMPETITION TABLE? These are common alignment strategies used: Align on walls – deliberately back into a wall to straighten out Square/Align on lines –If you are moving angled, you can straighten out whenever you see a line using two color sensors Move until a line – travel until you find a line so you know where you are on the mat Align on a mission model – Mission models that are stuck down with dual-lock can be used to align against Copyright © 2020 Prime Lessons (primelessons.org) CC-BY-NC-SA. (Last edit: 12/14/2020) ‹#› Mission Model Back into walls Square on a line Align on a mission model A E A E A E
Slide 59
OTHER FACTORS IN RELIABILITY Battery life If you program your robot when the battery life is low, it won’t run the same when fully charged Motors behave differently with low battery But using sensors makes you not as dependent on battery LEGO pieces come apart over time: Squeeze in LEGO pieces in key areas before a run – the pegs get loose which means the sensors may not be in the same place as a previous run Push wires in for sensors and motors. They come out! Motors and sensors don’t always match: Some teams test motors, sensors and wheels to make sure that they match You will never get a perfect match so we recommend use other techniques and accept that they will be different Copyright © 2020 Prime Lessons (primelessons.org) CC-BY-NC-SA. (Last edit: 12/14/2020) ‹#›
Slide 60
CREDITS This lesson was created by Sanjay Seshan and Arvind Seshan for Prime Lessons and edited by mentors at the Society of Women in Computer @ William and Mary. More lessons are available at www.primelessons.org Copyright © 2020 Prime Lessons (primelessons.org) CC-BY-NC-SA. (Last edit: 12/14/2020) ‹#› This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License .
Tags
Categories
Technology
Download
Download Slideshow
Get the original presentation file
Quick Actions
Embed
Share
Save
Print
Full
Report
Statistics
Views
6
Slides
60
Age
38 days
Related Slideshows
11
8-top-ai-courses-for-customer-support-representatives-in-2025.pptx
JeroenErne2
44 views
10
7-essential-ai-courses-for-call-center-supervisors-in-2025.pptx
JeroenErne2
44 views
13
25-essential-ai-courses-for-user-support-specialists-in-2025.pptx
JeroenErne2
36 views
11
8-essential-ai-courses-for-insurance-customer-service-representatives-in-2025.pptx
JeroenErne2
33 views
21
Know for Certain
DaveSinNM
19 views
17
PPT OPD LES 3ertt4t4tqqqe23e3e3rq2qq232.pptx
novasedanayoga46
23 views
View More in This Category
Embed Slideshow
Dimensions
Width (px)
Height (px)
Start Page
Which slide to start from (1-60)
Options
Auto-play slides
Show controls
Embed Code
Copy Code
Share Slideshow
Share on Social Media
Share on Facebook
Share on Twitter
Share on LinkedIn
Share via Email
Or copy link
Copy
Report Content
Reason for reporting
*
Select a reason...
Inappropriate content
Copyright violation
Spam or misleading
Offensive or hateful
Privacy violation
Other
Slide number
Leave blank if it applies to the entire slideshow
Additional details
*
Help us understand the problem better