How to use sample Limelight code in java Command Based File

I am the new lead programmer for team 1662. I learned to program in java in a command based format. I am trying to convert the Limelight Deep Space 2019 Example code into command based format. How would I go about doing this?

Thank You!

1 Like

For future reference, it’s generally advisable to link to code when referencing it so that we know we’re looking at the same thing. I’ll assume you’re referring to this: http://docs.limelightvision.io/en/latest/cs_drive_to_goal_2019.html

The only part of that code that’s limelight-specific is the Update_Limelight_Tracking method. You can make similar calls wherever you need. I would recommend either Robot::robotPeriodic(), or the periodic method of a subsystem (e.g. drive or a “vision” subsystem). Really, it’s up to you. The key is that you use NetworkTables to obtain the values you need.

Simplest way in my opinion:

Create a Vision subsystem for managing all your limelight updates. In the Vision subsystem periodic method update all your variables in the same way the limeilight example code does.

Create a command that requires your Drivetrain and Vision subsystems.

Bind that command to a button.whileHeld() method.

In the execute() method of the command do all the driving logic getting the limelight values, adding or subtracting proportional control constants, and then finally drive the robot.

Our students will be doing this as one of their tasks tonight, so if you are still stuck by around 8 pm EST our github will have a command based example that hopefully is working. Check it out for future reference if needed.

2 Likes

Any update on how this is coming I am struggling to understand how to do this and some example code would be nice.

They have a starting point. I will try and get them to push to github tomorrow. I’ll send you a message when they do so you can see.

1 Like

If you want an example, take a look at our code. It is mostly taken from the example code. We added some features like angle correction with a gyro (which we run in our command after the robot reaches the target), but the rest is the same.

1 Like

Here’s an example from our team. Our Limelight subsystem doesn’t update on every execute(), it subscribes to updates to the Limelight network table. The thinking was that our update code only needs to run if the Limelight has new values. In practice, it probably doesn’t make much of a difference.

Here’s the subsystem that interacts with the limelight network table: LimeLight
Here’s a command that uses it to drive to a target: CombinedTarget
Finally, the command is bound to a button in RobotContainer using a button binding

new JoystickButton(driverController, XboxController.Button.kY.value)
        .whenHeld(new CombinedTarget(driveTrainSubsystem, limelight));
1 Like

The updated command has been pushed to github for your review. The relevant files are the Vision subsystem and the command that aligns with vision bound to the controller “A” button.

1 Like

EagleForce has invited iNicole to stop by our shop today, we are about 15 miles north of 1662. Fortunately she was going to be in our neighborhood anyway, so it works well for us all.
Hopefully all the help and direction posted here plus our hands on support will get RaptorForce headed in the right direction.

1 Like