The left servo is different because Kp for that system is -35
pulseLeft = 2 - distanceLeft * (-35) + 750
Since the values -35, 35, 2, and 750 all have names, it's definitely a good place for some
constant declarations.
Kpl
Kpr
SetPoint
CenterPulse
With these constant declarations in the program, you can use the name
35,
in place of 35,
Kpr
SetPoint
these constant declarations, the proportional control calculations now look like this:
pulseLeft
= SetPoint - distanceLeft
pulseRight = SetPoint - distanceRight * Kpr + CenterPulse
The convenient thing about declaring constants for these values is that you can change
them in one place, at the beginning of the program. The changes you make at the
beginning of the program will be reflected everywhere these constants are used. For
example, by changing the
entire program changes from -35 to -40. This is exceedingly useful for experimenting
with and tuning the right and left proportional control loops.
Example Program – FollowingBoeBot.bs2
FollowingBoeBot.bs2 repeats the proportional control loop just discussed with every
servo pulse. In other words, before each pulse, the distance is measured and the error
signal is determined. Then the error is multiplied by Kp, and the resulting value is
added/subtracted to/from the pulse widths that are sent to the left/right servos.
√
Enter, save, and run FollowingBoeBot.bs2.
Point the Boe-Bot at an 8 ½ × 11" sheet of paper held in front of it as though it's
√
a wall-obstacle. The Boe-Bot should maintain a fixed distance between itself
and the sheet of paper.
√
Try rotating the sheet of paper slightly. The Boe-Bot should rotate with it.
√
Try using the sheet of paper to lead the Boe-Bot around. The Boe-Bot should
follow it.
Chapter 8: Robot Control with Distance Detection · Page 281
CON
-35
CON
35
CON
2
CON
750
in place of 2, and
directive from -35 to -40, every instance of
Kpl CON
Kpl
in place of 750. After
CenterPulse
* Kpl + CenterPulse
in place of -
in the
Kpl
Need help?
Do you have a question about the Boe-Bot and is the answer not in the manual?
Questions and answers