Our team has many brand new sensors on our robot but we continue to have consistency issues with our our autonomous. We test the sensors and they work but when we run our program the values are spurratic and inconsistent so our autonomous sometimes works ok and sometimes doesn’t work right at all.
Any help would be greatly appreciated.
Let’s see some code
#pragma config(I2C_Usage, I2C1, i2cSensors)
#pragma config(Sensor, in1, potR, sensorPotentiometer)
#pragma config(Sensor, in2, acc1, sensorAccelerometer)
#pragma config(Sensor, in3, acc2, sensorAccelerometer)
#pragma config(Sensor, in7, gyro, sensorGyro)
#pragma config(Sensor, in8, potL, sensorPotentiometer)
#pragma config(Sensor, dgtl7, Rsonar, sensorSONAR_inch)
#pragma config(Sensor, dgtl9, Bsonar, sensorSONAR_inch)
#pragma config(Sensor, dgtl11, Lsonar, sensorSONAR_inch)
#pragma config(Sensor, I2C_1, enc, sensorQuadEncoderOnI2CPort, , AutoAssign)
#pragma config(Motor, port1, Scorer, tmotorVex393HighSpeed, openLoop, reversed)
#pragma config(Motor, port2, RF, tmotorVex393HighSpeed, openLoop, reversed)
#pragma config(Motor, port3, RR, tmotorVex393HighSpeed, openLoop, reversed, encoder, encoderPort, I2C_1, 1000)
#pragma config(Motor, port4, Lift, tmotorVex393, openLoop)
#pragma config(Motor, port5, Swerve, tmotorVex393, openLoop, reversed)
#pragma config(Motor, port6, Flip, tmotorVex393, openLoop)
#pragma config(Motor, port7, Lift2, tmotorVex393, openLoop)
#pragma config(Motor, port8, LR, tmotorVex393HighSpeed, openLoop)
#pragma config(Motor, port9, LF, tmotorVex393HighSpeed, openLoop, reversed)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
#pragma platform(VEX)
//Competition Control and Duration Settings
#pragma competitionControl(Competition)
#pragma autonomousDuration(20)
#pragma userControlDuration(120)
#include "Vex_Competition_Includes.c" //Main competition background code...do not modify!
float power=0;
float conversion1=.066;
int motorpower=0;
task wheelalign()
{
if(SensorValue[potL]>SensorValue[potR])
{
motor[Swerve] = ((SensorValue[potL]-SensorValue[potR]) / 24.93);
}
if(SensorValue[potR]>SensorValue[potL])
{
motor[Swerve] = -(((SensorValue[potL]-SensorValue[potR]) / 22.17));
}
}
void pre_auton()
{
}
task autonomous()
{
////////////Notes////////////
// Pot.Left(straight) = 1924
// Pot.Right(straight) = 1840
// Pot.Left(right) = 629
// Pot.Right(right) = 3445
// Pot.Left(left) = 3585
// Pot.Right(left) = 419
// Enc Clicks(360*) = 391
// Pot.Difference(Left) = 3166(Motorvalue Conversion = 24.93)
// Pot.Difference(Right) = 2816(Motorvalue Conversion = 22.17)
//////Pre-Set Motor Functions//////
//
// Forward = motor[RF] = 127;
// motor[LF] = 127;
// motor[RR] = 127;
// motor[LR] = 127;
//
// Backwards = motor[RF] = 127;
// motor[LF] = 127;
// motor[RR] = 127;
// motor[LR] = 127;
//
// Rotate Left = motor[RF] = 127;
// motor[LF] = -127;
// motor[RR] = 127;
// motor[LR] = -127;
//
// Rotate Right = motor[RF] = -127;
// motor[LF] = -127;
// motor[RR] = 127;
// motor[LR] = -127;
//
// Stop = motor[RF] = 0;
// motor[LF] = 0;
// motor[RR] = 0;
// motor[LR] = 0;
SensorValue[enc] = 0;
motor[Flip] = 127;
wait1Msec(1500);
motor[Flip] = 0;
while(SensorValue[enc] > -442)
{
motor[RF] = 70;
motor[LF] = 70;
motor[RR] = 70;
motor[LR] = 70;
}
motor[RF] = 0;
motor[LF] = 0;
motor[RR] = 0;
motor[LR] = 0;
SensorValue[enc] = 0;
while(SensorValue[enc] < 151)
{
motor[Flip] = -85;
motor[RF] = -100;
motor[LF] = -100;
motor[RR] = -100;
motor[LR] = -100;
}
motor[RF] = 0;
motor[LF] = 0;
motor[RR] = 0;
motor[LR] = 0;
wait1Msec(1200);
motor[Flip] = 0;
while(SensorValue[potL] <= 3585)
{
motor[Swerve] = 70;
}
motor[Swerve] = 0;
while(SensorValue[Rsonar] <= 39)
{
motor[RF] = 70;
motor[LF] = 70;
motor[RR] = 70;
motor[LR] = 70;
}
motor[RF] = 0;
motor[LF] = 0;
motor[RR] = 0;
motor[LR] = 0;
}
task usercontrol()
{
while (true)
{
motor[RF] = vexRT[Ch3] - vexRT[Ch4];
motor[RR] = vexRT[Ch3] - vexRT[Ch4];
motor[LF] = vexRT[Ch3] + vexRT[Ch4];
motor[LR] = vexRT[Ch3] + vexRT[Ch4];
motor[Swerve] = vexRT[Ch1];
if(vexRT[Btn5D] == 1)
{
motor[Lift] = 127;
motor[Lift2] = -127;
}
else if (vexRT[Btn5U] == 1)
{
motor[Lift] = -127;
motor[Lift2] = 127;
}
else if (vexRT[Btn5D] == 0)
{
motor[Lift] = 0;
motor[Lift2] = 0;
}
if(vexRT[Btn6U] == 1)
{
motor[Flip] = -127;
}
else if (vexRT[Btn6D] == 1)
{
motor[Flip] = 127;
}
else if (vexRT[Btn6U] == 0)
{
motor[Flip] = 0;
}
if(vexRT[Btn8D] == 1)
{
motor[Scorer] = 127;
}
else if (vexRT[Btn8U] == 1)
{
motor[Scorer] = -127;
}
else if (vexRT[Btn8D] == 0)
{
motor[Scorer] = 0;
}
}
}
What are the sensors you are using? What is it that you are trying to accomplish in autonomous?
EDIT:
Please wrap your code in "
[CODE]
" tags. This keeps us from having to scroll through a of your code, and also keeps formatting.
~Jordan
We have 1 IME, 2 pots, a gyro, and 3 ultrasonics.
Firstly, my experience with VEX Ultrasonic Sensors showed that they had a bit of “noise”, so perhaps you could take the average of the past 5 values or so in order to get a more accurate reading. Also, if you want, I would look into creating some functions for driving in autonomous, so you don’t have to copy/paste code. Perhaps one function for driving using IMEs, one for driving using Ultrasonics, and another for turning using the gyro.
~Jordan
Our problem is we run the autonomous once and it does one thing, then the next time it does something completely different.
EX: Encoders will drive for about a foot and the next time they drive for almost 10ft.
Hm. And this is definitely when you are driving based on the IME, and not the ultrasonic sensor? Have you tried turning off the robot, remotes, disabling the competition switch, then powering back on, etc., between tests?
Not just the encoders, the ultrasonics are failing as well. We have to power cycle the robot because we are using robotC and we have tried a combination of turning stuff on and off. We tried new keys and batteries and all the sensors on our robot are brand new, out of the box and they worked fine yesterday when we had them.
Welcome to the real world.
The recommended way of using IMEs is via the nMotorEncoder variable. Try using
nMotorEncoder RR ]
instead of
SensorValue[enc]
What are you seeing this encoder doing in the debug window? Does it start from the wrong value, does it get to the correct value?
first, we realize the sensors arent perfect and our autonomous might vary slightly between runs but like we said normally it drives 1 foot and then for one run it will drive across the entire field when we didn’t make any changes to the encoder part of the program. And second, when we just ran the autonomous the encoder values were fine but this time the potentiometers didn’t work right so the motors spun continuously when we did not make any changes to the program.
my first thought is that it might be an ESD (electro-static discharge) problem.
if a am correct, that what is happening is that the part of the brain that controls what the motors are set to is getting shocked and resetting (which takes time) while your motors keep on spinning.
the main culprit is i2c sensors because the are inside the surge protection (I think I heard that)
this sounds kinda out there, but it was a real problem last year and caused many teams grief.
try disabling the code when it goes farther than expected, if it won’t then it could be ESD.
the only fix I have found is to avoid the ime’s like the pelage.
Best of luck
Phillip.
It sounds like something is not reset after it is used.
/* WAS THIS
SensorValue[enc] = 0;
while(SensorValue[enc] > -442)
*/
nMotorEncoder[RR] = 0;
while(abs(nMotorEncoder[RR]) < 442) //note abs()
{
motor[RF] = 70;
motor[LF] = 70;
motor[RR] = 70;
motor[LR] = 70;
}
motor[RF] = 0;
motor[LF] = 0;
motor[RR] = 0;
motor[LR] = 0;
/*
SensorValue[enc] = 0;
while(SensorValue[enc] < 151)
*/
nMotorEncoder[RR] = 0;
while (abs(nMotorEncoder[RR]) < 151) //note abs()
{
motor[Flip] = -85;
motor[RF] = -100;
motor[LF] = -100;
motor[RR] = -100;
motor[LR] = -100;
}
motor[RF] = 0;
motor[LF] = 0;
motor[RR] = 0;
motor[LR] = 0;
You might want to take a look at this video.
It was created for PROS, but is applicable to RobotC as well.
we just switched our Sensorvalue[enc] to nMotorencoder[RR] and the robot drove forward and didn’t stop, then when we switched it back it worked fine…
https://vexforum.com/attachment.php?attachmentid=7788&stc=1&d=1384375507
(Should have saved it as a PNG; sorry for the compression. :p)
Well, that’s because you have it on a reversed motor. One feature of the nMotorEncoder variable is that ROBOTC will reverse that for you so positive motor commands always result in positive encoder counting. When you were using the SensorValue method you had to do this yourself which is why you had negative values in the code.
All of this should be obvious if you are using the ROBOTC motor and sensors debug windows.
Ok, lets not start this crazy debate again. ESD issues are rare, it was a small problem last year but improvements made to ROBOTC 3.6 and later helped tremendously.
If you want to understand some of the background on last years issues, read this thread from post #1.
https://vexforum.com/t/esd-my-thoughts/23332/1
and also this thread.
https://vexforum.com/t/ime-technical-description-and-software-workarounds/23218/1
Sorry for dragging this off topic really quick, but what are the advantages of using nMotorEncoder instead of SensorValue? I’ve always used SensorValue and never really had any problems. Is the only difference that nMotorEncoder will automatically reverse the encoder values if the motor is reversed, or is there something else I’m missing out on?
SensorValue returns 16 bit so it will rollover at 32767 (or 52 revs on a 393 on torque). nMotorEncoder returns a 32 bit value. Rollover may not be a problem but it’s something that can be avoided. Other than the automatic reversal, nothing else I know of.
Makes sense, I haven’t quite programmed an autonomous routine where I want the robot to drive 32767 ticks in one go, but if I ever do I’ll make sure I switch to nMotorEncoder :D! Thanks jpearman!