Scripts
Ros-Nodes of the scripts folder.
Initial State Module
- Service:
/start
- Action:
/armor_client
This Node start the whole program by
- Looking for the aruco marker
orient the camera using the robot arm
decode information about the environment
initializing and loading the topology.
- class scripts.initial_state.InitialState[source]
Class representing the Initial-State of the Smach-State-Machine, which load the Ontology initialized with the environment description, and starting point of the Robot. …
- __init__(self)[source]
Initialization of parameters:
- client:ros_action_client
Armor-Client to set-up the Ontology
- path:str
The Ontology folder-path to load
- server:ros_server
the server of the Empty service /start with Callback execute()
- execute(self, request)[source]
Server Callback of the /start service requested from the fsm module to start up the whole program.
This Callback-Server load the ontology, set all the room of the environment with the respective doors, the starting position of the robot, already initialized in the starting ontology, the disjoint function that let the reasoner understanding all the individuals and I assumed all the rooms visited at time zero in order to yet start the counter for the URGENT rooms.
All the informations are retrived from aruco markers detection. Therefore the camera mounted on the robot’s arm scan the surroundings by achiving different orientations. The movement of the arm is performed by a MoveIt control node.
FSM Module
- Service:
/start /reason /recharge
- Action:
/armor_client motion/controller motion/planner
This Node implement the SMACH Finite-State-Machine that guide all the surveillance routine. The communication with other nodes is managed using ros-services and actions, the actual structure of the service and action client is implemented in the script helper.py in the utilities folder. two sub state machines are implemented to exploit the planning and control states while performing the movement and the recharge routine composed by a movement to the DOC-Station (Starting Room) and the actual recharging of the battery.
- class scripts.fsm.Controlling(interfacehelper)[source]
Class representing the controlling state directly connected with the script controller.py . When called from the SMACH state machine a action-client makes a request to the action-server motion/controller, and then it busy waits the response of the finished movement of the robot trough the via points passed by the client and taken from the Pointing State. Every acces to the flags to be checked is protected by mutexes in order to avoid simultaneus operations on the same varible, ROS automatically protect access to variables with mutexes.
Input Transitions:
- pointed:(str)
transition flag for the SMACH fsm from the Pointing state.
Returns:
- reached:(str)
transition flag for the SMACH fsm that ends the Moving sub-state machine
- battery_low:(str)
transition flag for the SMACH fsm to the recharge sub-state machine.
- class scripts.fsm.Initial(interfacehelper)[source]
Class representing the initial state directly connected with the script initial_state.py . When called from the SMACH state machine a client makes a request to the server /start, and then it busy waits the response of the finished loading of the Ontology from the server. Every acces to the flags to be checked is protected by mutexes in order to avoid simultaneus operations on the same varible, ROS automatically protect access to variables with mutexes.
First State runned when main state machine is called.
Returns:
- start:(str)
transition flag for the SMACH fsm to the reason state.
- class scripts.fsm.Pointing(interfacehelper)[source]
Class representing the pointing state directly connected with the script planner.py . When the sub-state machine moving is called from the SMACH state machine a action-client makes a request to the action-server motion/planner, and then it busy waits the response of the finished planning of the via-poits the robot will follow in the Controlling State. Every acces to the flags to be checked is protected by mutexes in order to avoid simultaneus operations on the same varible, ROS automatically protect access to variables with mutexes.
First State runned when the Moving sub-state machine is called.
Returns:
- pointed:(str)
transition flag for the SMACH fsm to the controlling state of the moving sub-state machine.
- battery_low:(str)
transition flag for the SMACH fsm to the recharge sub-state machine.
- class scripts.fsm.Reasoning(interfacehelper)[source]
Class representing the reasoning state directly connected with the script reason.py . When called from the SMACH state machine a client makes a request to the server /reason, and then it busy waits the response of the finished decision of which room will be pointed by the robot. Every acces to the flags to be checked is protected by mutexes in order to avoid simultaneus operations on the same varible, ROS automatically protect access to variables with mutexes.
Input Transitions:
- start:(str)
transition flag for the SMACH fsm from the initial state.
Returns:
- reasoned:(str)
transition flag for the SMACH fsm to the moving sub-state machine.
- battery_low:(str)
transition flag for the SMACH fsm to the recharge sub-state machine.
- class scripts.fsm.Recharge(interfacehelper)[source]
Class representing the Recharge state directly connected with the script battery.py . When the sub-state machine recharge is called from the SMACH state machine a client makes a request to the server /recharge, and then it busy waits the response of the finished recharging of the robot’s battery. Since the robot can recharge the battery only in the DOC-Statetion, if the robot is not there the fsm redirect the the state to the moving sub-state machine nested in the recharge sub-state machine in order to force the robot to DOC before recharging. Every acces to the flags to be checked is protected by mutexes in order to avoid simultaneus operations on the same varible, ROS automatically protect access to variables with mutexes.
First State runned when the Recharge sub-state machine is called.
Returns:
- battery_full:(str)
transition flag for the SMACH fsm that ends the recharge sub-state machine.
- not_at_dock:(str)
transition flag for the SMACH fsm to Moving sub-state machine in order to get to the DOC-station.
Reasoner Module
Service:
/reason
Action:
/armor_client
This Node implement the reasoner capable of decide the next-room to be visited by the robot. It firt retrive the position of the robot and the room it can reach, then it compute the next room giving priority to corridors, but if there’s one or more URGENT rooms it will point randomly one of them.
- class scripts.reasoner.Reasoner[source]
Class representing the Reasoning-State of the Smach-State-Machine, which decide the next room to point whenever a client-request on the custom-service /reason is performed by the finite state machine.
- __init__(self)[source]
Initialization of parameters:
- client:ros_action_client
Armor-Client to set-up the Ontology
- _helper:InterfaceHelper (object)
Object define in the intefacehelper script in utilities folder
- reachable_list:list[]
list of reachable rooms
- urgent_list:list[]
list of urgent rooms
- corridors:list[]
list of corridors
- execute(self, request)[source]
Server Callback of the /reason service requested from the fsm module to reason on the next room to point.
This Callback-Server updates the position of the robot, the room that can reach, the urgent rooms (if any) and the corridors. Then it calls the private method _next_room(self).
Battery Module
Service:
/reason
Action:
/armor_client
This Node implement the recharging bar visible at screen that starts whenever the robot battery is low and it is in the DOC-Station (Starting Room). In addition to this, in a new thread, a random notifier simulate the decrease of the robot’s battery while moving in the environment.
- class scripts.battery.Battery[source]
Class representing the Robot’s battery, it mainly has two functions a random alarm that notifies that the battery is low and need a recharge, a loading bar visible on screen that simulates the recharging action at the DOC-station.
- __init__(self)[source]
Initialization of parameters:
- server:ros_server
the server of the Empty service /recharge with Callback execute()
- _helper:InterfaceHelper (object)
Object define in the intefacehelper script in utilities folder
- _battery_low:Bool
variable that represent the state of the battery
- _random_battery_time:list[]
ROS parameter containing the interval of seconds in which the random notifier works
- th:thread
the thread in which the random notifier works
- execute(self, request)[source]
Server Callback of the /recharge service requested from the fsm module when the battery has to be rehcarged.
This Callback-Server calls the private method _printProgressBar(…) that simulates the recharging action.
- _printProgressBar(self, iteration, total, prefix='', suffix='', decimals=1, length=100, fill='¦', printEnd='backslash r')[source]
Call in a loop to create terminal progress bar
Parameters:
iteration - Required : current iteration (Int)
total - Required : total iterations (Int)
prefix - Optional : prefix string (Str)
suffix - Optional : suffix string (Str)
decimals - Optional : positive number of decimals in percent complete (Int)
length - Optional : character length of bar (Int)
fill - Optional : bar fill character (Str)
printEnd - Optional : end character (e.g. “backslash r”, “backslash n”) (Str)
Planner Module
Action:
/armor_client motion/planner
This Node implement the planning action of creating a set of via points between a room to another. Those via points will be then passed to the Controlling node to perform the actual movement.
- class scripts.planner.PlaningAction[source]
Class representing the Planning state of the Smach-State-Machine, which creates a set of via points between the robot position and a target room to be pointed decided by the Reasoner State and passed to this ros node via a motion/planner action-client request in the fsm script.
Controller Module
Action:
/armor_client motion/controller
This Node implement the controlling action that mainly consists in retrive the via points from the planner node and then move the robot sending a goal target to the move base action server. Once reached the final destination the current time and location associated with the robot is updated as the visited time of the room for the URGENT property estimation.
- class scripts.controller.ControllingAction[source]
Class representing the Controlling state of the Smach-State-Machine, which manage the robot’s motion trough via poits sent by request from the action-client motion/controller in the fsm script.
- __init__(self)[source]
Initialization of parameters:
- client:ros_action_client
Armor-Client to set-up the Ontology
- as:ros_action_server
the server of the motion/controller action
- execute_callback(self, goal)[source]
Server Callback of the action motion/controller requested from the fsm module to start up the controlling action towards a target room.
This Callback-Server move the robot by sending the goal to the move base action server. Once the robot reach the target room some Ontology paramenters are updated:
the robot location (isIn)
the time related to the robot (now)
the time in which the new target room is visited (visitedAt)
- action_client()[source]
Defining the client function that constructs a SimpleActionClient in order to open a connection to the Move Base ActionServer. This function sets some parameters of the client
- active_cb()[source]
No-parameter callback that gets called on transitions to Active. This function is called before the goal is processed
- done_cb(status, result)[source]
Callback that gets called on transitions to Done. The callback should take two parameters: the terminal state (as an integer from actionlib_msgs/GoalStatus) and the result. This Function is called after a goal is processed. It is used to notify the client of the current status of every goal in the system.