-
Notifications
You must be signed in to change notification settings - Fork 0
robot_class
mbot_robot_class was created to make it easier to use mbot. It was developed as a set of python classes, divided into the main functions (e.g., manipulation and navigation). Its purpose is twofold - to be a central python API, and to allow interaction with a user/developer, not only for testing purposes, but also for daily use.
One caveat to take into account is that being developed in python script, it should not be used for real-time constrained tasks. Many functions have hidden sleeps to allow subscribing to a topic (e.g. a PCL topic), and it is designed to be used occasionally, not constantly.
Another thing to take into consideration is that, to allow versatility, the package does not have any build or run dependencies on other mbot packages. As such, in case of not being installed, some functionalities may not be available if you launch this package in your PC. Launching inside the robot (SSH first) will solve these issues; some (very limited) functionalities are not at all available outside the robot.
The two main uses for mbot_robot_class are described below, as well as how to use them.
mbot_class # an alias created in the scripts repository
rosrun mbot_robot_class_ros interactive_node.sh # alternativeRequires ipython. Using this command in a terminal will launch an ipython interactive session and create a fully-featured mbotRobotInstance object from mbot_robot_class.
Writing mbot, followed by a double-tab, will allow you to see the kind of functionalities available. As an example, by entering mbot.hri.say? you can see the expected arguments of this functionality. Not all functions have sanity checks for the arguments.
from mbot_robot_class_ros import mbot as mbot_class
mbot = mbot_class.mbotRobot()The main use for mbot_robot_class is as an API, especially for state machines and other frameworks requiring high versatility.
To use in libraries, such as smach states, there is no need to make the mbot variable global. Only one mbotRobot() object can be created at any time in a script, and it is implemented as a singleton. Using some python magic, the following can be done to avoid re-creating this object multiple times along your program (meaning you also dont need to save it as a class variable):
#in the beginning of your code
mbot_class.mbotRobot() # creates the object, leaves it in memory
mbot = mbot_class.mbotRobot # easy access to the singleton, as a function object
#in another function
mbot().hri.say('test')
mbot().navigation.get_available_locations()
#if you need a specific function multiple times
say = mbot().hri.say
say('bla')
say('bla2')The object creation can take one of two dictionaries: enabled or disabled, describing the functionalities to be used. An example can be seen in the TBM state machine scripts. Included in mbot_robot_class is the what_can_be_disabled.py script (you can launch it with rosrun), that takes a filename as an argument. After developing your code, use this script to find out which functionality you can safely disable from mbot robot class. This will minimize the amount of subscribers and publishers created.
After the object creation, subsequent function calls do not need these arguments.