Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   PID & One Second Delay Between Auto and TeleOp (http://www.chiefdelphi.com/forums/showthread.php?t=136187)

WillNess 29-03-2015 14:09

PID & One Second Delay Between Auto and TeleOp
 
This year we have a giant arm that sticks behind our robot, with two joints. At the end of an arm is a claw. One of our autonomous modes is that the both parts will drop down, our robot will drive backwards, our claw will close on the bin on the center step, and the arm will then fold up and set the bin so that it is resting on our robot while still grabbing the bin. The problem is, during the one second between autonomous and teleop, our PID is disabled so the arm droops a little and some of the time we drop that bin. I've temporarily fixed the problem by storing the bin in a different position where if the PID disables none of the parts of the arm will droop, but it is vital for our drivers to start in the docked position.
So:
- Is it possible to operate the PID during this 1 second delay?
- Is this delay considered "disabledPeriodic"
- Are there any other fixes?

GeeTwo 29-03-2015 14:14

Re: PID & One Second Delay Between Auto and TeleOp
 
Something to try:

After the arm has reached the proper position and stabilized, get the voltage setting for the motor, set that voltage and disable the PID (or perhaps swap the order). This setting seems more likely to survive the transition from auto to teleop.

MrRoboSteve 29-03-2015 14:31

Re: PID & One Second Delay Between Auto and TeleOp
 
I believe the robot is in the disabled state during the period between autonomous and teleop, so no commanding will be sent to the motor controllers. Someone with a roboRIO at hand could validate that.

Without seeing your mechanism, it's hard to picture what would work. Bungees or constant force springs are often used in similar scenarios when you need a balancing force.

WillNess 29-03-2015 14:32

Re: PID & One Second Delay Between Auto and TeleOp
 
GeeTwo:

I tried creating two variables and setting it to the .getAverageVoltage() for each potentiometer on the arm during Auto Periodic and then in TeleOpInit I would set the setPoint for each part of the arm to their respective variable but I didn't seem to get the arm to jump back up to its previous position, and sometimes the first part of the arm had drooped too much and the bin had already fell.

GeeTwo 29-03-2015 14:42

Re: PID & One Second Delay Between Auto and TeleOp
 
Quote:

Originally Posted by WillNess (Post 1463347)
GeeTwo:

I tried creating two variables and setting it to the .getAverageVoltage() for each potentiometer on the arm during Auto Periodic and then in TeleOpInit I would set the setPoint for each part of the arm to their respective variable but I didn't seem to get the arm to jump back up to its previous position, and sometimes the first part of the arm had drooped too much and the bin had already fell.

I was referring to the voltage applied to the motor (throttle, PID output value to actuator), not the voltage returned from the potentiometer (PID input value from sensor).

WillNess 29-03-2015 14:42

Re: PID & One Second Delay Between Auto and TeleOp
 

Above is the image of what we call our "Stinger"
It has two parts:
The shoulder and the elbow.
The shoulder is the bottom part and the elbow is the part that is turned, think of it as an actual human arm where the joint is where the elbow starts.
This is our old docked position, now our shoulder is a little farther up so it's not at 0 degrees.

GeeTwo 29-03-2015 14:46

Re: PID & One Second Delay Between Auto and TeleOp
 
Also, are you using the same motor controller object between auto and tele? Declaring a new motor controller at the beginning of teleop would presumably reset the throttle to zero.

WillNess 29-03-2015 14:50

Re: PID & One Second Delay Between Auto and TeleOp
 
Quote:

Originally Posted by GeeTwo (Post 1463354)
Also, are you using the same motor controller object between auto and tele? Declaring a new motor controller at the beginning of teleop would presumably reset the throttle to zero.


Yes. The only time we declare motor controllers is in robotInit.

GeeTwo 29-03-2015 14:54

Re: PID & One Second Delay Between Auto and TeleOp
 
Glad to see the picture - not what I hand in mind (I was thinking of an overhead arm). Putting the arm vertical or nearly vertical leaning against the tall frame would presumably handle the temporary "storing the bin in a different position where if the PID disables none of the parts of the arm will droop".

Would it help if you used your temporary solution, then at the beginning of teleop, the robot automatically moved the arm to the "docked" position, without waiting on driver input?

WillNess 29-03-2015 15:27

Re: PID & One Second Delay Between Auto and TeleOp
 
Quote:

Originally Posted by GeeTwo (Post 1463359)
Glad to see the picture - not what I hand in mind (I was thinking of an overhead arm). Putting the arm vertical or nearly vertical leaning against the tall frame would presumably handle the temporary "storing the bin in a different position where if the PID disables none of the parts of the arm will droop".

Would it help if you used your temporary solution, then at the beginning of teleop, the robot automatically moved the arm to the "docked" position, without waiting on driver input?

That sounds like a good idea.
What I'm doing temporarily is bringing the shoulder back down to 0 degrees, and then making the elbow go to 90 degrees, in which nothing falls.
I guess at teleop init I could set both of the positions to go to docked position.
Which raises another question:
- Is there any way to do something only if the robot is in practice mode or playing an actual match?

MrRoboSteve 29-03-2015 15:45

Re: PID & One Second Delay Between Auto and TeleOp
 
DriverStation::IsFMSAttached() helps you with part of your question.

Ben Wolsieffer 29-03-2015 15:48

Re: PID & One Second Delay Between Auto and TeleOp
 
Quote:

Originally Posted by WillNess (Post 1463375)
- Is there any way to do something only if the robot is in practice mode or playing an actual match?

You could use:
Code:

DriverStation.getInstance().isFMSAttached()
to detect whether the robot is connected to the field, but I don't think this works for practice mode.

WillNess 30-03-2015 02:55

Re: PID & One Second Delay Between Auto and TeleOp
 
Do you guys think this would work?
Code:

robotInit(){
  boolean = false;
}
autonomousPeriodic(){
  boolean = true;
}
teleopInit(){
  if(boolean == true){
      shoulder.set(shoulderDocked);
      elbow.set(elbowDocked);
  }
  boolean = false;
}

The thing is I'd need to reset the roboRio if I wanted to ever test autonomous and teleop NOT in practice mode.

WillNess 30-03-2015 03:04

Re: PID & One Second Delay Between Auto and TeleOp
 
Or I could add
Code:

disabledInit(){
  Timer.start();
}
teleopInit(){
  if(Timer.getFPGATimestamp > 1.000){
      Timer.stop();
      Timer.reset();
  }else{
      shoulder.set(shoulderDocked);
      elbow.set(elbowDocked);
      Timer.stop();
      Timer.reset();
  }
 
}

Questions: Do I need the .stop() and .reset() or just one? does the .reset() start the timer again?

MrRoboSteve 30-03-2015 07:51

Re: PID & One Second Delay Between Auto and TeleOp
 
Remember you also have DisabledInit and DisabledPeriodic available.

GeeTwo 30-03-2015 09:51

Re: PID & One Second Delay Between Auto and TeleOp
 
Quote:

Originally Posted by WillNess (Post 1463599)
Questions: Do I need the .stop() and .reset() or just one? does the .reset() start the timer again?

The documentation isn't clear. Going back to the source code, it appears that the timer carries the "accumulated time" from a stop to a start, so if you want to zero the result of later get()s, you must do a reset(). (I'm presuming that the C++ and Java versions behave equivalently.)

