7 double map(
double x,
double in_min,
double in_max,
double out_min,
double out_max) {
8 return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
12 if(!
myRIO_init()) {cout <<
"Error initializing myRIO";
return -1;}
24 const long sampleTimeUs = 500;
26 Wifi w([&](
long data) {
27 double motorLeftSpeed = static_cast<char>((data&0xFF00)>>8);
28 double motorRightSpeed = static_cast<char>(data&0xFF);
30 if(motorLeftSpeed > 127) motorLeftSpeed -= 255;
31 if(motorRightSpeed > 127) motorRightSpeed -= 255;
33 motorLeftSpeed =
map(motorLeftSpeed, -128, 127, -850, 850);
34 motorRightSpeed =
map(motorRightSpeed, -128, 127, -850, 850);
36 if(abs((
int)ceil(motorLeftSpeed))<50) motorLeftSpeed = 0;
37 if(abs((
int)ceil(motorRightSpeed))<50) motorRightSpeed = 0;
61 double correctedL = motorLeftPid.
compute(encL);
66 double correctedR = motorRightPid.
compute(encR);
73 double dutyCycle =
map(force, 0, 5, 0, 100);
74 if(dutyCycle>100) dutyCycle = 100;
78 proxi = 27.726*pow(proxi, -1.2045);
79 dutyCycle =
map(proxi, 10, 100, 100, 0);
80 if(dutyCycle>100) dutyCycle = 100;
81 if(dutyCycle<0) dutyCycle = 0;
void setAngularSpeedAndDirection(double speed)
Set the speed in angular speed and the direction.
void setDutyCycle(double dutyCycle)
Set the Duty Cycle.
This class can be used to regulate a motor speed.
static void writeLed(int led, bool state)
Write to a led.
bool getDefaultDirection()
Get the default direction of the motor.
void setSetpoint(double setpoint)
Set the setpoint.
Use this class to exchange data via wifi.
long getEncoderPulses()
Get the Encoder values.
double compute(long enc)
Refresh the PID output.
double map(double x, double in_min, double in_max, double out_min, double out_max)
static double readPin(int pin)
Read an analog pin.
Outputs a PWM signal (3.3V)
static void wait_us(long int us)
Wait function in microseconds.
Combination of PWM and Encoder to work with motors.