We are attempting to change our auton from time-based to sensor-based. We recently added a quad encoder to each side and a gyro and now we are attempting to implement the coding but are having a few issues. This is the first time we’ve tried using those sensors in competition, and our main goal is to have the sensor-based codes work as well as the time-based codes but with less sensitivity to variations in field conditions and battery levels.
-
Individually tested, the voids for GTurnRight, GTurnLeft, EncForward, & EncBackward work as expected and are within reasonable accuracy limits.
-
When added together, the first steps work correctly - but when it gets to the GTurnLeft it doesn’t ever move past it to the EncForward (no matter what we’ve played with, the robot goes until it does that turn and then sits there).
-
The quad encoders don’t appear to be re-setting to 0 after each movement in the debugger window, even though that is at the beginning of the void.
-
We know the Gyro has to initially sit for 2 secs in pre-auton. Afterwards, though, when you are running code with multiple turns - can you reset it quickly to 0 (without resting) just to make selecting degrees easier? For instance, can you say “GTurnRight 90 degrees”, reset to 0 on the move, do other things, then “GTurnRight 90 degrees” again?
-
Also on the Gyro - shouldn’t we be able to say degrees*10 so that what we enter as “int degrees” is 90 instead of having to put 900? We tried that and it didn’t seem to work correctly, but it seems like it should…
-
Anything else major missing or that ought to be incorporated (either immediately - for basic performance or eventually - for better performance later)?
We’re cutting down the code here, as we have an LCD and all codes together so it gets bulky.
(Note - we plan to eventually incorporate PID [or at least P] for straighter driving and perhaps tweak things like scaling and error some for even great accuracy, but we only have a few days to get things working well enough for an upcoming competition. We will then have much more time available to fine tune things!)
#pragma config(Sensor, in1, POT, sensorPotentiometer)
#pragma config(Sensor, in2, Gyro, sensorGyro)
#pragma config(Sensor, dgtl1, rightEncoder, sensorQuadEncoder)
#pragma config(Sensor, dgtl3, leftEncoder, sensorQuadEncoder)
#pragma config(Sensor, dgtl5, limitswitch, sensorTouch)
#pragma config(Motor, port1, rightMotorB, tmotorVex393HighSpeed_HBridge, openLoop, reversed, driveRight)
#pragma config(Motor, port2, rightMotorF, tmotorVex393HighSpeed_MC29, openLoop, reversed, driveRight)
#pragma config(Motor, port3, ArmMotor, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port4, Intake1, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port5, Intake2, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port6, Angler, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port7, Puncher2, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port8, Puncher1, tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor, port9, leftMotorF, tmotorVex393HighSpeed_MC29, openLoop, driveLeft)
#pragma config(Motor, port10, leftMotorB, tmotorVex393HighSpeed_HBridge, openLoop, driveLeft)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
/*---------------------------------------------------------------------------*/
/* Y */
/* Description: Competition template for VEX EDR */
/* */
/*---------------------------------------------------------------------------*/
// This code is for the VEX cortex platform
#pragma platform(VEX2)
// Select Download method as "competition"
#pragma competitionControl(Competition)
int count = 0; //Define
//Main competition background code...do not modify!
#include "Vex_Competition_Includes.c"
const short leftButton = 1;
const short centerButton = 2;
const short rightButton = 4;
//Wait for Press--------------------------------------------------
void waitForPress()
{
while(nLCDButtons == 0){}
wait1Msec(5);
}
//----------------------------------------------------------------
//Wait for Release------------------------------------------------
void waitForRelease()
{
while(nLCDButtons != 0){}
wait1Msec(5);
}
//----------------------------------------------------------------
/*---------------------------------------------------------------------------*/
/* 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 usercontrole 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()
{
SensorType[in5] = sensorNone;
wait1Msec(100);
SensorType[in5] = sensorGyro;
wait1Msec(2000);
bStopTasksBetweenModes = true;
//------------- Beginning of LCD Selection Code ---------------
//Clear LCD
clearLCDLine(0);
clearLCDLine(1);
//Battery voltage information
bLCDBacklight = true; //Enable/disable lcd backlight.
string mainBattery, powerexpander;
clearLCDLine(0); //Clear lcd lines.
clearLCDLine(1);
//Display the Primary Robot battery voltage
displayLCDString(0, 0, "Primary: ");
sprintf(mainBattery, "%1.2f%c", nImmediateBatteryLevel/1000,'V'); //Build the value to be displayed
displayNextLCDString(mainBattery);
//Display the Power Expander's voltage
sprintf (powerexpander, "%1.2f%c",SensorValue[in1] /4/45.6, 'v');
displayLCDString(1, 0, "Backup: ");
displayNextLCDString(powerexpander);
//How long to display voltage in milliseconds
wait1Msec(1000);
//Battery voltage information
//While loop until center button for selection
while(nLCDButtons != centerButton)
{
//Selecting Autonomous
switch(count){
case 0:
//Display first choice
displayLCDCenteredString(0, "B-F HF LF P"); //Rename "Code 1" etc. to name codes based on what they do.
displayLCDCenteredString(1, "< Enter >");
waitForPress();
//Increment or decrement "count" based on button press
//If left button is pressed switch to last code
if(nLCDButtons == leftButton)
{
waitForRelease();
count = 19;
}
else if(nLCDButtons == rightButton)
{
waitForRelease();
count++;
}
//
break;
__________________________________