How to get a robot to drive striaght and turn 90 degrees(Very, very new to this please help)

kdani2019kdani2019 Posts: 1
edited 2019-10-11 - 07:26:44 in Robotics
Hi,

I am using Basic stamp for a simple project to learn coding and robotics. I have a robot that will need to:
-drive straight for 2 feet
-turn 90 degrees counterclockwise
-drive 1/2 foot
-turn 90 counterclockwise
-drive for 2 feet
-turn 90 degrees clockwise

I was thinking of repeating this and putting it in a loop.. can anyone help me with an example of how to turn 90 degrees or how to loop this in basic ?
I have minimal experiance using MATLAB and python.

This is what I have experimented with so far...
' {$STAMP BS2}
' {$PBASIC 2.5}
counter VAR Word
DEBUG "Counterclockwise 10 o'clock", CR
FOR counter = 1 TO 50
 PULSOUT 13, 700
 PAUSE 20
 PULSOUT 12, 800
 PAUSE 20
NEXT
DEBUG "Clockwise 2 o'clock", CR
FOR counter = 1 TO 50
PULSOUT 12, 700
PAUSE         20
NEXT
FOR counter = 800 TO 700 STEP 8
 PULSOUT 13, counter
 PAUSE 20
 PULSOUT 12, counter
 PAUSE 20
NEXT
DEBUG "Center 12 o'clock", CR
FOR counter = 1 TO 80
 PULSOUT 13, 760
 PAUSE 20
  PULSOUT 12, 760
 PAUSE 20
NEXT
DEBUG "Counterclockwise 10 o'clock", CR
FOR counter = 1 TO 50
 PULSOUT 13, 800
 PAUSE 20
 PULSOUT 12, 700
 PAUSE 20
NEXT
DEBUG "All done."
END


ModEdit: Code tags added

Comments

  • The first thing anyone is going to need to know, to properly interpret your code is what you have connected where.
  • If you want your robot to move in a precise, predictable manner it will require feedback from the wheels or motors. Two motors given the same electrical power will spin at different speeds because of mechanical and electrical differences between the two motors. Feedback will allow your controller to know how fast each one is turning and can adjust the speed of the motors towards a common set point. This will enable the robot to run in a straight line. Without feedback straight lines become arcs as the robot wanders left or right.
    Making right angle turns is just a matter of driving one wheel forward for x number of feedback pulses, or one motor forward and the other reverse for spin in place.
    Florida, between St. Petersburg and the Gulf of Mexico

    Do not look directly into laser with remaining good eye...
  • ercoerco Posts: 19,546
    @kdani2019: Welcome to the forum. Are you using an original BoeBot or equivalent? As Hal mentioned, feedback from wheels or motors is required for consistent navigation. An original Boebot has no feedback, but the new Activity bot does. Or you could add feedback 360 servos to a boebot... Name your poison! :)
    "When you make a thing, a thing that is new, it is so complicated making it that it is bound to be ugly. But those that make it after you, they don’t have to worry about making it. And they can make it pretty, and so everybody can like it when others make it after you."

    - Pablo Picasso
  • ercoerco Posts: 19,546
    edited 2019-10-13 - 17:09:55
    BTW the program you wrote using for/next loops is a good start for basic encoder-free motion, which can yield fairly consistent results (but different floor surfaces and deteriorating battery voltage are always "gotchas"). You should definitely read Parallax's fine "Robotics with the Boebot" PDF. It's a great FREE (who does that anymore?) download at https://www.parallax.com/sites/default/files/downloads/28125-Robotics-With-The-Boe-Bot-v3.0.pdf
    "When you make a thing, a thing that is new, it is so complicated making it that it is bound to be ugly. But those that make it after you, they don’t have to worry about making it. And they can make it pretty, and so everybody can like it when others make it after you."

    - Pablo Picasso
Sign In or Register to comment.