Shop OBEX P1 Docs P2 Docs Learn Events
The sensor for Bot going straight — Parallax Forums

The sensor for Bot going straight

qiuqiuaaaqiuqiuaaa Posts: 37
edited 2011-10-21 19:03 in Accessories
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!

Comments

  • Daniel HarrisDaniel Harris Posts: 207
    edited 2011-10-21 08:17
    Hello qiuqiuaaa,

    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! :)
  • graffixgraffix Posts: 389
    edited 2011-10-21 09:52
    Leon your link didnt work for me?said notify admin
  • LeonLeon Posts: 7,620
    edited 2011-10-21 09:57
    The cross-post was deleted.
  • graffixgraffix Posts: 389
    edited 2011-10-21 17:49
    Welcome to the forums qiuqiuaaa
  • qiuqiuaaaqiuqiuaaa Posts: 37
    edited 2011-10-21 18:56
    Thank you. I have also tried constant value, but it looks like dancing. It cannot move smoothly because it always rotates. BTW, this campass seems sensitive to the environment. The same angle value indicates differient direction( about 5 degrees bias ) within only several meters. Is it normal? I am confused about the direction. There is no strong magnetic field.
  • qiuqiuaaaqiuqiuaaa Posts: 37
    edited 2011-10-21 19:03
    graffix wrote: »
    Welcome to the forums qiuqiuaaa

    thank you:smile:
Sign In or Register to comment.