WillNess 30-03-2015 12:09

Re: PID & One Second Delay Between Auto and TeleOp
 
Quote:

Originally Posted by GeeTwo (Post 1463632)
The documentation isn't clear. Going back to the source code, it appears that the timer carries the "accumulated time" from a stop to a start, so if you want to zero the result of later get()s, you must do a reset(). (I'm presuming that the C++ and Java versions behave equivalently.)

Ok so if we implement something equivalent to this code, right before I start it I will do a timer.reset();

MrRoboSteve 30-03-2015 12:24

Re: PID & One Second Delay Between Auto and TeleOp
 
I think this is closer to what you want. The logic is simpler if you move the timer check into disabledPeriodic(). The result of timer.getFPGATimestamp() is probably not what you want.

Code:


bool teleopAfterAutonomous = false;

autonomousInit() {
  teleopAfterAutonomous = true;
}

disabledInit(){
  disabledTimer.Reset();
  disabledTimer.Start();
}

disabledPeriodic(){
  if (disabledTimer.Get() > 1) {
    // If we're disabled for more than one second, assume that we are not in a match
    // Might be necessary to bump 1 above to a somewhat higher value.   
    teleopAfterAutonomous = false;
  }
}

teleopInit(){
  if(teleopAfterAutonomous || DriverStation.getInstance().isFMSAttached()){
      shoulder.set(shoulderDocked);
      elbow.set(elbowDocked);
  }
}


