Coordinate System for a Boe-Bot
Hello, I have successfully managed to create a code for my Boe-Bot where it utilizes 3 IR detectors to avoid obstacles. Not all that hard to do, even with my limited knowledge/experience.
The next step I would like to achieve is to create a code for the robot so that I can tell it somewhere to go, or it can decide where it wants to go.
My idea is to make a Coordinate system that is embedded in the code. I'll start by explaining my idea.
My variables would be
Currx VAR Word 'Current position on the x Axis
Curry VAR Word 'Current Position on the y Axis
Destx VAR Word 'Destination on the x axis
Dexty VAR Word 'Destination on the y axis
Slopex VAR Bit 'Slopex and Slopey will be used in the code when the Boe-Bot makes a turn.
Slopey VAR Bit
The basic idea is that whenever the robot moves forward, it will automatically add or subtract from the Current x and y positions. and it will keep moving until Currx and Curry = Destx and Desty.
my code for it to move forward looks like this:
MoveAhead:
PULSOUT 13, 850
PULSOUT 12, 670
PAUSE 20
Currx + Slopex
Curry + Slopey
RETURN
If I start out with the front of the robot parallel to the Y axis, then when it moves foward, in this example Slopex should = 0, since it is not moving in that direction, and Slopey should =1, because it is moving positively in that direction.
The problems I have come when i need to turn.
Lets start with the right turn.
My first idea was to add or subtract 1 from every time the robot made a left or right turn. For starters, every turn will be a complete 90 degree turn, to make things simpler.
This way if a robot made a right turn, the program would then have the values
Slopex=1
Slopey=0
However, if i make another right turn, 0-1 is negative 1, and as far as i know the basic stamp cannot do negative numbers.
So that is my problem. How can i make the robot know which direction it is facing?
My other idea would be to add 1 every time it made a right turn, and subtract one every time it made a left turn. Except, instead of starting at 0, I would start at least say 40 (because it is divisible by 4).
Then I can tell its facing by 40/4 or 39/4, and whatever the remainder is, 0, 1 , 2, or 3, would be its facing and I can add or subtract from the x and y values based on that number.
Can anyone tell me if that will work? I don't know how to code it, or how the stamp deals with remainders. keep it mind I don't have a gps module, so I can't go that route.
I have scoured this forum for posts similar to this one to no avail. If anyone can help me with this code, me and my engineering class would greatly appreciate it.
Thank you
The next step I would like to achieve is to create a code for the robot so that I can tell it somewhere to go, or it can decide where it wants to go.
My idea is to make a Coordinate system that is embedded in the code. I'll start by explaining my idea.
My variables would be
Currx VAR Word 'Current position on the x Axis
Curry VAR Word 'Current Position on the y Axis
Destx VAR Word 'Destination on the x axis
Dexty VAR Word 'Destination on the y axis
Slopex VAR Bit 'Slopex and Slopey will be used in the code when the Boe-Bot makes a turn.
Slopey VAR Bit
The basic idea is that whenever the robot moves forward, it will automatically add or subtract from the Current x and y positions. and it will keep moving until Currx and Curry = Destx and Desty.
my code for it to move forward looks like this:
MoveAhead:
PULSOUT 13, 850
PULSOUT 12, 670
PAUSE 20
Currx + Slopex
Curry + Slopey
RETURN
If I start out with the front of the robot parallel to the Y axis, then when it moves foward, in this example Slopex should = 0, since it is not moving in that direction, and Slopey should =1, because it is moving positively in that direction.
The problems I have come when i need to turn.
Lets start with the right turn.
My first idea was to add or subtract 1 from every time the robot made a left or right turn. For starters, every turn will be a complete 90 degree turn, to make things simpler.
This way if a robot made a right turn, the program would then have the values
Slopex=1
Slopey=0
However, if i make another right turn, 0-1 is negative 1, and as far as i know the basic stamp cannot do negative numbers.
So that is my problem. How can i make the robot know which direction it is facing?
My other idea would be to add 1 every time it made a right turn, and subtract one every time it made a left turn. Except, instead of starting at 0, I would start at least say 40 (because it is divisible by 4).
Then I can tell its facing by 40/4 or 39/4, and whatever the remainder is, 0, 1 , 2, or 3, would be its facing and I can add or subtract from the x and y values based on that number.
Can anyone tell me if that will work? I don't know how to code it, or how the stamp deals with remainders. keep it mind I don't have a gps module, so I can't go that route.
I have scoured this forum for posts similar to this one to no avail. If anyone can help me with this code, me and my engineering class would greatly appreciate it.
Thank you
Comments
Your plan is theoretically sound, but practically flawed. I hate to rain on such an enthusiastic parade, but you're getting ahead of yourself where accurate navigational calculations are concerned. Robots (including BOE-bot) that use differential steering NEVER go straight. Not long enough for accurate calculations anyway. Even after careful calibration, they're always curving slightly. Friction, battery voltage, hysteresis, floor irregularities, wheel slippage, rolling resistance, all these variables and more conspire against you. And when a robot executes a given turn command, the actual angle turned will vary +/- a degree or two. Sounds slight, but the accumulated error keeps increasing. With every foot travelled and turn executed, your positional uncertainty grows. And not consistently, either. Try this: program your bot to execute a dozen fixed maneuvers, any combination of straight segments and turns. Set it in a fixed starting location and orientation, perhaps squared up against a wall for consistency. Use tape on your floor to mark your exact starting location. Run·the same sequence of maneuvers·a dozen times and mark the finish locations. You will probably find that your bot rarely ends up at the same location and heading. Welcome to the challenging world of robotics! Some people add wheel encoders to track motion better, but dead reckoning via wheel odometry on a differential drive platform is·one of the most·difficult tasks in all robotics. The best you can hope for is to minimize your error and periodically navigate to a known waypoint (ie, locate an inside corner wall) to zero out errors. The Probotics robot CYE was the best at this, and is still a great robot worthy of studying.
Beyond that bit of great news, you are correct that the Stamp's positive integer math has its limitations. Use finer resolution units for higher accuracy, and use word variables (64K max) instead of byte variables (255 max) in your cartesian coordinate system. For your origin (zero point), use 32K, 32K so you can·travel up to 32K units in each direction.
BTW, I'm tackling navigation on a Scribbler robot (diff-drive, not unlike BOE-bot) using a stationary IR beacon to locate a recharging base. It is also possible to navigate between multiple beacons. I'm writing an article for ROBOT magazine on this right now. I posted links to beacon videos at http://forums.parallax.com/showthread.php?p=716431 if you want to take a peek.
Good luck on your project, I hope I have not discouraged you too much. The real world is a frustrating place for robots and designers who desire consistency. But you're among friends here. We're all working on different aspects of robotics. I think accurate navigation is the most important, that's what I'm working on. Personally, I'm convinced that differential drive is the worst possible platform to base a dead-reckoning robot on. I'm having much better luck with different steering systems. Time will tell. Cheers.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·"If you build it, they will come."
-Phil
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·"If you build it, they will come."
Thanks very much