-
Notifications
You must be signed in to change notification settings - Fork 43
Python API
It is possible to specify a robot mission in Aerostack using Python language using certain predefined functions. The specification must follow certain conventions that are explained below.
A mission that simply takes off and lands the robot is specified as follows:
import mission_execution_control as mxc
def mission():
mxc.executeTask('TAKE_OFF')
mxc.executeTask('LAND')The function mission() is a special function that is executed when the mission is started. As you can see, for this example it is necessary to import the mission_execution_control package in order to use the executeTask() function. This function executes any task and waits for it to complete. It returns a string with the termination status. The available tasks performed by behaviors can be found here:
Recurrent tasks don't terminate until they are stopped, so they mustn't be executed with the function executeTask(), or they will block the program with and endless loop. In order to activate a task without waiting for its termination, the function startTask() is provided. To deactivate a recurrent task, use the function stopTask(). Example:
import mission_execution_control as mxc
def mission():
mxc.executeTask('TAKE_OFF')
mxc.startTask('PAY_ATTENTION_TO_QR_CODES')
mxc.executeTask('FOLLOW_PATH', path = [ [0, 2, 1], [2, 2, 1] ])
mxc.executeTask('ROTATE', relative_angle = 270)
mxc.executeTask('FOLLOW_PATH', path = [ [3, 3, 1], [3, 0, 1] ])
mxc.stopTask('PAY_ATTENTION_TO_QR_CODES')
mxc.executeTask('LAND')In order to add and remove beliefs from the belief memory the functions addBelief() and removeBelief() are provided.
To consult the belief memory, two functions are provided: queryBelief() and trueBelief(). The latter simply returns true or false, while the first returns a boolean and a dictionary with the variables unified if it was successful. Example:
import mission_execution_control as mxc
def mission():
mxc.addBelief('color(9, red)')
mxc.addBelief('empty(9)’)
result = mxc.trueBelief('color(?X, ?Y)') # This will return true
success, unification = mxc.queryBelief('color(?X, ?), empty(?X)')
if success: # Always check if query was successful before trying to access the unification variables
my_string = unification['X']
mxc.removeBelief('color(%s, red)' % my_string)
mxc.removeBelief('empty(%s)' % my_string)Contact: We thank and welcome any suggestion or comment about Aerostack. For any question or bug report you can read and/or write at the issues page. You can also contact the team support at the following address: [email protected]
The content of the Aerostack wiki is licensed under Creative Commons license CC BY 4.0