Hi, I’m confused. :lol:
I was looking at someone’s code for a Kiwi drive robot (three omni wheels), and he’s doing something I don’t quite understand, and would like clarified.
He uses the same label for two two different functions, it seems, or I’m just not understanding some aspect of C?
Here’s his sketch (the simple form):
/* Kiwi drive macros and functions
* By Jonathan M. Guberman, 2011
* http://upnotnorth.net
*
* Use this code however you like, but don't blame me if it doesn't work!
*/
#include <Servo.h>
#define SPEED(x) (90 + (x))
#define DRIVE(x,y,z) servo1.write(90 + (x)); servo2.write(90 + (y));servo3.write(90 + (z))
#define MAXSPEED 20
Servo servo1;
Servo servo2;
Servo servo3;
void setup()
{
}
void loop()
{
}
void setDrive(int angle, int maxspeed){
float x = cos(3.14159 * (float) angle / 180);
float y = sin(3.14159 * (float) angle / 180);
DRIVE((int)(x*maxspeed),(int)((-0.5*x + 0.866*y)*maxspeed),(int)((-0.5*x-0.866*y)*maxspeed));
}
void setDrive(int angle){
setDrive(angle, MAXSPEED);
}
void stopDrive(){
DRIVE(0,0,0);
}
void stopDrive(int time){
stopDrive();
delay(time);
}
How is the complier understanding the difference between a call to stopDrive() and stopDrive(value) or setDrive() and setDrive(value)? What is actually going on here, and what are the limitations?