Recently during our state competition our inertial sensor had a bad cable that would sometimes transfer power but not data. We forgot to check for the semis and lost because of auto. Womp, womp.
However, I was wondering if anyone knows if you can check for a disconnected sensor. That way to prevent any future problems with cables or sensors we could have two inertial sensors on the bot and switch to the second if one ever disconnects.
To solve the problem quickly you could try zip tying the cable. When an IMU disconnects it returns inf, or at least it does in pros, so you could do something like this :
#include <cmath>
if(std::is_inf(IMU_value)){
use_other_one();
}
While youre at it because you have two imu when both of them are not disconnected you should average both of them to reduce the noise by a factor root(2). Also because IMU’s can be funky I would probably use the if statment std::is_inf() || std::is_nan() just in case. Good luck
How to make a Alert when a motor gets disconnected read this topic.
You can check for a disconnected vex device by using .installed();
// Assuming that you are using C++
if(InertialSensor.installed()){
// dosomething
}
else{
// Do something else
}
an example for how you could use this would be in this little function below :
inertial PrimaryInertial(PORT1);
inertial SecondaryInertial(PORT2);
controller Controller1(primary); // Defines the controler
motor L(PORT3); // Idealy you would have more than 2 motors but this is just a example
motor R(PORT4);
void turn(double desiredRotation,double motorPower = 50){ // This is a simple function that uses the error for direction
double error = 2;
while(fabs(error) > 1){ // If the error is not within a degree
if (PrimaryInertial.installed()){ // If our main sensor is plugged in work as normal
error = desiredRotation-PrimaryInertial.rotation(deg);
}
else{ // Our PrimaryInertial is unplugged?
if(SecondaryInertial.installed()){ // Check if our backup inertial is plugged in and use it instead
error = desiredRotation-SecondaryInertial.rotation(deg);
}
else{ // Both are unplugged and the user probley needs to be alerted
Controller1.rumble("......"); // Indicates a problem
}
} // End else above
L.spin(forward,motorPower * error / fabs(error),percent); // Spins the motor the desired power * the sign of the error
R.spin(reverse,motorPower * error / fabs(error),percent); // Spins the motor the desired power * the sign of the error
task::sleep(15); // A little wait to save resources
}
L.stop(hold); // Stop the motors
R.stop(hold);
}
int main(){
PrimaryInertial.startCalibration();
SecondaryInertial.startCalbration(); // Calibrate both sesnors
waitUntil(!PrimaryIntertial.isCalibrating()); // Since this is our primary sensor the secondary one can be done later
turn(5); // Turns 5 degrees
while(true){
task::sleep(15); // Wait for ever
}
}
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.