2 NOOB CommandFramework Questions

This years’ game has our team attempting to step up our programming a bit. As such, I envision we will want to officially make the switch to the Command Framework. I have been learning it for a while, and have a solid understanding of most aspects (much of which is due to this community, thank you).

I want to fully understand it before working with the team to create our routines. I am sort of diving into the deep end and am using the 0-Autonomous tutorial

to help me combine simulator examples (ramsete, and State Space elevator, and eventually, the arm).

I am actually doing well in general. It works almost as expected. However, there are still two issues I am finding, and I suspect they are related.

  1. In auto, unless I create a parallel command group, I starve the motor safety for the drivetrain. Is this expected, or am I doing something wrong?

  2. After I run my ElevatorPIDCMD, I am unable to use the elevator to run (it never ends) unless I set

  public boolean isFinished() {
    return true;

However, if I do that, it runs so quickly, that I do not actually see it happen.

So the in-game experiment of course is to
run the command,
.and then drop off the cargo, t
.and then end the command to lower the elevator.

Then, be able to use the stick in the teleop. The stick code works, but only if I do not ever (in auto or teleop) run the command to raise the elevator.

How do I accomplish this?

Here is my code.

I have been creating constants inline rather than taking advantage of the constants file for ease of setup. I will fix it later, and totally understand that this is a bad habit which will be vanquished.

1 Like

For your elevator example. You need to specify when the command needs to end in isfinished.

If it’s meant to stop when a limit switch is hit you need to return the value of the limit switch or for another sensor you’ll need to check the state of the sensor and return whether it is close enough to your desired state.

In your case it seems to be an encoder so you’ll want to check if the encoder is near the distance you want to go. Something like

“return math.abs(elevatordistance - setpoint) < 1”
Its advisable to leave some room for error by doing this instead of checking for equality because the sensor will gain some error every time the elevator goes up or down.

If it’s meant to be bound to a controller you can use “buttonname.whilepressed()” in robot container and leave is finished returning false.


So, Even after using the fix @Cameron_Williams suggested (which I also needed; thank you), it did not work. Oddly enough however, when I added a different button with a setpoint of 0, it worked. So then I started thinking about PID issues and realized that in the simulator (or in real life), I would not see small oscillations (or maybe it never reached the setpoint at all).

That was the issue. I had to add some printed lines to figure out where the issue was, but somehow in the oscillation, the command kept interrupting itself. This locked up motor safety in auto as well. When I wrapped the return true v return false in a conditional statement that allowed for tolerance (and then actually used the set tolerance method), the command worked as expected.

I also pushed the code with the fix to Git in case anyone comes looking.

1 Like

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