Every time we start my autonomous it does something different and won’t do anything we want it to. Please help.
Maybe give examples of what exactly is going one? Post your code? Even just a general idea of what your code is?
I I had to guess, you are using time code and or using v4. As stated above, posting you code will help a lot.
Sometimes, if you don’t stop ALL your motors after a run
yourmotor.stop();
weird things can happen the next run. One of VexcodeV5s flaws.
I’m using time code in v5 because we can’t figure out how to get shaft encoders to work.
Here’s my code
#include “vex.h”
using namespace vex;
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
FrontRoller.spin(directionType::fwd,100,velocityUnits::pct);
BackRoller.spin(directionType::rev,100,velocityUnits::pct);
task::sleep(2000);
FrontRoller.stop(brakeType::brake);
BackRoller.stop(brakeType::brake);
LeftFront.spin(directionType::fwd,50,velocityUnits::pct);
LeftBack.spin(directionType::fwd,50,velocityUnits::pct);
RightFront.spin(directionType::fwd,50,velocityUnits::pct);
RightBack.spin(directionType::fwd,50,velocityUnits::pct);
task::sleep(1500);
LeftFront.stop(brakeType::brake);
LeftBack.stop(brakeType::brake);
RightFront.stop(brakeType::brake);
RightBack.stop(brakeType::brake);
FrontRoller.spin(directionType::fwd,100,velocityUnits::pct);
BackRoller.spin(directionType::rev,100,velocityUnits::pct);
task::sleep(1000);
FrontRoller.stop(brakeType::hold);
BackRoller.stop(brakeType::hold);
LeftBack.spin(directionType::fwd,50,velocityUnits::pct);
RightFront.spin(directionType::fwd,50,velocityUnits::pct);
task::sleep(1000);
LeftBack.stop(brakeType::brake);
RightFront.stop(brakeType::brake);
LeftFront.spin(directionType::fwd,50,velocityUnits::pct);
LeftBack.spin(directionType::rev,50,velocityUnits::pct);
RightFront.spin(directionType::fwd,50,velocityUnits::pct);
RightBack.spin(directionType::fwd,50,velocityUnits::pct);
RightIntake.spin(directionType::fwd,50,velocityUnits::pct);
LeftIntake.spin(directionType::fwd,50,velocityUnits::pct);
FrontRoller.spin(directionType::fwd,50,velocityUnits::pct);
BackRoller.spin(directionType::fwd,50,velocityUnits::pct);
task::sleep(1000);
LeftFront.stop(brakeType::brake);
LeftBack.stop(brakeType::brake);
RightFront.stop(brakeType::brake);
RightBack.stop(brakeType::brake);
RightIntake.stop(brakeType::brake);
LeftIntake.stop(brakeType::brake);
BackRoller.stop(brakeType::brake);
FrontRoller.stop(brakeType::brake);
}
Well…I’m no expert on coding but to me everything looks fine.
There is one thing though…I cant remember what unit the time value is in, I believe telling it to sleep for 2000 is 20 seconds if I’m not mistaken. Don’t quote me on that since I use a value of 1 for my while loops and I don’t really use anything higher.
I used time in my middle school years. When I turned to v5 I used time code as well and from what it sounds like you are having the same issues. I have no clue why it did thst but ever sense I changed the way I code auton I have never had that problem. Some people on my team called me crazy and thst I just changed the code but once I showed them they were extremely confused
What do you mean by it does something different? Do you go to a different spot every time? Are you a couple of inches off from run to run? It is hard to help you without understanding the issue. Since you are using v5, you can use the internal encoders to move the motors a fixed number of rotations instead of time. This could help improve your autonomous
for example, to move forward…
LeftFront.startRotateFor(); // need to fill in the amount of rotations and speed
LeftBack.startRotateFor();
RightFront.startRotateFor();
RightBack.rotateFor()
We actually have had the same experience the past few years. We also used time functions, This year though we have been using rotations, which have so far worked much better.
For example:
TopMotor2.spinFor(forward, -10, turns, false);
TopMotor.spinFor(forward, 10, turns, false);
waitUntil(TopMotor.isDone());
vex::task::sleep (50);
The weird thing is that I used time code in v5 for the past two years and never once experienced this problem
I mean that sometimes when I start the code it is different every time we start. One time it the lift motors start and we score a point the next the robot is driving into the wall and tries to break through it.
I wasnt entirely sure since Robot-mesh has 2 time units
it has
vex::sleep()
and
vex::sleepMs()
not really units but they’re both a vex task
Oh my… switch to using the integrated motor encoders! It’s not that hard, I promise. I’m amazed anyone gets anywhere using timings. Here’s an example:
topLeftMotor.rotateFor(-200, deg, false);
topRightMotor.rotateFor(-200, deg, false);
bottomLeftMotor.rotateFor(-200, deg, false);
bottomRightMotor.rotateFor(-200, deg, true);
Each motor will rotate backwards 200 degrees. The true/false things are are “blocking,” if its true then the program will wait at that line until the motor has completed that rotation, and it will continue immediately if it’s true. You can also change the deg to rev for revolutions, and make the 200 positive to drive forward.
You should also look into using drivetrain commands, they would be helpful
When you are driving into the wall, is it trying to go to the goal and just missing or is it going a completely different direction? As @JasonFPV put it, I suspect that it is your use of time based movement that is causing problems.
The issue to time based autonomous is that you have little repeatability. Some days, you will have a perfect run and others it won’t work at all. Using sensors such as internal encoders of the v5 motors should give a better auton run.
Also, for the type description
i.e.
motor1.spin(directionType::fwd, 75, velocityUnits::pct);
motor1.stop(brakeType::brake);
you don’t have to type ‘directionType’ or ‘brakeType’ you can just put
motor1.spin(fwd, 75, velocityUnits(pct));
motor1.stop();
you don’t need to specify the brake type if you’re just using brake
you only really need to specify units
it makes the code look a bit cleaner
The issue is that slop in the gear box can be off by a lot. Which is typically the issue for inconsistent auton with v5. You can fix this by adding tracking wheels. Odometry isn’t necessary but allows for more complex algorithms.
It should be noted that for the last line that the rotateFor function automatically sets blocking parameter to true if nothing is there. So, the extra true parameter is extraneous.
bottomRightMotor.rotateFor(-200, deg);
I would but were using an x drive so using the integrated encoders wouldn’t work.