I’m trying to make a slew rate function since the robot is really jerky in the auton if we go 100% power. The function itself compiled and when we put it to test, it did one wheel at a time. its because it goes through each motor separately. How do I make a non-blocking function because tasks don’t seem to work, it gives me an error for some reason. I don’t know if I should make a class or a method for slew rate, but I really want to implement it into our bot.
Here’s the code:
double wheel_diameterCM = 10.16;
double circumfrence = wheel_diameterCM * M_PI;
//Idk if its the best way to do this, but i dont know how to make a method or a nonblocking function in C++
int slew_rate(vex::motor MotorName, int end_power, int time, double dist_to_destinationCM, bool rev){
MotorName.resetRotation();
double deg_to_rotate = (360 * dist_to_destinationCM) / circumfrence; //277
if (rev == false){
while (deg_to_rotate > MotorName.rotation(vex::rotationUnits::deg)){
int power = 5;
MotorName.setVelocity(0,vex::percentUnits::pct);
MotorName.spin(vex::directionType::fwd);
while (power < (end_power - 5) && deg_to_rotate > MotorName.rotation(vex::rotationUnits::deg)){
MotorName.setVelocity(power,vex::percentUnits::pct);
power += 5;
vex::task::sleep(time);
}
if (MotorName.rotation(vex::rotationUnits::deg) > deg_to_rotate - circumfrence){
while (power > 0 && deg_to_rotate > MotorName.rotation(vex::rotationUnits::deg)){
MotorName.setVelocity(power,vex::percentUnits::pct);
power -= 10;
vex::task::sleep(100);
}
}
MotorName.stop();
}
}else if (rev == true){
while (deg_to_rotate > MotorName.rotation(vex::rotationUnits::deg)){
int power = 5;
MotorName.setVelocity(power,vex::percentUnits::pct);
MotorName.spin(vex::directionType::rev);
while (power < end_power && deg_to_rotate > MotorName.rotation(vex::rotationUnits::deg)){
MotorName.setVelocity(power,vex::percentUnits::pct);
power += 5;
vex::task::sleep(time);
}
if (MotorName.rotation(vex::rotationUnits::deg) > deg_to_rotate - circumfrence){
while (power > 0 && deg_to_rotate > MotorName.rotation(vex::rotationUnits::deg)){
MotorName.setVelocity(power,vex::percentUnits::pct);
power -= 10;
vex::task::sleep(100);
}
}
MotorName.stop();
}
}
return 0;
}
///////this is the function part////////////
void move_slew_fwd (int time, double dist, bool rev){
vex::task t1 (slew_rate(FrontRight, 100,time, dist, false));
vex::task t2 (slew_rate(FrontLeft, 100,time, dist, false));
vex::task t3 (slew_rate(RearRight, 100,time, dist, false));
slew_rate(RearLeft, 100, time, dist, false) // I tried to make a nonBlock here but it gives me errors in the tasks
}
Thank you!