How to track using a limelight and a turret?

This is our first time using java and the limelight. We are having trouble figuring out how to set up and code the turret to use the limelight input.

What have you programmed so far? What do you need help with specifically?

Are you trying to track the target while you are driving around?

1 Like

We used the tx (horizontal degree offset) value that the limelight computes as the error in a PID loop that controls turret last year.

Hope that helps!

2 Likes

We have programmed nothing with respect to the limelight - we are trying to digest the getting started samples to help us out, but we are at a loss of what to actually do. We want the limelight to be our targeting system for our turret to score in the upper hub. We have everything else coded for our robot - it can drive, pneumatic s work, intake and shooting mechanisms work, etc. The only thing left to do is to get the turret to spin to target the scoring hub. This is new to us and we are trying to figure it out.

1 Like

there are many fancy algorithms and stuff that can be done here … but i would recommend starting with a simple thing - standard PID

  1. make sure you set proper soft limits to the controller (so you don’t damage the cable). if you have limit switch of any kind (hall effect/ optical) it is even better, but setting right soft limits will be enough
  2. see at what % power the turret starts moving - set that as the “nominal” value for the Talon (fwd and reverse)
  3. set voltage compensation to 10v
  4. set peak fwd, reverse to 0.3, -0.3 (just temporarily to test things slowly before going full power)
  5. use the limelight Tx value as the error for a turret PID control : power = KpTx + Kd(Tx-prevTx)/cycle_time
  6. tune Kp, Kd=0 until it roughly works … right directions, no surprises (the motor direction may need to be inverted - depending on installation / gears)
  7. peak fwd, rev to 1,-1
  8. tune Kp, Kd … and enjoy :slight_smile:
2 Likes

First I recommend thoroughly reading the limelight documentation. This will probably answer nearly all your questions.

The basic idea of aiming with the limelight is this: you know the angle you’re turret is at (using an encoder, I recommend converting encoder counts to degrees), and the limelight gives you an x offset in degrees. You can set the position of your turret’s angle to it’s current position +/- the limelight x offset. Run this in the execute method of a command, and the limelight offset will eventually be zero, and then you’re aiming at the goal.

This is our (slightly modified) 2020 code for aiming using vision.

public void execute() {
    if (vision.visionHasTarget()) {

      turret.turnToDegree(turret.getAngleDegree() + vision.getVisionXError());
    } else {
      turret.setSpeed(0);
    }
  }

You will need to use a PID loop for positional control, but it isn’t too complicated (if you read the documentation (this link is for ctr controllers)).

1 Like

Yes our plan is to be able to track the target while standing still and moving.

If your just trying to get going I would advise against controlling your turret in degrees.

turret.setRawVoltage(Limelight.tx * kp); , should be plenty to get you tracking.

start kp really small, invert if it goes the wrong direction.

3 Likes

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