Quote:
Originally Posted by Greg Marra
Why does the "drive" library use a different metaphor than the rest of the program? I find this rather confusing. [/edit]
|
It would have been nice if everything worked using the -127 - +127 metaphor since it makes much more sense than having an arbitrary value of 127 for stopped. The reason the rest of the code doesn't do that is because of easyC compatibility. It had the SetPWM functions that did the 0-255 thing.
But the drive library make some things incredibly easy to do, especially around control problems. For example, you can use a gyro to drive in a straight line with this fairly simple program:
Code:
void main(void)
{
int heading;
InitGyro(1); // initialize gyro on port 1
TwoWheelDrive(2,1); // Setup 2 motor drive robot (ports 1 & 2)
StartGyro(1); // start gyro sampling
while (1)
{
heading = GetGyroAngle(1); // get the current heading
Drive(80, heading/2); // turn towards the error
}
}
And that's the whole program, no other files required.
So we use the drive stuff, but it isn't necessary. It helps with the bookkeeping of remember which way all the motors need to go and basically decouples the driving and turning values so you can think of them independently.