Help with spinToPosition/rotateto command

A couple of my teams are wanting to set up their remote to push a button and take their lift to a specific height during driver control. Over break I have been experimenting with the spinToPosition and rotateTo Commands to show them an example and neither one is working the way I want it to. Below is the code for a Clawbot. I am wanting it to lower the arm to the desired height, open the claw, and back away from the cube. The issue we are having is that the arm will never lower to the position that I am asking it to go to. It acts as though it is skipping the rotateTo or spinToPosition command. Any help would be appreciated

using namespace vex;
void openclaw()
{
  ClawMotor.setStopping(brake);
  ClawMotor.spinToPosition(0,degrees);
  ClawMotor.setTimeout(1,sec);
}
void closeclaw()
{
  ClawMotor.setStopping(hold);
  ClawMotor.spinToPosition(70,degrees);
  ClawMotor.setTimeout(1,sec);
}
void firstblock()
{
  ArmMotor.rotateTo(0,degrees,true);
  ArmMotor.setTimeout(2,sec);
  openclaw();
 // Drivetrain.setDriveVelocity(60,  percent);
  //Drivetrain.driveFor(reverse,6,inches);
}
void secondblock()
{
  ArmMotor.spinToPosition(30,degrees);
  ArmMotor.setTimeout(1,sec);
  openclaw();
  Drivetrain.driveFor(reverse,6,inches);
}
void thirdblock()
{
  ArmMotor.spinToPosition(60,degrees);
  ArmMotor.setTimeout(1,sec);
  openclaw();
  
  Drivetrain.driveFor(reverse,6,inches);
}
int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();
//  int  state = 0;

  ClawMotor.setStopping(hold);
  ClawMotor.setPosition(0,degrees);
  ArmMotor.setVelocity(40, percent);
  ClawMotor.setVelocity(30, percent); 
  ArmMotor.setStopping(hold);
 ArmMotor.spinToPosition(110,degrees,true);
 ArmMotor.setPosition(0,degrees);
 while(1)
{
if(Controller1.ButtonL2.pressing()&&ArmMotor.position(degrees)>0)
  {ArmMotor.spin(reverse,40,percent);}
  else if (Controller1.ButtonL1.pressing()) {
  ArmMotor.spin(forward,40,percent);
  }
  else {
  ArmMotor.spin(forward,0,percent);
  }
Controller1.ButtonDown.pressed(firstblock);
Controller1.ButtonLeft.pressed(secondblock);
Controller1.ButtonUp.pressed(thirdblock);

}
}Preformatted text
1 Like

event registration should only be done once, move these outside of the while loop.

while the spinToPosition or spinTo commands are running, make sure that you don’t send any additional motor commands such as spin, the motor can only be doing one thing at a time.

4 Likes

What does the true command in this code mean?-ArmMotor.spinToPosition(110,degrees,true);

The last argument tells it to wait until it reaches target position before the function returns.

bool vex::motor::rotateTo(double rotation, rotationUnits units, bool waitForCompletion=true);

See the API: VEX Help

1 Like

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