Mechatronics Robotics
/
BrobotV1
These are the core files for the Robot at Team conception.
Diff: Brobot.cpp
- Revision:
- 0:eba74e7a229b
- Child:
- 8:351b0b7b05b2
diff -r 000000000000 -r eba74e7a229b Brobot.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Brobot.cpp Fri May 26 07:40:48 2017 +0000 @@ -0,0 +1,73 @@ +/* + * BROBOT.cpp + * + */ + +#include <cmath> +#include "Brobot.h" + + +Brobot::Brobot(PwmOut* left, PwmOut* right, int number) +{ + pwmL = left; // set local references to objects + pwmR = right; + + this->number = number; +} + +// empty constructor +Brobot::Brobot() +{} + +void Brobot::rotate( float phi) +{ + if(phi>0.5f || phi<-0.5f) { + phi=0; + } + + *pwmL = 0.5f + phi; + *pwmR = 0.5f + phi; +} + +void Brobot::forward() +{ + *pwmL=0.65f; // asterisk is dereferencing the pointer so + *pwmR=0.36f; // you can access the variable at the pointers address + // also another way to dereference the pointer is: pwmR->write(0.xx) +} + +void Brobot::slow(float scale) +{ + if(scale>0.5f || scale<-0.5f) { + scale=0; + } + + *pwmL = *pwmL - scale; + *pwmR = *pwmR + scale; +} + +void Brobot::turnleft() +{ + *pwmL=0.48f; + *pwmR=0.31f; + wait(0.1); +} + +void Brobot::turnright() +{ + *pwmL=0.69f; + *pwmR=0.52f; + wait(0.1); +} + +void Brobot::back() +{ + *pwmR=0.65f; + *pwmL=0.35f; +} + +void Brobot::stop() +{ + *pwmR=0.5f; + *pwmL=0.5f; +} \ No newline at end of file