Program Issue

Most likely what you’ll want is some way to indicate within usercontrol whether buttonTilt is currently executing. If it is executing, it shouldn’t call Tilt.stop(). One possible solution would be to use a global variable for this purpose.


pressed is an event, i.e… something happens.
buttonTilt is your “event handler” it does the work when the event happens


Ohhhh, So tilt stop is in the if else if statements and when that up button is pressed, it is also programmed to stop the motors until left or right are pressing?

, can i just do the pressed Up statement as my Else on the driver control so it shows no stop? Or do i need a stop so the tilters dont make it move?

And how will a global varible work.

ok that makes sense now.

Here is something to try to get your code working without too much changes. If this doesn’t work you can put all your tilt code into a single task. tiltPID can still be a function but called from that task (sleep() usage would probably need to change).

Anyway here is something to try.
You usually want user control to override the automated control. So for that inside the while of the callback you want to add a return if either user tilt button is pressed.

// if user wants control, immediately return from tiltPID 
if (Controller1.ButtonRight.pressing() || Controller1.ButtonLeft.pressing()){

then you need to make sure that opcontrol is not always stopping the tilt motors when not pressing a button as this code does.

else { 

so you only want to call stop(hold) only one time after releasing the tilt buttons

 int tiltActive = 1; // control when stop is called. 1 = initialize tilt motors to stop(hold)

 while (true) { 
  // your other code

    if(Controller1.ButtonRight.pressing())   {
     Tilt.spin(directionType::fwd, TiltSpeedPCT, velocityUnits::pct);
     Tilt2.spin(directionType::fwd, TiltSpeedPCT, velocityUnits::pct);
    else if(Controller1.ButtonLeft.pressing()) {
      tiltActive = 1;
      Tilt.spin(directionType::rev, TiltSpeedPCT, velocityUnits::pct);
      Tilt2.spin(directionType::rev, TiltSpeedPCT, velocityUnits::pct);
    else if (tiltActive) {  // this else gets called once after the operator releases the above button(s)
      tiltActive=0; // when tilt is not active, don't keep telling the motor to stop

Ok awesome. Thank you very much.

And just a quick question, Can i stack any height of cubes?

My builder wants to know if I can use that PID loop to stack any height of cubes like a 9 or 10 stack without changing anything?

Sorry about all these questions.

I have limited PID experience so hopefully others can help you more with that. However, I would start with ki and kd set to 0 and get kp tuned first. Then tune kd. If that works I’d leave ki at 0.

Since tuning can be time consuming it might be a good idea to have buttons to increment and decrement the constant value so you don’t have to recompile each test. I’d also display that value to the controller.

Note, you may need different values for the constants for different heights of cubes.

Good Luck.

ed. I just look over your i-term and you cannot modify that on the fly since you are saving the error and not ki*error. So if you change ki it will apply to all prior errors which can cause a bump in the output. But like i said you probably can/should leave ki=0.


Ok. I will just use this for our 9 stack since that is a good stack for a normal match and just manually stack for the 11 or below. Thanks

When we press Up. the tilter barely moves but then no other button moves.

When we press Left or right,it goes but wont stop

Nevermind. We figured it out. thank you all

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