Help with coding a lady brown using c++

Having a very hard time coding our lady brown. Does anyone know how to help? We are using C++

Hello Ohioan

Simply set up buttons for it in a while(true) loop in your driver control.

like if(Controller.Button.pressing(){
Motor.spin(forward)
}
and then one to spin it in reverse.

You could also make it spin to a certain rotation to make it better.

PS: Heard about you guys, I’m from the same school as 6390F

1 Like

What coding language, software, etc?
8pxl had a good video on youtube, and those concepts should apply for all programming languages.

We use C++ on VS code

It’s a bit different depending on a few things:

  1. Do you have a rotation sensor? I’ll assume yes, but you can do the same thing with the IME readings.
  2. Do you want to toggle between states (down, loading, scoring) or do you want to manually control everything? It’s probably better to do state-based, so that’s what I’ll show.

Given that there’s already a great tutorial for PROS (https://www.youtube.com/watch?v=THGxIVEevKI) I don’t see any harm in providing code for this in Vex C++ as well. Exact same code/concepts as the video, just translating the programming language.

First, you’ll need to have your rotation sensor and lady brown motor (or motor group) defined, I’m assuming you know how to do that.

First, we’ll define variables that keep track of the current arm state, as well as what position the arm is supposed to be at for each state.

const int numStates = 3;
int states[numStates] = {0, 30, 180}; //Create array of target degree values
int currState = 0;
int target = 0;

Then, we can write a function that will set the arm to the next state:

void nextState() {
  //Cycle to next state
  ++currState;
  if (currState == numStates) currState = 0;
  target = states[currState]; //Update target arm position
}

We also need a function that moves the arm to the target position. We’ll just use a standard proportional controller.

void liftControl() {
  double kp = 0.2; //tune this to your robot
  double error = target - rotationSensor.position(degrees);
  //If you don't have a rotation sensor, replace rotationSensor.position(degrees) with LB.position(degrees)
  LB.spin(forward, error*kp, volt);
}

Finally, we need to set everything up so that when we press R1, the state is toggled and the arm goes to the correct position. To do this, we’ll start two tasks inside the main function:

  //Runs the liftControl function every 10ms
  thread liftControlThread = thread([]{
    while (1) {
      liftControl();
      task::sleep(10);
    }
  });
  
  //Toggles states using R1
  controller(primary).ButtonR1.pressed(nextState);

The last step is to tune the kp value. If the arm is moving too slowly/not moving enough, kp is too low. If it is very fast and is shaking around the target, kp is too high.

If something isn’t working let me know, I’ll try to help further.