Robotics Fundamentals 1, Chapter 5: Challenge 3 solution (line position, calibration, current and choice) Formulas: x(i) = ( i - (n - 1)/2 ) p w(i) = (raw - lo) / (hi - lo), limited to 0 to 1 x(line) = sum( w x ) / sum( w ) two-point calibration: g = (t2 - t1) / (r2 - r1), true = g (r - r1) + t1 shunt: V = I R, P = I^2 R, counts = floor( V / Vref x 1024 ) (a) Six sensors, pitch 10 mm: x(i) = (i - 2.5) x 10 = -25, -15, -5, +5, +15, +25 mm. Weights: w0 = (62 - 60) / (860 - 60) = 2 / 800 = 0.0025 w1 = (150 - 70) / (880 - 70) = 80 / 810 = 0.0988 w2 = (700 - 80) / (900 - 80) = 620 / 820 = 0.7561 w3 = (820 - 75) / (870 - 75) = 745 / 795 = 0.9371 w4 = (280 - 65) / (850 - 65) = 215 / 785 = 0.2739 w5 = (95 - 90) / (900 - 90) = 5 / 810 = 0.0062 sum(w) = 2.0745 sum(w x) = 0.0025(-25) + 0.0988(-15) + 0.7561(-5) + 0.9371(+5) + 0.2739(+15) + 0.0062(+25) = -0.063 - 1.482 - 3.780 + 4.686 + 4.109 + 0.155 = +3.62 mm x(line) = 3.62 / 2.0745 = +1.75 mm: the line is 1.75 mm to the RIGHT of the centre of the bar. On or off, threshold 0.5: only sensors 2 and 3 exceed it (0.756 and 0.937), at -5 and +5 mm, and their middle is 0 mm: the robot would think the line is exactly central. The weighted average finds the 1.75 mm that the on or off decision cannot see (the pitch is 10 mm). Direction: the line is to the right, so the robot should turn clockwise (right). In the convention of Robotics Fundamentals 4, where counter-clockwise is positive, the turning rate is negative. How hard to turn is the subject of Robotics Fundamentals 7. (b) g = (200.0 - 10.0) / (196.5 - 8.2) = 190.0 / 188.3 = 1.00903. true = 1.00903 (r - 8.2) + 10.0 = 1.00903 r + 1.726 (gain 1.00903, offset +1.726 cm). Reading 120.0: true = 1.00903 x 120.0 + 1.726 = 121.08 + 1.726 = 122.81 cm. Check point, reading 101.4: true = 1.00903 x 101.4 + 1.726 = 102.32 + 1.726 = 104.04 cm. The real distance is 100.0 cm, so the calibrated value is 4.04 cm too high. What it tells you: the two-point line is exact only at its two points. A 4 cm error at the middle means the sensor is not straight-line (or the check point is a mistake: repeat it, averaging many readings). If it is genuinely nonlinear, add calibration points and use a lookup table with interpolation, or calibrate in a variable that makes the relation straight (for an infrared sensor, 1 / V). (c) Shunt R = 0.05 ohm, gain G = 20, so the amplified voltage is V = I x 0.05 x 20 = 1.0 V per amp (one volt for each amp). Running 0.5 A: 0.5 V, counts = floor(0.5 / 5 x 1024) = floor(102.4) = 102. Stall 3.2 A: 3.2 V, counts = floor(3.2 / 5 x 1024) = floor(655.4) = 655. Heat in the shunt at stall: P = I^2 R = 3.2^2 x 0.05 = 10.24 x 0.05 = 0.512 W, so use a shunt resistor rated at least 1 W (often more, with some margin for heating and voltage spikes). The shunt also drops 3.2 x 0.05 = 0.16 V at stall (a loss to the motor). Trip at 2.0 A: 2.0 V = 2.0 / 5 x 1024 = 409.6 counts, so trip when the count reaches 410 (one count is about 0.0049 A here, since 1 V per amp and LSB = 4.883 mV). (A real program would filter the reading first (Chapter 5, section 9) and ignore the brief start-up surge of a motor, which can exceed the running current for tens of milliseconds, before declaring a stall.) (d) Suggested sensors (other sensible answers are possible if the reasons are sound): Stopping at a table edge: a downward-pointing IR reflective sensor at the front. Reason: very cheap and fast, and it detects the loss of floor at once. Drawback: short range, and a dark or shiny floor can fool it, so test it on the real floor (and mount at least two, so the robot can turn away from the edge). Keeping 20 cm from a wall within 5 mm: IR triangulation (close range, fine resolution there) or a laser time-of-flight module. Reason: narrow beam and millimetre-level resolution at 20 cm. Drawback: sunlight and surface colour affect them, and they cost more than an ultrasonic sensor, which is only good to a few millimetres at best and has a wide beam. Stopping an arm joint at the end of its travel, safely: a limit switch wired normally closed. Reason: certain and cheap; a broken wire or a failed switch looks like "limit reached" and the arm stops (fail-safe). Drawback: it wears, and it must be placed so that the joint stops BEFORE its hard stop; add a software limit from the encoder as well.