loading
 
Alerting when locked on - FRC image tracking
Kyle Fischer from United States  [8 posts]
11 year
Is there a way to get a message back to the smart dashboard saying that we are currently tracking distance to the goal. For example, if a robot or something is blocking our view can we get a signal saying that we are currently not tracking and to not use the data. Thanks
Steven Gentner from United States  [1446 posts] 11 year
Kyle,

Yes, you can but it depends on how you are doing the tracking. For example, if you are using the blob replace module to generate the BFR_COORDINATES the test in the VBScript will check that this is an array or not. When something is in the way, tracking will be lost and this variable will not contain anything. So if you add an "else" to the if array statement you can zero out the distance variable that gets sent. For example:

if isArray(list) then
  if ubound(list) > 0 then

... other stuff ....

  else
    SetVariable "/SmartDashboard/Distance", 0
  end if
else
  SetVariable "/SmartDashboard/Distance", 0
end if

which would set the Distance variable to zero when its not tracking. Then on your side, if you see this variable go to zero, you know that tracking is disabled ... this naturally assumes that the distance is never a true distance of zero which is reasonable since the camera would not be seeing the target if it were in fact 0 inches from the target.

If you are using the Target_Localization module, that will remove the variables (you can assume it to also be zero) when tracking fails.

Does this help?

STeven.
Kyle Fischer from United States  [8 posts] 11 year
Ok we are using the blob filter module but how would you do this with a Boolean? I am unfamiliar to vbscript and i keep getting syntax errors.
Thanks
Steven Gentner from United States  [1446 posts] 11 year
Can you post your VBScript here or include your entire robofile for us to look at? We'd just be guessing otherwise.

Keep in mind that a boolean is just a zero or non-zero value so it can easily be emulated using a number.

STeven.
Kyle Fischer from United States  [8 posts] 11 year
here is the code.

list = GetArrayVariable("BFR_COORDINATES")
if isArray(list) then
  if ubound(list) > 0 then

        targetPixelHeight = 0
    targetSamples = 0

    ' calibrated for an Axis camera
    imageHeight = GetVariable("IMAGE_HEIGHT")
    imageWidth = GetVariable("IMAGE_WIDTH")
        centerX = imageWidth / 2
      cameraFieldOfView = 47.5
      targetHeight = 31.0

    ' grab list of coordinates from blob_replace
         ' note the array is sorted by previous module in a specific order
    righty = list(1)
    rightyy = list(7)
    lefty = list(3)
    leftyy = list(5)

        ' based on these two side lines get the center line height
        ' the center line is used since we want to aim to the center
      ' of the target. This also removes any perspective distortion
      ' where the right or left size may be a couple inches closer
        ' or futher away from the camera
      targetPixelHeight = ((lefty - leftyy) + (righty - rightyy)) / 2

write targetPixelHeight

    ' we can use a known distance to determine FOV if we don't know it
      ' measuredDistance = 10.0*12.0
      ' write "Calculated FOV " & (((atan((((targetHeight*imageHeight)/targetPixelHeight)/2)/measuredDistance)*2.0)*180.0)/3.14159) & vbCRLF

    ' determine distance in inches
    totalDistance = (((targetHeight*imageHeight)/targetPixelHeight)/2)/tan(((cameraFieldOfView*3.14159)/180.0)/2.0)
    
        SetVariable "Distance", CInt((totalDistance*100)/12)/100
        ' since we know the FOV of the camera we can simply scale the total field
        ' of view into the pixel distance from center of screen to desired target
        angleCenterX = (list(angleTo)+list(angleTo+2)+list(angleTo+4)+list(angleTo+6))/4
        ' we now know the center of the target X coordinate
        angle = (cameraFieldOfView * (centerX - angleCenterX)) / imageWidth
        SetVariable "Locked", true
        SetVariable "Angle", CInt(angle*100)/100
        else
        SetVariable "Locked", false
    end if
    else
    SetVariable "Locked", false
end if

program.robo
Steven Gentner from United States  [1446 posts] 11 year
Kyle,

Looks like you got it! I checked the VB and it seems to be functioning ok. If you run into issues on the receiving side you can try using

SetVariable "Locked", 0

or

SetVariable "Locked", 1

instead of true and false if you find that working with bools is not quite working correct. While NT supports bools, they may translate to ints (0 or 1) before you get them either in Java, C++, Labview, etc.

Or are you still getting an error in the above code? Seems to work on the most recent RR version.

STeven.
Kyle Fischer from United States  [8 posts] 11 year
Ok thank very much. It works now greatly. Once again thanks

This forum thread has been closed due to inactivity (more than 4 months) or number of replies (more than 50 messages). Please start a New Post and enter a new forum thread with the appropriate title.

 New Post   Forum Index