autonomous code

We need help with our auton code. We have a six motor holomatic drive. It doesn’t stop when it’s supposed to. It keeps spinning in circles.

void autonTurnRight(float autonDegreesRight)
{
SensorValue[frontLeftEncoder]=0;
while ((SensorValue(frontLeftEncoder)*0.0425423997) < (autonDegreesRight / 5))
// divide by 360 to get rotations, times pi, times wheel diameter, times 1.5 for wheel type
{
motor[frontRight1] = -127;
motor[backRight1] = -127;
motor[backRight2] = -127;
motor[frontLeft1] = 120;
motor[backLeft1] = 120;
motor[backLeft2] = 120;
}	//end while loop for forward motion
motor[frontRight1] = 0;
motor[backRight1] = 0;
motor[backRight2] = 0;
motor[frontLeft1] = 0;
motor[backLeft1] = 0;
motor[backLeft2] = 0;
delay(500);
}

{
autonTurnRight(90);
}

I am assuming you meant holonomic. Try taking a look at this.
[https://vexforum.com/t/holonomic-drives-2-0-a-video-tutorial-by-cody/27052/1)

Six motors you say?

Gib picture.

BTW, good job actually posting your code and using the code button. You get “didn’t ask the forum to read your mind” ribbon.

There are two motors on each back wheel and one on each front wheel. Thanks for the quick replies.

Ah OK, my code that Aiden posted will work for you with minimal edits to account for the extra two motors, and actually if those are using Y cables no edit is required.

That code isn’t for autonomous.

No it’s not but it can be adapted.

Let’s say you wrote a function like so…

go(direction, speed)

where direction was converted into a pair of x, y floats and fed into the typical holonomic code.

Basically instead of hard-coding the wheel values, think of hard-coding what the joystick does.

I’ll try that. Thanks!

It doesn’t work. We based it off our drive code but it only works with time.

void autonDrive(int rightX, int rightY, int leftX, int leftY, int time)
{
while (true)
{
int X2 = 0, Y1 = 0, X1 = 0, Y2 = 0, threshold = 15;
int temp1=0, temp2=0, temp3=0, temp4=0;

//Loop Forever
while(true)
{

if(abs(rightY) > threshold)
Y1 = rightY;
else
Y1 = 0;

if(abs(rightX) > threshold)
X1 = rightX;
else
X1 = 0;

if(abs(leftX) > threshold)
X2 = leftX;
else
X2 = 0;

if(abs(leftY) > threshold)
Y2 = leftY;
else
Y2 = 0;

//Control Commands
motor[frontRight1] = Y1 - X2 - X1;
motor[backRight1] =  Y1 - X2 + X1;
motor[backRight2] =  Y1 - X2 + X1;
motor[frontLeft1] = Y2+ X2 + X1;
motor[backLeft1] =  Y2+ X2 - X1;
motor[backLeft2] =  Y2+ X2 - X1;
delay(time);
}
}
}

void pre_auton()
{
}

{
autonDrive(122, 34, 52, 245, 70);
//autonDrive(int rightX, int rightY, int leftX, int leftY, int time)
}

In your original code did you check the encoder values to make sure its increasing like you expect it to?

I’m sorry but I haven’t stopped laughing for 5 minutes.

NattyMan0007.stopLaughingISR();

#ERROR!! 10429: Instance NattyMan0007.laughingStop hung at runtime.

Think about a function as essentially placing a piece of code into the autonomous section - or having a reference to some code that RobotC essentially treats the same as something you would just write directly into the autonomous section. That means we want to as a general statement, if not only for readability, place our while(true) loops outside of the function and in the task.

With the autonomous code, we generally want to shy away from using infinate loops anyway however and look at how a holonomic drive actually works. Why does the code that Cody posted actually act on the wheels that way and cause your robot to move in that specific way? Using that we can manipulate the movement of the robot in certain ways.

As a first, remove the while(true) loops from your code and place all the appropriate code in a for( timeperiod ) piece. Something along the lines of:

function ( x, y, rot, time ) {
for( int counterVar = 0; counterVar > time; time++ ) {
// Code here for affecting your drive.
delay( unit of time )

ERROR: Segmentation fault (core dumped)

All reactor core safeguards are now non-functional. Please prepare for reactor core meltdown.

<3333 Portal 2