Hi - I'm doing some work on the image processor and wanted to know what lane I'm in. I can't import RaceCodeFunctions because it would cause an import loop, however RaceCodeFunctions.CurrentTrackPostion() just returns Globals.controller.lastD0, so I am using that.
My problem is that I am often getting numbers such as -3.50 which would be a position that would mean I was stuck at the edge of the track. I am seeing this when I am roughly at lane -2 visually according to the simulator and the only call made at that point is AimForLane(2). No overrides have been reached at that point (which is just after the start). There is a lot going on with d0 in RunLoop that I don't fully understand, but I would have thought that is would still just give me the lane I'm on. Anyone know what could be going on there?
Thanks
Jason
Part of the confusion here is that there are multiple meanings to the "where am I" question in the robot code.
These are the most likely values you would want and what they actually mean:
Globals.controller.lastD0
- Current offset from the target lane calculated from the last image. This will be a little noisy at times so you may need to filter / average the value before using it.Globals.userTargetLane
- Latest value set byAimForLane(?)
. This should only change when the code sets a new value from somewhere.Globals.controller.autoTargetLane
- Current offset generated by the image processing. As standard this holds the lane change used for preforming the overtaking override.Settings.targetTrackPosition
- Settings adjustment for track target. Usually not used (set to0.0
), but it provides a way to change the target lane "on the fly" when simulating or testing a robot.full0
insideControlLoop.RunLoop
- Current offset from the track center calculated from the last image. This is probably the value you wanted, but is buried in the PID loop code.To get the full target the image processing code is tracking to you want the sum of the settings adjustment, the race code target, and any override adjustments. This is the sum to use:
You can re-calculate the actual offset calculated from the track using the last set of results passed from the image processing to the control loop like this
It looks like there is a mistake in the
CurrentTrackPosition()
function. It is actually returning how far the robot currently is from its target lane rather than the actual track offset position. It should be using the code listed above for calculating the lane. I will test this change and check it works as intended.I have done some testing and
CurrentTrackPosition()
is indeed wrong. The code forcurrentLane
above works as intended and has been checked in to the Monster series and Grand Pi code already.Great stuff - thanks Arron.
Add new comment