# Option track-ball The state machine for the ball tracking movements ## State Machine ## State other-modes
If that state is active,
> | The option other-head-movement is executed.
The decision tree:
Pseudo code of the decision tree:
if ( | ball.time-since-last-seen < 1000 | ) | // ball seen by chance in the last second
{
transition-to-state(scan-back-to-ball);
}
else
{
transition-to-state(ball-lost);
}
## State ball-seen
If that state is active,
> | The basic behavior look-at-ball-and-closest-landmark is executed.
The decision tree:
Pseudo code of the decision tree:
if ( |
( | ball.time-since-last-seen > time-after-which-is-considered-lost | )
&& |
( | ball.seen.distance < 500 | )
| ) | // ball lost near
{
transition-to-state(ball-just-lost);
}
else if ( |
( | ball.time-since-last-seen > (time-after-which-is-considered-lost * 1.5) | )
&& |
( | ball.seen.distance > 500 | )
| ) | // ball lost far
{
transition-to-state(ball-lost);
}
else if ( | head-control-mode == search-auto | ) | // head control mode is searchAuto
{
if ( |
( | time-of-state-execution > 1000 | )
&& |
( | ball.consecutive-seen-time > 1000 | )
&& |
( | ball.time-since-last-seen-consecutively < 300 | )
&& |
( | ball.relative-speed-x > -300 | )
&& |
( | ball.seen.distance > 1200 | )
| ) | // Ball was seen consecutively for 500 ms
{
transition-to-state(directed-scan-away-from-ball);
}
else if ( |
( | time-of-option-execution > 2000 | )
&& |
( | ball.time-since-last-seen < 300 | )
&& |
( | ball.seen.distance > 800 | )
&& |
( | ball.consecutive-seen-time > 2000 | )
&& |
( | ball.time-since-last-seen-consecutively < 500 | )
&& |
( | ball.relative-speed-x > 300 | )
| ) | // ball rolls off
{
transition-to-state(directed-scan-away-from-ball);
}
else if ( |
( | time-between-last-beacons > 8000 | )
&& |
( | ball.relative-speed-x > -200 | )
| ) | // ball is near but roboter hasnt seen two diffrent beacons for long
{
transition-to-state(directed-scan-away-from-ball);
}
else if ( |
( | time-since-last-seen-beacon > 5000 | )
&& |
( | ball.relative-speed-x > -200 | )
| ) | // ball is near but roboter hasnt seen any beacon
{
transition-to-state(directed-scan-away-from-ball);
}
else if ( |
( | (time-since-last-seen-beacon / 3000) > 3 | )
&& |
( | time-since-last-seen-beacon > 10000 | )
| ) | // ball is near but roboter hasnt seen any beacon for long
{
transition-to-state(directed-scan-away-from-ball);
}
else
{
transition-to-state(ball-seen);
}
}
else
{
transition-to-state(ball-seen);
}
## State return-to-ball
If that state is active,
> | The basic behavior return-to-ball is executed.
The decision tree:
Pseudo code of the decision tree:
if ( | ball.time-since-last-seen < 250 | ) | // ball found again
{
transition-to-state(ball-found-again);
}
else if ( |
( | time-of-state-execution > 1000 | )
( | set-joints-is-close-to-destination | )
| ) | // After 1 sec
{
transition-to-state(ball-lost);
}
else
{
transition-to-state(return-to-ball);
}
## State directed-scan-away-from-ball
If that state is active,
> | The basic behavior directed-scan-for-landmarks is executed.
The decision tree:
Pseudo code of the decision tree:
if ( | head-control-mode == search-for-ball | ) | // head control mode is searchForBall
{
transition-to-state(return-to-ball);
}
else if ( |
( | time-of-state-execution > 800 | )
( | set-joints-max-pan-reached | )
( |
!( | next-landmark-is-within-reach | )
| )
| ) | // if robot has looked away from the ball for some time
{
transition-to-state(scan-back-to-ball);
}
else
{
transition-to-state(directed-scan-away-from-ball);
}
## State scan-back-to-ball
If that state is active,
> | The basic behavior scan-back-to-ball is executed.
The decision tree:
Pseudo code of the decision tree:
if ( | ball.time-since-last-seen < 250 | ) | // ball found again
{
transition-to-state(ball-found-again);
}
else if ( | head-control-mode == search-for-ball | ) | // head control mode is searchForBall
{
transition-to-state(return-to-ball);
}
else if ( |
( | ball.time-since-last-seen > 1000 | )
( | set-joints-is-close-to-destination | )
| ) | // No ball was found
{
transition-to-state(ball-lost);
}
else
{
transition-to-state(scan-back-to-ball);
}
## State ball-just-lost
If that state is active,
> | The basic behavior look-around-at-seen-ball is executed.
The decision tree:
Pseudo code of the decision tree:
if ( | ball.time-since-last-seen < 160 | ) | // ball found again
{
transition-to-state(ball-found-again);
}
else if ( | time-of-state-execution > 450 | ) | // ball was not found
{
transition-to-state(ball-lost);
}
else
{
transition-to-state(ball-just-lost);
}
## State ball-lost
If that state is active,
> | The basic behavior find-ball is executed.
The decision tree:
Pseudo code of the decision tree:
if ( | ball.time-since-last-seen < 250 | ) | // ball found again
{
transition-to-state(ball-found-again);
}
else
{
transition-to-state(ball-lost);
}
## State ball-found-again
If that state is active,
> | The basic behavior look-at-ball is executed.
The decision tree:
Pseudo code of the decision tree:
if ( | ball.time-since-last-seen > (time-after-which-is-considered-lost * 1.5) | ) | // ball lost
{
transition-to-state(ball-lost);
}
else if ( | time-of-state-execution > 500 | ) | // after 500 ms
{
transition-to-state(ball-seen);
}
else
{
transition-to-state(ball-found-again);
}