The sensor for Bot going straight
qiuqiuaaa
Posts: 37
I want my Boe-Bot to go straight, and I used campass HM55B. When program, I catch the initial angle, and save as 'initialangle'. To go straight, a part of program is as below
IF (angle = initialangle - 1 OR angle = initialangle OR angle = initialangle + 1) THEN
PULSOUT 12,speedr
PULSOUT 13,speedl
ELSEIF (angle > initialangle + 1 AND angle < initialangle + 180) THEN
speedr = speedr - 1
PULSOUT 12,speedr ' rotate the 'Bot left
PULSOUT 13,speedl
ELSEIF (angle < initialangle - 1 OR angle > initialangle + 180) THEN
speedr = speedr + 1
PULSOUT 12,speedr ' rotate the 'Bot right
PULSOUT 13,speedl
speedr is right wheel speed, speedl is left wheel speed. there are initial values for them. I hope the direction remain the initialangle, and change the apeed. However, it behaves unstable. How to program?? And whether there is some other sensor suitable for straight line. I tried encoder before, and it also doesn't work. What can I do?? Help!
IF (angle = initialangle - 1 OR angle = initialangle OR angle = initialangle + 1) THEN
PULSOUT 12,speedr
PULSOUT 13,speedl
ELSEIF (angle > initialangle + 1 AND angle < initialangle + 180) THEN
speedr = speedr - 1
PULSOUT 12,speedr ' rotate the 'Bot left
PULSOUT 13,speedl
ELSEIF (angle < initialangle - 1 OR angle > initialangle + 180) THEN
speedr = speedr + 1
PULSOUT 12,speedr ' rotate the 'Bot right
PULSOUT 13,speedl
speedr is right wheel speed, speedl is left wheel speed. there are initial values for them. I hope the direction remain the initialangle, and change the apeed. However, it behaves unstable. How to program?? And whether there is some other sensor suitable for straight line. I tried encoder before, and it also doesn't work. What can I do?? Help!
Comments
http://forums.parallax.com/showthread.php?135308-The-sensor-for-Bot-going-straight
I believe your programming logic needs some brushing up on. With the bit of code you posted, it looks like you are only changing the right motor's pulsout time, depending on how the robot is oriented with respect to initialangle. The idea is sound, but your implementation needs some work.
I would suggest having three condition to check: if the robot is centered (pointing straight), if the robot is baring left, or if the robot is baring right. It looks like your current if statements take care of that. Might I suggest, instead of incrementing or decrementing a single wheel value by one, that you have constant pulsout values for each of the three cases. This way, your robot will always make one of three determinations: keep going straight, robot is baring left -> turn right, or robot is baring right -> turn left.
Hope that helps!
thank you