robot_brain2 module
This script defines a class ActionClientcortex that implements a SimpleActionClient to send and cancel goals to a specified service. It also defines a class sensory1 that acquires locations from a database using ArmorClient, determines the robot’s current location, and chooses a target location based on the robot’s position, reachable locations, and urgency.
In the working scenario, the robot uses sensory1 to determine its current location and choose a target location. Then, the ActionClientcortex is used to send a control action to move the robot to the target location. The robot moves to the target location, and the process repeats until a stopping condition is met.
- class robot_brain2.ActionClientcortex(service_name: str, action_type, done_callback=None, feedback_callback=None, mutex=None)[source]
Bases:
objectA simple wrapper for ROS action client to send and receive goals.
- Parameters:
service_name (str) – The name of the action service to connect to.
action_type (Any) – The type of the action message.
done_callback (Optional[Callable[[int, Any]], None]]) – The callback function to be called when the action is done. It takes two arguments: the status code (int) and the result (Any). Defaults to None.
feedback_callback (Optional[Callable[[Any], None]]) – The callback function to be called when there is feedback from the action. It takes one argument: the feedback message (Any). Defaults to None.
mutex (Optional[Lock]) – The mutex to lock when accessing class variables. Defaults to None.
- _is_running
A boolean value indicating whether the action is currently running.
- Type:
bool
- _is_done
A boolean value indicating whether the action is done.
- Type:
bool
- _results
The results of the action.
- Type:
Any
- _service_name
The name of the action service to connect to.
- Type:
str
- _mutex
The mutex to lock when accessing class variables.
- Type:
Lock
- _client
The SimpleActionClient object used to communicate with the action service.
- Type:
SimpleActionClient
- _external_done_cb
The external done callback function.
- Type:
Optional[Callable[[int, Any], None]]
- _external_feedback_cb
The external feedback callback function.
- Type:
Optional[Callable[[Any], None]]
- done_callback_(status, results) None[source]
The internal done callback function.
- Parameters:
status (int) – The status code of the action.
results (Any) – The result message received from the action service.
- feedback_callback_(feedback) None[source]
The internal feedback callback function.
- Parameters:
feedback (Any) – The feedback message received from the action service.
- get_results()[source]
Returns the results of the action if it has completed, otherwise logs an error message.
- Returns:
The results of the action if it has completed.
- is_done() bool[source]
Returns a boolean value indicating whether the action is done.
- Returns:
True if the action is done, False otherwise.
- Return type:
bool
- class robot_brain2.sensory1[source]
Bases:
object- choose_target()[source]
Chooses a target location for the robot to move to based on its current position and reachable locations.
- Returns:
A tuple containing the robot’s current position and its target destination.
- Return type:
tuple
- get_coordinate(location)[source]
Gets the coordinate of a given location.
- Parameters:
location (str) – The location whose coordinate to retrieve.
- Returns:
A tuple containing the x and y coordinates of the specified location.
- Return type:
tuple
- go_to_recharge(robot_location)[source]
Moves the robot to the charging room for recharge.
Uses the client.manipulation.replace_objectprop_b2_ind method to update the isIn property of the robot to the charging room, and then synchronizes the changes with the buffered reasoner.
- Parameters:
robot_location – The current location of the robot.
- Returns:
None
- list_formatter(old_location, start, end)[source]
Formats a list of locations by extracting the substring between the start and end characters.
- Parameters:
old_location (list) – A list of strings to be formatted.
start (str) – The starting character of the substring to be extracted.
end (str) – The ending character of the substring to be extracted.
- Returns:
A list of formatted strings.
- Return type:
list
- location_acquire(location)[source]
Acquires information about the robot’s current location, reachable locations, corridors, or urgent rooms.
- Parameters:
location (str) – A string indicating the type of location information to acquire.
- Returns:
A list of locations meeting the specified criteria.
- Return type:
list
- move_location(target, current_position)[source]
Moves the robot to a new location.
- Publishes the target and current position to their respective topics, updates the robot’s location
in the knowledge base, and synchronizes the changes with the buffered reasoner.
- Parameters:
target – The target location for the robot.
current_position – The current position of the robot.
- Returns:
None
- class robot_brain2.sensory2[source]
Bases:
objectA class for managing sensor data and robot state.
- battery_callback_(msg: Bool) None[source]
Callback function for the anm.TOPIC_BATTERY_LOW topic.
Updates the _battery_low attribute with the received message data.
- Parameters:
msg – A ROS Bool message containing the battery status.
- Returns:
None
- init_robot_pose(point) None[source]
Initializes the robot’s position using a ROS service call.
- Parameters:
point – A geometry_msgs.Point message containing the initial robot position.
- Returns:
None