we are having trouble with our gyros in autonomous. I have the code copied below. the problem is that it doesn’t stop spinning. the gyro readings also do not appear on the controller screen.
#include “robot-config.h”
/---------------------------------------------------------------------------/
/* /
/ Description: Competition template for VCS VEX V5 /
/ /
/---------------------------------------------------------------------------*/
//Creates a competition object that allows access to Competition methods.
vex::competition Competition;
///////////////////////////////////////////////////////////////////
//variable definitions
//////////////////////////////////////////////////////////////////////
double wheelDiameterIN = 2.75;
double circumference = wheelDiameterIN * M_PI;
////////////////////////////////////////////////////////////
//distance
//////////////////////////////////////////////////////////////////
void dist (int in){
(360 * in) / circumference;
}
//////////////////////////////////////////////////////////////////////////////
//straight
/////////////////////////////////////////////////////////////////////////////////
void straight (int speed,int dist){
FL.startRotateFor(dist,rotationUnits::deg,speed,velocityUnits::pct);
BL.startRotateFor(dist,rotationUnits::deg,speed,velocityUnits::pct);
FR.startRotateFor(dist,rotationUnits::deg,speed,velocityUnits::pct);
BR.rotateFor(dist,rotationUnits::deg,speed,velocityUnits::pct);
}
//////////////////////////////////////////////////////////////////////////////////////
//right turn
/////////////////////////////////////////////////////////////////////////////////////
void RTurn (int speed, int degree){
//while loop will prevent code from moving on until requirements are met
while (((Gyro1.value(rotationUnits::deg))+(Gyro2.value(rotationUnits::deg)))/2<= -degree){
FL.spin(directionType::fwd, speed,velocityUnits::pct);
BL.spin(directionType::fwd, speed,velocityUnits::pct);
FR.spin(directionType::rev, speed,velocityUnits::pct);
BR.spin(directionType::rev, speed,velocityUnits::pct);
Controller1.Screen.print("Gyro");//this will show the value of the gyro on screen
Controller1.Screen.newLine();
Controller1.Screen.print("Reading = %f");
task::sleep(10);//this helps reserve battery powerwhile doing
}
//once these requirements are met the wheels stop
FL.stop(brakeType::brake);
BL.stop(brakeType::brake);
FR.stop(brakeType::brake);
BR.stop(brakeType::brake);
}
///////////////////////////////////////////////////////////////////////////
//left turn
//////////////////////////////////////////////////////////////////////////////////
void LTurn (int speed, int degree){
//while loop will prevent code from moving on until requirements are met
while (((Gyro1.value(rotationUnits::deg))+(Gyro2.value(rotationUnits::deg)))/2<= degree){
FL.spin(directionType::rev, speed,velocityUnits::pct);
BL.spin(directionType::rev, speed,velocityUnits::pct);
FR.spin(directionType::fwd, speed,velocityUnits::pct);
BR.spin(directionType::fwd, speed,velocityUnits::pct);
Controller1.Screen.print("Gyro");//this will show the value of the gyro on screen
Controller1.Screen.newLine();
Controller1.Screen.print("Reading = %f");
task::sleep(10);//this helps reserve battery powerwhile doing
}
//once these requirements are met the wheels stop
FL.stop(brakeType::brake);
BL.stop(brakeType::brake);
FR.stop(brakeType::brake);
BR.stop(brakeType::brake);
}
////////////////////////////////////////////////////////////////////////////////////
//lift
///////////////////////////////////////////////////////////////////////////
void arm (int degar,int spd){
Lift.rotateTo(21degar,rotationUnits::deg,spd,velocityUnits::pct);
}
////////////////////////////////////////////////////////////////////////////////////
//intake
///////////////////////////////////////////////////////////////////////////
void roller (int deger,int spid){
IntakeL.spin(directionType::fwd, spid,velocityUnits::pct);
IntakeR.spin(directionType::fwd, spid,velocityUnits::pct);
}
/---------------------------------------------------------------------------/
/ Pre-Autonomous Functions /
/ /
/ You may want to perform some actions before the competition starts. /
/ Do them in the following function. You must return from this function /
/ or the autonomous and usercontrol tasks will not be started. This /
/ function is only called once after the cortex has been powered on and /
/ not every time that the robot is disabled. /
/---------------------------------------------------------------------------*/
void pre_auton( void ) {
// All activities that occur before the competition starts
// Example: clearing encoders, setting servo positions, …
task::sleep(1500);
}
/---------------------------------------------------------------------------/
/* /
/ Autonomous Task /
/ /
/ This task is used to control your robot during the autonomous phase of /
/ a VEX Competition. /
/ /
/ You must modify the code to add your own robot specific commands here. /
/---------------------------------------------------------------------------*/
void autonomous( void ) {
IntakeL.spin(directionType::fwd, 100,velocityUnits::pct);
IntakeR.spin(directionType::fwd, 100,velocityUnits::pct);
straight(100,36);
vex::task::sleep(1000);
straight(100,-30);
LTurn(50,90);
straight(100,24);
RTurn(100,90);
straight(100,24);
vex::task::sleep(1000);
straight(100,-30);
RTurn(100,115);
straight(100,43);
LTurn(100,65);
straight(50,6);
vex::task::sleep(1000);
Tray.rotateTo(805,rotationUnits::deg,100,velocityUnits::pct);
straight(50,-12);
}
/----------------------------------------------------------------------------/
/* /
/ User Control Task /
/ /
/ This task is used to control your robot during the user control phase of /
/ a VEX Competition. /
/ /
/ You must modify the code to add your own robot specific commands here. /
/----------------------------------------------------------------------------*/
void usercontrol( void ) {
// User control code here, inside the loop
while (1){
Brain.Screen.clearScreen();
Brain.Screen.printAt(20,80, "Gyro");
Brain.Screen.printAt(20,120,"Readunf = %f", Gyro1.value(rotationUnits::deg));
FL.spin(directionType::fwd, Controller1.Axis3.value(), vex::velocityUnits::pct);
BL.spin(directionType::fwd, Controller1.Axis3.value(), vex::velocityUnits::pct);
FR.spin(directionType::fwd, Controller1.Axis2.value(), vex::velocityUnits::pct);
BR.spin(directionType::fwd, Controller1.Axis2.value(), vex::velocityUnits::pct);
if (Controller1.ButtonB.pressing()){
Tray.spin(directionType::fwd, 100, vex::velocityUnits::pct);
}
else if (Controller1.ButtonA.pressing()){
Tray.spin(directionType::rev, 100, vex::velocityUnits::pct);
}
else{
Tray.stop(brakeType::hold);
}
if (Controller1.ButtonL1.pressing()){
Lift.spin(directionType::fwd, 100, vex::velocityUnits::pct);
}
else if (Controller1.ButtonL2.pressing()){
Lift.spin(directionType::rev, 100, vex::velocityUnits::pct);
}
else{
Lift.stop(brakeType::hold);
}
if (Controller1.ButtonR1.pressing()){
IntakeL.spin(directionType::fwd, 100, vex::velocityUnits::pct);
IntakeR.spin(directionType::fwd, 100, vex::velocityUnits::pct);
}
else if (Controller1.ButtonR2.pressing()){
IntakeL.spin(directionType::rev, 100, vex::velocityUnits::pct);
IntakeR.spin(directionType::rev, 100, vex::velocityUnits::pct);
}
else{
IntakeL.stop(brakeType::hold);
IntakeR.stop(brakeType::hold);
}
vex::task::sleep(20); //Sleep the task for a short amount of time to prevent wasted resources.
}
}
//
// Main will set up the competition functions and callbacks.
//
int main() {
//Run the pre-autonomous function.
pre_auton();
//Set up callbacks for autonomous and driver control periods.
Competition.autonomous( autonomous );
Competition.drivercontrol( usercontrol );
//Prevent main from exiting with an infinite loop.
while(1) {
vex::task::sleep(100);//Sleep the task for a short amount of time to prevent wasted resources.
}
}