Globals.controller.lastD0

4 posts / 0 new
Last post
casramsey
Globals.controller.lastD0

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

Arron Churchill
Arron Churchill's picture
Current lane

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:

  1. 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.
  2. Globals.userTargetLane- Latest value set by AimForLane(?). This should only change when the code sets a new value from somewhere.
  3. Globals.controller.autoTargetLane - Current offset generated by the image processing. As standard this holds the lane change used for preforming the overtaking override.
  4. Settings.targetTrackPosition - Settings adjustment for track target. Usually not used (set to 0.0), but it provides a way to change the target lane "on the fly" when simulating or testing a robot.
  5. full0 inside ControlLoop.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:

targetLane = Settings.targetTrackPosition + Globals.userTargetLane + Globals.controller.autoTargetLane

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

calculatedTrackValues = Globals.controller.lastSample
currentLane = calculatedTrackValues[0] + calculatedTrackValues[1]

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.

Arron Churchill
Arron Churchill's picture
Code fixed

I have done some testing and CurrentTrackPosition() is indeed wrong. The code for currentLane above works as intended and has been checked in to the Monster series and Grand Pi code already.

casramsey
Great stuff - thanks Arron.

Great stuff - thanks Arron.

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <pre>
  • Syntax highlight code surrounded by the <pre class="brush: lang">...</pre> tags, where lang is one of the following language brushes: bash, cpp, perl, python.
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Comment Images
Files must be less than 10 MB.
Allowed file types: png gif jpg jpeg.
Comment Attachments
Files must be less than 10 MB.
Allowed file types: txt pdf nfo doc docx rtf jpg png gif bmp zip tar gz csv xls.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.