V5 programming - what am I doing wrong?

Hi all - was hoping someone could help w/an ongoing V5 issue

Normally we wait until we assemble & program the robot to determine which motors are reversed, and do so in the motor set-up.

However, to make autonomous (& other stuff) easier we created functions(values)

However, when we call the function the motors do not go as we expect, but rather one is our of phase. i.e. to go fwd it ends up turning.

Below is a sample call and the function
rDrive(30,30,30,30,0); //should go straight but goes right

void rDrive(double lDeg, double rDeg, int l, int r, bool b){ // drive by relative distance
L_Drive.rotateFor(lDeg, vex::rotationUnits::deg,l, vex::velocityUnits::pct, false);
R_Drive.rotateFor(rDeg, vex::rotationUnits::deg,r, vex::velocityUnits::pct, b);
}//end rDrive

When declaring the motors you can put a true in the arguments list to reverse the motor…

vex::motor L_Drive(vex::PORT2, true); //this motor is reversed
vex::motor R_Drive(vex::PORT2, false); //this motor is not reversed

This way the when you call anything to do with motor, like .rotateFor() will be reversed.

Does thin mean you did reverse the motors? If what I said isn’t the problem can you further elaborate on the issue.


Want to make you code look good on vexforum?

Inline code is done using single back quotes: `some code`


This…

myClass someCode(); //comment
someCode.run();

is done by using three back quotes. They have to be on a line all by themselves…
```
myClass someCode(); //comment
someCode.run();
```

This sometimes doesn’t correctly highlight your code so you can specify the type of language by writing it after the first three back quotes…
```cpp
myClass someCode(); //comment
someCode.run();
```

4 Likes

LOL - you answered my ā€˜legible code’ question already - thanks!

Yes, the motor set-up is reversed such that they move the correct direction via arcade control (both are reversed)

But when we call the function() one goes the wrong way. I guess rather than trying to figure it out I can maybe correct the direction in the function:

          rDrive(30,-30,30,30,0);  //notice the -30 to go fwd

void rDrive(double lDeg, double rDeg, int l, int r, bool b){  // drive by relative distance
  rDeg = rDeg * -1;
  L_Drive.rotateFor(lDeg, vex::rotationUnits::deg, l , vex::velocityUnits::pct, false); 
  R_Drive.rotateFor(rDeg, vex::rotationUnits::deg, r , vex::velocityUnits::pct, b); 
}//end rDrive

2 posts were split to a new topic: Robot Mesh Studio Programming Issue

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.