WillNess 30-03-2015 13:25

Re: PID & One Second Delay Between Auto and TeleOp
 
Thank you, I think this should work!

Quote:

Originally Posted by MrRoboSteve (Post 1463723)
I think this is closer to what you want. The logic is simpler if you move the timer check into disabledPeriodic(). The result of timer.getFPGATimestamp() is probably not what you want.

Code:


bool teleopAfterAutonomous = false;

autonomousInit() {
  teleopAfterAutonomous = true;
}

disabledInit(){
  disabledTimer.Reset();
  disabledTimer.Start();
}

disabledPeriodic(){
  if (disabledTimer.Get() > 1) {
    // If we're disabled for more than one second, assume that we are not in a match
    // Might be necessary to bump 1 above to a somewhat higher value.   
    teleopAfterAutonomous = false;
  }
}

teleopInit(){
  if(teleopAfterAutonomous || DriverStation.getInstance().isFMSAttached()){
      shoulder.set(shoulderDocked);
      elbow.set(elbowDocked);
  }
}



WillNess 30-03-2015 13:30

Re: PID & One Second Delay Between Auto and TeleOp
 
Quote:

Originally Posted by MrRoboSteve (Post 1463723)
I think this is closer to what you want. The logic is simpler if you move the timer check into disabledPeriodic(). The result of timer.getFPGATimestamp() is probably not what you want.

Code:


bool teleopAfterAutonomous = false;

autonomousInit() {
  teleopAfterAutonomous = true;
}

disabledInit(){
  disabledTimer.Reset();
  disabledTimer.Start();
}

disabledPeriodic(){
  if (disabledTimer.Get() > 1) {
    // If we're disabled for more than one second, assume that we are not in a match
    // Might be necessary to bump 1 above to a somewhat higher value.   
    teleopAfterAutonomous = false;
  }
}

teleopInit(){
  if(teleopAfterAutonomous || DriverStation.getInstance().isFMSAttached()){
      shoulder.set(shoulderDocked);
      elbow.set(elbowDocked);
  }
}


Except during teleopInit() I think I'd have to set the teleopAfterAutonomous = false. Because if I do the practice mode and then I start teleop the teleopAfterAutonomous would be true and then would go to the docked positions so it would look like this: (Correct me if I'm wrong)
Code:

teleopInit(){
  if(teleopAfterAutonomous || DriverStation.getInstance().isFMSAttached()){
      shoulder.set(shoulderDocked);
      elbow.set(elbowDocked);
      teleopAfterAutonomous = false;
  }
}


GeeTwo 30-03-2015 16:22

Re: PID & One Second Delay Between Auto and TeleOp
 
Quote:

Originally Posted by WillNess (Post 1463767)
Except during teleopInit() I think I'd have to set the teleopAfterAutonomous = false. Because if I do the practice mode and then I start teleop the teleopAfterAutonomous would be true and then would go to the docked positions so it would look like this: (Correct me if I'm wrong)
Code:

teleopInit(){
  if(teleopAfterAutonomous || DriverStation.getInstance().isFMSAttached()){
      shoulder.set(shoulderDocked);
      elbow.set(elbowDocked);
      teleopAfterAutonomous = false;
  }
}


Only if there's somewhere later in the code (e.g. in teleopPeriodic()) that uses teleopAfterAutonomous. As for what I see here, the variable is not going to be referenced again. That also means that it won't hurt anything...

MrRoboSteve 30-03-2015 17:00

Re: PID & One Second Delay Between Auto and TeleOp
 
WillNess, I think your change is a good one.

In my code, I assumed that you'd have at least a second of disabled between your practice runs. That delay causes teleopAfterAutonomous to become false. Your change resets things immediately.

WillNess 30-03-2015 21:07

Re: PID & One Second Delay Between Auto and TeleOp
 
Yes I don't think I'll ever be starting the robot within 1 second of code uploading or rebooting.


All times are GMT -5. The time now is 12:32.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi