RtActivities that start one of two options depending on a sensor measurement.
With the class ConditionalRtActivites, the Robotics API provides the possibility to differentiate between two pre-planned Activites and, depending on the result, chooses one of them to execute.
In order to use the class in an application, it must be fully parameterized upon
construction.
The constructor itself needs two separate Activities (which can be
ConditionalRtActivites themselfes for further branching) and a special type of
Sensor called BooleanSensor. Sensors will be further explained in the next
chapter.
A BooleanSensor can only return two values: True and False.
When the ConditionalActivity is executed by the RCC, the current value of the
Sensor is checked and based on the result, the first (BooleanSensor returns True) or
the second (False) Activity will be executed.
It is also possible to commit just one Activity and a BooleanSensor to a ConditionalRtActivity. Then, the committed Activity will only be executed if the Sensor is True.
The full constructors for both approaches are shown below:
How to create | Summary |
ConditionalRtActivity (BooleanSensor condition, RtActivity ifActivity) | Returns a ConditionalRtActivity which only executes if the Sensor is ”‘True”’ |
ConditionalRtActivity (BooleanSensor condition, RtActivity ifActivity, RtActivity elseActivity) | Instantiates a new ConditionalRtActivity which executes the ”‘ifActivity”’ if the Sensor is ”‘True”’, and the elseActivity if the Sensor is ”‘False”’ |
Alternative: Invoke RtActivities.ifElse (condition, ifActivity, elseActivity) | Returns an instantly created and anonymous ConditionalRtActivity |
Like every Activity, a ConditionalActivity can be given a name too, but the constructors still stay the same:
As stated above in the video, the following Example instructs a lightweight Robot to drive its left arm with two different Activities: The first one will be executed no matter what, while the second one will start only if there was no obstacle in the way of the first movement. Please note that this is just a quick illustration and that the collision-handling, which is vital in a real environment context, is nowhere implemented. It is therefore strongly advised to not use this code with a real robot.
If the application is tested as a simulation, it is recommended to use the class
BooleanFromJavaSensor, instead of a BooleanSensor, since the BooleanFromJavaSensor
can be parameterized by hand and thus, every possible outcome can be calculated.