FRC Chameleon Vision Only Updates Pitch and Yaw Values Once

We are an FRC team using VSCode trying to use Chameleon Visions example code (Robot Code Example — Chameleon Vision documentation) to auto-align to a target. When we run the code the robot gets the Pitch and Yaw values and spins to try and get to the target. The problem is that the Pitch and Yaw values only update when the command starts and then stay static. They continue to update on Chameleon Vision but the code only takes them once. Is there a way to have the code constantly update the values while the command runs?

A few things here:

  1. Chameleon Vision hasn’t been under active development for a while. The Chameleon Vision developers have since moved on to the PhotonVision project.
  2. In order to have the values update, you’ll need to put the lines of code that update the values into the execute() block of your command. I suspect you’ve put them in an area that would only update once, such as the constructor of the command, but I can’t tell for sure without seeing your code specifically.

This is our GitHub page: GitHub - CSW-Robotics/V2-CSW-Robotics-2021-Code-5347

We have Sub_NetworkTables that we want to run constantly to update the Pitch and Yaw values and then there is Cmd_PID_Alighn that turns the robot.

It would appear you attempted to do this, at least for pitch, using the periodic method of your Sub_NetworkTables subsystem.

However, because you specified the type *NetworkTableEntry* pitch, java will treat this as a new variable in the local (method) scope, and not as the class variable up on line 19. The same holds true for your Pitch() and Yaw() methods. They won’t update your class’s variables because you initialized them as new variables within the method.

These should be getting updated values as far as I can tell from the following lines in the execute() method.

Is this not functioning? or are these new changes seeing as the last commit is about the same age as your last post in this thread?

This commit has had the same problem of the pitch and yaw not updating but we will change Sub_NetworkTables so the pitch and yaw variables are the ones initialized on line 19 and see if that works. Unfortunately due to school covid restrictions, it is hard to get access to the robot and we probably won’t be able to until later this week but thank you so much for the suggestions!

We changed Sub_Networktables so the Pitch and Yaw variables initialized at the top are the ones used throughout the subsystem. (and we committed the changes to GitHub) But the robot seems to still have the same problem of the Pitch and Yaw not constantly updating. Are there any other suggestions you have or flaws that you see? Thank you so much for the help.

The network table values are updated by Chameleon Vision independent of your code (we used it last year so have some familiarity with it) but I don’t think this is a Chameleon Vision issue.

Here are my thought (you’ll find they really are the same as what @bobbysq mentioned but we can come at it from a slightly, very slightly, different direction):

  • Watch your network tables while you are running using the dashboard - you should be able to see them changing as Chameleon Vision updates them.

  • Take a look at each and every place where you get a value from the network table. Are you saving it to use later? Be careful because this is a likely cause of getting stale data . Take a look at your code and make sure you are getting new values before using them. If you do this 5 times in a function it, you might need to get it 5 times depending on your logic or it might be OK to get it once at the top - if that value is appropriate to use multiple times in that function.

Look carefully to make sure you aren’t saving the value from a previous read that happened in the past. As @bobbysq mentioned, the logic you are trying to do should be done in the execute() function and you’ll want to get the new values each and every time you enter this function to get the latest, most current values.

I’m betting the values are updating in the network table but you have a bug where you aren’t picking the new values up frequently enough (or maybe not at all after the first one).

It’s brutal but if you look at everyplace you want to use a value like “yaw” and backtrack to where it got picked up from the network table, you’ll probably see that it isn’t very fresh and is the root cause of your problem. In your execute() routine, you should be picking up “yaw” like right before the first time you need it and possibly even before each time you’re using it (depending on what you’re doing - there are a ton of ways to slice this logic-wise). You could go so far as taking a look at changing anyplace you are using your “yaw” variable and replace it with the appropriate call to pick it up from the Network Table.

One other thing, there is a “isValid” boolean entry that indicates whether there is a target or not - only try to get the target related values when “isValid” is true.

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