Command based programming not calling initialize

Hello, we are having problems with command based programming. In our code, we are calling the shooting command from robot.java using a lambda, however it never reaches the initialize function within the command.



It prints the first string, and passes the requirements, but never prints initialized or calls the shooter functions from the turret subsystem. Any suggestions?

The lambda-accepting bindings wrap the lambda in an InstantCommand and run that on trigger activation.

So, your code is simply running an InstantCommand that instantiates a ShootingCommand and then exits.

4 Likes

You shouldn’t need a lambda for what you’re trying to do. The lambda expression as written essentially runs a command that creates an instance of “ShootingCommand” and then exits. If your goal is to directly run “ShootingCommand” you would want to write:

btn.whenPressed(new ShootingCommand(turret_subsystem, oi.l1(),0.8));

If the reason you are doing this is because you only want oi.l1() to be evaluated when the command actually runs, you could consider passing it in as ‘oi::l1’ instead which will pass the method into the constructor instead of the value that method takes. This is called a method reference. You can then call that method during initialize:

btn.whenPressed(new ShootingCommand(turret_subsystem, oi::l1,0.8));

Another option if method references are too daunting is to just pass oi into the command and call oi.l1() in initialize.

2 Likes

Thanks for the suggestion, and it works great! But now other things aren’t working~
Now the command unexpectedly ends itself once it reaches the shooting part;
image

i think you are calling intake_subsystem but you haven’t passed that to ShootingCommand when you initialized it.

can you post the line numbers

Where is intake_subsystem in your command being initialized/passed to the Command. I only see you passing turret_subsystem to your command from your RobotContainer.

Also, in the future, it generally helps make things easier if you upload your entire code project to Github.

Thanks for the suggestion gixxy, but github just reallllllllly hates me for some reason, not allowing me to push or pull from remotes due to a authentication bug.
image

Do you have 2-factor authentication setup on your account? If so, you need to use a “personal access token” instead of your password. https://help.github.com/en/github/authenticating-to-github/accessing-github-using-two-factor-authentication

1 Like

Beat me to that one. Was a huge pain for me because the school 3468 is at blocks all external ssh

I’m behind a corporate network proxy… I know your pain. Github is virtually unusable here

Anyways, now the command doesn’t seem to stop; here’s the finish code
image

Can you maybe push your code to another git service (gitlab, bitbucket, etc)? This would be infinitely easier if we could actually see your code

Wrote this to easy my Github ssh/https troubles. https://gist.github.com/gurustave/e7a1df709c2a4258440719c7c27216d4

Hey Fletch, I tried out gitbucket, here’s the repo for our code;
https://bitbucket.org/A0wn/spoon-test-commands/src/master/

I… have a lot of comments. Unfortunately, they all boil down to “please read the docs”.

I should’ve noticed this much earlier. Sorry about that.

First and foremost, these should be in RobotContainer. In fact, you really shouldn’t have to touch Robot.java much at all with the “new” command-based framework.

To go beyond that, I’ll need to know what your current problem is.

Alrighty, so the shooting command doesn’t seem to stop, either due to the timer giving weird values or the buttonpress not returning that the button has stopped being pressed.

Assuming you’re referring to this command: https://bitbucket.org/A0wn/spoon-test-commands/src/937d453bd5765a2f998d463c43dc9942521c4915/src/main/java/frc/robot/Robot.java#lines-126

buttonPressed will ALWAYS be true right now (https://bitbucket.org/A0wn/spoon-test-commands/src/937d453bd5765a2f998d463c43dc9942521c4915/src/main/java/frc/robot/commands/ShootingCommand.java#lines-82), but that doesn’t explain why the timer isn’t ending. I’m sure there’s a logic failure somewhere, but I’m not seeing it at quick glance. I’ll have to take a deeper dive into this unless someone else beats me to it.

Again, I do recommend reading through the command-based docs and considering starting a new project then copying your logic into that format. If nothing else, it’ll be MUCH easier for other teams or CSAs to help you with any issues you might experience at your event(s).

1 Like

Hey Fletch, thanks alot for your help! The timer happened to magically work again after all of that…