V5 coding help

void usercontrol( void ) {
// User control code here, inside the loop
while (1==1){

FlywheelDown.spin(directionType::fwd,80,velocityUnits::rpm);
FlywheelUp.spin(directionType::fwd,-80,velocityUnits::rpm);
FrontL.spin(vex::directionType::fwd, Controller1.Axis3.value(), vex::velocityUnits::pct);
BackL.spin(vex::directionType::fwd, Controller1.Axis3.value(), vex::velocityUnits::pct);
FrontR.spin(vex::directionType::rev, Controller1.Axis2.value(), vex::velocityUnits::pct);
BackR.spin(vex::directionType::rev, Controller1.Axis2.value(), vex::velocityUnits::pct);

   
if(Controller1.ButtonL1.pressing())  {
    Intake.spin(directionType::fwd,-600,velocityUnits::rpm);
   
}
if(Controller1.ButtonL2.pressing())  {
    Intake.spin(directionType::rev,600,velocityUnits::rpm);
        }
else {
    Intake.stop(brakeType::brake);
}
  
if(Controller1.ButtonR1.pressing())  {
   
    
    FlywheelDown.spin(directionType::fwd,100,velocityUnits::rpm);
    FlywheelUp.spin(directionType::fwd,-100,velocityUnits::rpm);
    
    
    //-100, 100 is max, good for top flag shooting/full court
    
}
if(Controller1.ButtonR2.pressing())  {
   
    
    FlywheelDown.spin(directionType::fwd,70,velocityUnits::rpm);
    FlywheelUp.spin(directionType::fwd,-70,velocityUnits::rpm);
    
    
    //-100, 100 is max, good for top flag shooting/full court
    
}

  
if(Controller1.ButtonR2.pressing())  {
    
}
else {
    ;
}
if(Controller1.ButtonA.pressing()) {
    Scraper.spin(directionType::fwd,100,velocityUnits::rpm);
    
}   
if(Controller1.ButtonB.pressing()) {
    Scraper.spin(directionType::rev,100,velocityUnits::rpm);
    
} 
   
else {
    Scraper.stop(brakeType::brake);
}
vex::task::sleep(20); //Sleep the task for a short amount of time to prevent wasted resources. 

}
}

The intake and scraper will only turn backwards, the other button does nothing even though it is programmed here.

You have the motor spinning at positive speeds and spinning forward, and it spins at negative speeds in reverse in the other instance. You have a double negative.

In your code, I fixed the issue for the intake, but not the scraper. You need to take care of that. I want you to learn how to code, so If I just gave away the full answer I wouldn’t be doing that.

Code

This text will be hidden

FlywheelDown.spin(directionType::fwd,80,velocityUnits::rpm);
FlywheelUp.spin(directionType::fwd,-80,velocityUnits::rpm);
FrontL.spin(vex::directionType::fwd, Controller1.Axis3.value(), vex::velocityUnits::pct);
BackL.spin(vex::directionType::fwd, Controller1.Axis3.value(), vex::velocityUnits::pct);
FrontR.spin(vex::directionType::rev, Controller1.Axis2.value(), vex::velocityUnits::pct);
BackR.spin(vex::directionType::rev, Controller1.Axis2.value(), vex::velocityUnits::pct);

   
if(Controller1.ButtonL1.pressing())  {
    Intake.spin(directionType::rev,600,velocityUnits::rpm);
   
}
if(Controller1.ButtonL2.pressing())  {
    Intake.spin(directionType::rev,-600,velocityUnits::rpm);
        }
else {
    Intake.stop(brakeType::brake);
}
  
if(Controller1.ButtonR1.pressing())  {
   
    
    FlywheelDown.spin(directionType::fwd,100,velocityUnits::rpm);
    FlywheelUp.spin(directionType::fwd,-100,velocityUnits::rpm);
    
    
    //-100, 100 is max, good for top flag shooting/full court
    
}
if(Controller1.ButtonR2.pressing())  {
   
    
    FlywheelDown.spin(directionType::fwd,70,velocityUnits::rpm);
    FlywheelUp.spin(directionType::fwd,-70,velocityUnits::rpm);
    
    
    //-100, 100 is max, good for top flag shooting/full court
    
}

  
if(Controller1.ButtonR2.pressing())  {
    
}
else {
    ;
}
if(Controller1.ButtonA.pressing()) {
    Scraper.spin(directionType::fwd,100,velocityUnits::rpm);
    
}   
if(Controller1.ButtonB.pressing()) {
    Scraper.spin(directionType::rev,100,velocityUnits::rpm);
    
} 
   
else {
    Scraper.stop(brakeType::brake);
}
vex::task::sleep(20);

Thanks for the reply! Our team has found it hard to switch from robot c to c++ programming. We are attempting to make the switch in order to compete with the other v5 robots at worlds.

3 Likes

Did the fix help?

Also, every time through the loop you set ±80 rpm even when you’re pressing a button to set them to ±100 rpm or ±70 rpm. This will cause problems. You should really have a single if-else if-else loop, using the conditions for the if and else if, and putting the default in the else.

sorry for the late response. I fixed this issue but I still cannot spin the intake backwards (I also fixed the flywheel issue)

Make your three statements for the intake into one “block”. Have the buttonL2 be an elseif not an if, and keep the else.

if(Controller1.ButtonL1.pressing()) {
Intake.spin(directionType::fwd,-600,velocityUnits::rpm);
}
else if(Controller1.ButtonL2.pressing()) { Intake.spin(directionType::rev,600,velocityUnits::rpm);
}
else {
Intake.stop(brakeType::brake)
}
That’s the code

Edit: formatting issues, sorry i can’t code format on an iPad.

1 Like

for some reason, it still is not working

Is the intake spinning at all? Like can you only go one way or does it just not spin?

Edit: Going reverse at 600 is the same as going forward -600. Do reverse -600 to get a reverse speed from forward 600

1 Like

That’s what I told him earlier

Your fix helped! Thank you!