![]() |
![]() |
| Bearing Sensor |
The Bearing Sensor is really more of a Bearing Calculator. Components like
the Waypoint and Loot Sensors can tell you where a target is. Given that
target, the Bearing Sensor
allows your rover to maintain a heading toward your goal by
telling you whether you're aiming right at it or off to one side. The two
inputs you need are the
RefBearing, which is the direction you are trying to go, and the FuzzyAngle,
which governs the precision of the sensor.
If, somehow, you know where you want to go in advance, you can also feed that value to the BearingSensor by setting it manually. | ||||||||||||||||||||
| ICE | Thanks to KentQ at CogniToy for dishing out the code for the Bearing Sensor. Let's break it down... | ||||||||||||||||||||
sub sense()
' Update TrueBearing
p as Position
p = system.getObjectAbsolutePosition()
TrueBearing = p.getOrientationAngle()
| |||||||||||||||||||||
| Every 0.24 seconds, sense() gets called, and the rover's orientation in the global reference frame is calculated as a degree value. | |||||||||||||||||||||
if(TrueBearing < -180) then
TrueBearing = TrueBearing + 360
elseif(TrueBearing > 180) then
TrueBearing = TrueBearing - 360
end if
| |||||||||||||||||||||
| TrueBearing gets massaged to insure that it is in the range -180 to 180 degrees. Remember that 0 degrees is forward, +90 is left, and -90 is right. | |||||||||||||||||||||
DeltaBearing = TrueBearing - AbsoluteRefBearing
if(DeltaBearing < -180) then
DeltaBearing = DeltaBearing + 360
elseif(DeltaBearing > 180) then
DeltaBearing = DeltaBearing - 360
end if
| |||||||||||||||||||||
| DeltaBearing is calculated as the difference between TrueBearing and AbsoluteRefBearing, which seems to be calculated somewhere else. I have to assume that it is the translation of RefBearing (the desired angle in the vehicle's reference frame) to the absolute reference frame. Then DeltaBearing is also massaged to be between -180 and 180 degrees. | |||||||||||||||||||||
if(DeltaBearing <> LastFrameDeltaBearing) then
call Change.trigger()
LastFrameDeltaBearing = DeltaBearing
end if
| |||||||||||||||||||||
| If DeltaBearing is not the same as last time, then trigger a change event. | |||||||||||||||||||||
whatEvent as integer
nextEvent as Event
if(abs(DeltaBearing) < FuzzyAngle) then
whatEvent = 0
nextEvent = OnRef
elseif
deltaBearing < 0 then
whatEvent = -1
nextEvent = RightOfRef
else
whatEvent = 1
nextEvent = LeftOfRef
end if
| |||||||||||||||||||||
| Now check and see if DeltaBearing is bigger than our FuzzyAngle. If it is, then figure out what kind of event to throw. | |||||||||||||||||||||
' Only fire nextEvent if it's actually different from last time.
if whatEvent <> lastEvent then
lastEvent = whatEvent
call nextEvent.trigger()
end if
end sub
| |||||||||||||||||||||
|
And the comment says it all. If it isn't news, we don't wanna know.
Properties |
The Bearing Sensor has four properties, two of which you will want to keep
track of. The other two seem to be for internal use only.
|
Events |
| The bearing sensor can trigger four events:
|
![]() |
![]() |