Problems with using 330's goal tracking code

Hi, We took team 330’s goal tracking code and made modifications so that the X axis output would be to control a victor for a turret. We pretty much just removed the Y-axis PID control loop and are using only the X-axis PID control loop for control the position of a turret. When we run the code, the bot finds the target and oscillates left and right. I increased the integral gain to reduce the steady state error, but there was no improvement. I also tried playing around with the proportional and derivative gains, but there was also no improvement.

Has anyone attempted what I’m doing and might know the source of my problem?

I attached two screenshots of my code for reference. As an incentive, feel free to use my ideas for your bot as well if you feel that they are useful to you. All the credit should go to team 330 though!

goal_track_main.pdf (215 KB)
goal_track.pdf (170 KB)

goal_track_main.pdf (215 KB)
goal_track.pdf (170 KB)

I have a private message from Matt Krass from a very long time ago that seems to apply here:

I personally have never used D. I gave up working on the mental gymnastics to make it work on our non-floating-point controller last year, and haven’t done much at all with the cRIO. These young whipper-snappers…when I was your age, we had to use fixed-point math, and walk uphill–both ways–to the competition field…:stuck_out_tongue:

I’m sure someone a bit more qualified to answer will see this post later today, and you will get a collection of responses better-constructed and -advised than mine.

Good luck,

Thanks for the tuning procedure, Jacob! I will definitely try your suggestion! I’m really concerned that I have a bug in my code somewhere that I’m not seeing. Before I assume that it is a tuning problem, I really would like a fresh set of eyes to take a look at my code and see if there is anything fishy.

Your advice is great Jacob! Thanks for the quick reply…i’m actually loosing sleep over this code!

Someone else may be able to tell you exactly what to change, but I don’t see it. What I’d do is modify the code to plot your process variable and your output against time. If you post that, people can tell you much more about your system.

To get the plot, take the vision value you are trying to center and bundle it with the output of the PID. Then wire the cluster to a waveform chart. Next you “bump” the system. Start with the target in the center and move it to one side pretty quickly and hold it there until the control system moves to that area. Do this again to the other side. You may need to increase the X scale or even the history length to log enough data.

Greg McKaskle

Jacob’s recommendation on tuning P first is exactly what you should do. We’ve used PID controllers for the past 5 years, and used just P control on almost all of them. There are several good white papers on CD about PID, including one by Matt Krass. Greg’s suggestion of plotting the values is a good one. One way to get the step input is to change the setpoint. See also, the following excerpt from the PID article on wikipedia: Once you understand the manual process, you could try to play around with autotuning:

The example was optimized for driving on the regolith, so there’s a few things you’d probably want to change for driving a turret.

The first thing I’d do is remove the PID rate limiter. This was designed to keep the wheels from slipping. Hopefully your turret doesn’t have that problem. Leaving that in there will slow down the response and make it more likely to oscillate.

I’d also replace the robot drive VIs with the motor control VIs. Since you aren’t using the features of robot drive, I’d go with the lower overhead.

You mentioned using a Victor speed controller. I’d highly recommend using a jaguar. It will give a more linear response (PID is designed for linear systems). It also gives you much better slow speed control, which will help in reducing the oscillations.

Thanks for the replies Joe and Greg! Since you guys haven’t mentioned anything about the layout of my code, can I assume that you think my code layout is correct, but I need to adjust the PID gains? I just want to validate my code before I start tuning.

Right now I’m testing the code by having it turn the bot towards the goal to ensure that the code is written correctly. I understand that I’ll need to change the gains for the turret application, but it will be nice to know that the gains is all i need to change. When I ran the code out of the box from the team 330 posting, I figured that since our bots are similar in size, mass and drive configuration (tank drive) that their PID gains would be close to what I would want. So when I saw the bot oscillating, I immediately thought that it was a code problem. Just for confirmation, the out of the box gains in the program was proportional=0.5, derivative=integral=0.0.


The out of the box settings were 0.05 for P, 0 for the others. Due to a few mistakes, the settings in the code didn’t match the settings from the video. I think the gains might have been the very, but the maximum output values were higher in the code then the video. I figured that most people would have to tune the values anyway, so I didn’t spend the extra time to recreate the ones from the video. Sorry for leading you down the wrong path.

No worries, Joe! Thanks for the reply! is it possible to get an example set of gains from you so that I have something to start with that will tell me weather or not the code is correct and that the problem is only with tuning? Maybe not your best set of parameters, but something that converges to no error over time. That way if mine doesn’t converge then I know something is wrong.

I’m a fulltime engineering student and although I would like to mentor the team all day and get things just right, I have to do my studies too so it is hard sometimes to find the time to tune things from scratch. Again im not asking for competition gains, but something that will guarantee converge. Thanks!

Thanks for your help! It looks like I was able to get the response to converge. here are my gains for anyone interested. x-axis:P0.003,I0.5. y-axis: P0.015,I0.70. derivative terms 0. max x=0.45,max y=0.7

I’m trying to plot the x and y axis outputs to a graph but im having some trouble. I’m using the plot waveform and feeding to the input a get waveform time array, but im not getting the correct data types. Can anyone briefly explain the process to do this?


One of the easiest ways to do this is to:

  1. Go to your Front Panel
  2. Select Express->Graph Indicators->XY Graph (aka Express XY Graph)
  3. On the block diagram, wire your X and Y inputs
  4. Double click the Build XY Graph on the block diagram and turn off Clear Data on Each Call.


how do you put time values for the x variable each iteration? I guess I could just put a counter that increments, but im not sure how to do this either. I would like to not use a for loop. Any suggestions?

Sorry, I assumed you wanted an XY plot (plotting one variable against another). If you have two independent variables to plot, then use a Chart.

Bundle the two values (presumably X and Y) together and then wire to the Chart terminal.