Motors Won't Run When Another Is Running

Hello! We have a problem in our code. When running one motor set, such as the Arms, the other motor system (4-bar) won’t move. On the flip side, if we attempt to move the arms while the lift is active, the arms will not stop moving until the lift is deactivated. I’ve never attached code before, so I hope I’m doing this right.

// "when driver control" hat block
int ondriver_drivercontrol_0() {
    int i;
  while (true) {
    if (Controller1.ButtonL1.pressing()) {
      arms.setVelocity(200.0, percent);
      arms.spin(forward);
    } 
    else if (Controller1.ButtonL2.pressing()) {
      arms.setVelocity(200.0, percent);
      arms.spin(reverse);
    } 
    else if (Controller1.ButtonR1.pressing()) {
       arms.stop();
      FourBarLift.setVelocity(75.0, percent);
      FourBarLift.spin(reverse);
    } 
    else if (Controller1.ButtonR2.pressing()) {
       arms.stop();
      FourBarLift.setVelocity(75.0, percent);
      FourBarLift.spin(forward);
    } 
    else if (Controller1.ButtonDown.pressing()) {
        i = 1;
        arms.stop();
        FourBarLift.stop();
      Clamp.setVelocity(80.0, percent);
      Clamp.spin(forward);
    } 
    else if (Controller1.ButtonUp.pressing()) {
        i=0;
       arms.stop();
        FourBarLift.stop();
      Clamp.setVelocity(80.0, percent);
      Clamp.spin(reverse);
    } 
    else{
      arms.stop();
      FourBarLift.stop();
      if(i == 0){
      Clamp.stop();
      }
    }
    wait(1, msec);
  }
  return 0;
}

I’m sorry for the wall of text…

edit: code tags added by moderators

1 Like

Please, at least try to format your code so that others can read without much difficulty.

Here is how to.

Please copy and paste your code and enclosure with “```”.

I didn’t know how to do that. Do you mean like this

I’d like to personally thank the moderators for formatting it right because I am not used to it thank you so much @jpearman

2 Likes

Three things.

  1. Mods rock, thanks for fixing the post
  2. @Saffron - Highlight the entire post, you’ll see the QUOTE button, click that. Then look in the box it will show you how they got the code to work by putting three back quotes in front and after your code.
  3. In your code when you have the arms move you tell the lift to stop, likewise when you have the lift move you tell the arms to stop. What do you want it actually do? Should the lift continue until it gets to some point? If so, you will need to tell it when to stop. Or are you pressing two buttons at the same time and the stops are fighting each other?
6 Likes

You seem to be mixing your motor sets (arm, FourBarLift, Clamp) in interesting combinations. I am not sure if that is planned. Based on your cascading list of if statements only one motor / direction can run at a time.

Normally you would want each subsystem in its own if else code block. See below as an example.

//Arm control
 if (Controller1.ButtonL1.pressing()) {
      arms.spin(forward, 100, percent);
    } 
    else if (Controller1.ButtonL2.pressing()) {
      arms.spin(reverse, 100, percent);
    } 
    else {
       arms.stop();
    }

//FourBarLift control
if (Controller1.ButtonR1.pressing()) {
      FourBarLift.spin(reverse, 75.0, percent);
    } 
    else if (Controller1.ButtonR2.pressing()) {
      FourBarLift.spin(forward, 75.0, percent);
    } 
    else {
      FourBarLift.stop();
    }
8 Likes

It is now a much better format. I think @Hudsonville_Robotics and @Foster already answer your question. In general, you want to break a complicated task into many small simple tasks. Moving arm and moving life are two independent tasks, there is no need to mix them together unless you are trying macro to combine several steps together.

1 Like

Thank you very much for the explanation! Our programmer is out with covid right now, so I appreciate you making this easy for me to understand.

1 Like

Thank you so much for the format help! As for the robot, I think it’s the last scenario in which the stops are fighting each other–this may be due to the fact that I originally made this code in block form before surrendering it to a far more savvy teammate, who converted it to C++. I’ll test the solution proposed by @Hudsonville_Robotics tomorrow, and hopefully I won’t have any problems.