I’ve been trying to make some nice turning with an inertial sensor, I’ve started off with a P loop, to see if it was consistent enough, and it appears to be. even with different amounts of cubes in my tray, it will always reach the same angle each time. But I’ve been having the strangest issues with my turning P loop.
/*----------------------------------------------------------------------------*/
/* */
/* Module: main.cpp */
/* Author: VEX */
/* Created: Wed Dec 04 2019 */
/* Description: This program will turn right 90 degrees using the */
/* Inertial Sensor. */
/* */
/* */
/* */
/*----------------------------------------------------------------------------*/
// ---- START VEXCODE CONFIGURED DEVICES ----
// Robot Configuration:
// [Name] [Type] [Port(s)]
// LFdrive motor 1
// LBdrive motor 20
// Inertial2 inertial 2
// RFdrive motor 12
// RBdrive motor 10
// ---- END VEXCODE CONFIGURED DEVICES ----
#include "vex.h"
using namespace vex;
double P = 0.092;
double error = 0;
bool turnPactive = false;
int desiredAngle = 90;
int driveP (){
while(turnPactive){
error = desiredAngle - Inertial2.rotation(degrees);
int turnPower = error * P;
LFdrive.spin(forward, turnPower, voltageUnits:: volt);
LBdrive.spin(forward, turnPower, voltageUnits:: volt);
RFdrive.spin(reverse, turnPower, voltageUnits:: volt);
RBdrive.spin(reverse, turnPower, voltageUnits:: volt);
};
return 1;
};
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
Inertial2.calibrate();
// waits for the Inertial Sensor to calibrate
while (Inertial2.isCalibrating()) {
wait(100, msec);
}
vex::task turnip(driveP);
wait(2,seconds);
turnPactive = true;
}
This code works if you comment out the wait command before the turning. but if you have anything at all before the turning it won’t turn. This means that when I tried to code an auton, it would move forward as desired, but wouldn’t start the turn. I stripped it down to just this program trying to find the issue, to confirm it wasn’t an issue with my drive pid or anything in my competition program conflicting. It might be an issue with the way I’m multitasking or something, because it will only turn if I have no delay before I set turnPactive to true. no idea why, I’ve been troubleshooting for hours. I really appreciate the assistance.