Limelight programming help!

I am an slightly experienced programmer with team 2352. We are trying to use limelight but we cannot figure out how to make the motors react with the limelight values. I have looked at the limelight documentations but I still cannot figure out how the motors connect to the camera. Help would be appreciated!

1 Like

The camera does not feed motor values automatically… You’re going to have to do some scaling to use the values from the Limelight and convert it to a usable motor value.

One way to do this is through a simple PID Controller where only the P value is used. All it would do is take in the tx and ty values from the limelight, multiply it by this P value and set the motor to that value. This will move the robot in the correct direction towards aligning with the vision target.

This is a VERY high level explanation but if you would like a deeper explanation or want to see my GitHub, shoot me a PM and I would gladly help you out!

1 Like

The Limelight documentation has a good set of examples on how to do this, look at their Case Study section of their docs for code examples.
Here’s a link to our github that has a command example that is bound to a button on the controller to automatically drive toward the limelight target up until it reaches a certain area (distance from target).

2 Likes

The docs mentioned above are definitely the right starting point. It’s also not hard to build up the motivation for what you’ll be doing from first (ish) principles.

Question: What would you like your motors to do in response to limelight values?

For example, say the limelight detects the target 15 degrees to the right. What should the motors do?

2 Likes

I would like the robot to seek the target and follow it. For example if someone was wearing the vision tape the robot would follow them. I mainly want a way to center the vision target.

1 Like

Cool, this is a good start.

What sort of drivetrain do you have? What sort of motor speeds should happen if the target is 15 degrees to the right? How about 3 degrees to the left?

As a parallel line of thought:

How does your driver currently cause the robot to rotate a certain number of degrees left or right?

One way to approach the problem is to think of the limelight as a “replacement driver”. When the limelight tells you you’re too far to the left, you need to cause the robot to rotate to the right, in the same way a driver would make the robot go to the right.

Very specifically: the driver moves a joystick, which ends up as a number between -1 and 1 somewhere in code. This is then passed to some drivetrain class, which uses it to calculate motor speeds to accomplish the motion command.

If you were to (in code) replace the driver’s command with some command calculated from limelight numbers, in theory, your drivetrain could be made to turn toward the target.

I’m describing the process at a high level again. There’s lots of resources out there that will jump right in and talk about PID and gyros and such. They’re not wrong, robust solutions often require these. However, all of the solutions won’t make a ton of sense without an intuitive understanding of what the system needs to do, or how it will accomplish it.

1 Like

I’m currently using arcade drive and I have the drive motors set up on joysticks. Does that answer your question?

1 Like

There is very simple plug and play code on the limelight website. Go to the docs and look at the case studies. Find the one that suits your needs best and literally just paste it into teleopperiodic.

1 Like

It does answer this one:

However, it doesn’t directly address this one:

The mental model to have:

  1. Joysticks measure commands from an operator, and pass them to a drivetrain (“arcade drive”) class.
  2. These commands involve “how much forward/backward motion do you want”, and “how much rotation do you want”?
  3. These commands are represented by floating point numbers, within the fixed range of -1 to 1.

For a limelight to take the place of an operator, it would have to emulate the command you currently get from a joystick, and produce just such a command to cause the drivetrain to rotate as you desire.

Between this, and the links provided by others, I think there’s a lot to get started on. Chew on the problem yourself a bit, and see what you can learn.

1 Like

Okay after experimenting with the code and help provided this is what I have created.

//Drive Controls
double left_command = m_driver.getRawAxis(1);
double right_command = m_driver.getRawAxis(4);
double right = m_limelightTable.**getTX()***m_steeringKP; // This is where I get my errors.
double left = (m_targetArea-m_limelightTable.getTA())*m_driveKP; // This is where I get my errors.

m_Drive.arcadeDrive(left_command, right_command);

if (m_limelightTable.isTargetValid()) { // This is where I get my errors.
if (m_limelightTable.getTA() >= m_targetArea) { // This is where I get my errors.
left = 0;
right = 0;
}
} else {
left = 0;
right = 0;
}

m_Drive.arcadeDrive(left, right);

}

But I am still getting errors at the bolded texts.

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