mrp (move relative position) is a function that will move a motor for a set distance at a set speed. This is probably the simplest way to move a lego robot. mrp starts a motor moving. The motor will stop after the wanted distance is achieved, but the CBC will continue going through the program unless you put a bmd. bmd (block motor done) stops the program from going to the next line until mrp finishes. If mrp has already finished, bmd does nothing. Note that you would need two mrp's and two bmd's for a robot with two motors. Only put a bmd if you want the program to halt until the motor is finished. mrp's speed is out of 1000. mrp's distance is measured in "ticks." Approximately 1100 ticks are in a full wheel rotation. This is NOT an exact number because every motor is slightly different, but it is a general rule of thumb. bmd only waits for one motor before continuing. If you have two motors on your robot, you will want two bmd's. mrp and bmd look like this:
mrp's arguments go like this:
mrp(**motor port**, **speed (out of 1000)**, **distance (1100 per rotation)**);
bmd's arguments look like this:
bmd(**motor port**);
An example would look like this:
int main() { mrp(0,1000,1100); mrp(1,1000,1100); bmd(0); bmd(1); }
Comments
So can we add as many bmd and
So can we add as many bmd and mrp as required by the situation????
Eg:
int main()
{
mrp(0,1000,1100);
mrp(1,1000,1100);
.
.
.
mrp(n, 1000, 1100);
bmd(0);
bmd(1);
.
.
.
bmd(n);
}
Equestrian vacations
Because every motor is a
Because every motor is a little different, one motor might finish the move before the other. If you just have 1 bmd, you run the risk of the robot being at angle when the move finishes because the slower motor won't have moved the entire amount. This will not be a big issue, but if you want your robot to drive perfectly straight, you should have two bmd's.
-Marty Rand
{
Senior programmer at Norman Advanced Robotics
Former senior programmer at Whittier Middle School
Youth Advisory Council
All around nerd
}
How important are the two
How important are the two bmd's? my team has always used one and it seems to work fine for us. I could see this being more useful for turns though.
I void warranties
-various people
True. 850 - 900 has been as
True. 850 - 900 has been as far as I could ever go without inducing major drift. Your results may vary.
-Marty Rand
{
Senior programmer at Norman Advanced Robotics
Former senior programmer at Whittier Middle School
Youth Advisory Council
All around nerd
}
It should be noted that 1000
It should be noted that 1000 is not usually full speed; it's just a random number KIPR made up. The actual full speed depends on the load on the motor. If you use a velocity that's too high, the motor will fall back to open-loop control (essentially the fd() function), and the robot will lose accuracy (including drift).
The correct way to deal with this is the getpwm() function. Watch the value returned by this function as your robot is moving. If it's stuck at the maximum (either 100 or 255, can't remember which), then your velocity is too high. Choose a velocity where getpwm() is not stuck at the maximum (it will fluctuate a bit; this is normal).
As an informal observation, 1000 has been way too high for several robots I've worked on. But you should find out for yourself for every robot you work on.
-Jeremy Rand
Senior Programmer, Team SNARC (2012), Norman Advanced Robotics (2010-2011), Norman High (2008-2009), Norman North (2005-2007), Whittier Middle School (2003-2004)
2012 VP of Comm, 2011 President, Botball Youth Advisory Council (2009-2012)