-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Autodocking #2
base: dev
Are you sure you want to change the base?
Autodocking #2
Changes from 19 commits
31598a5
7181fc6
f6379e9
487aca9
032f3a1
eccecd3
0d9f9e1
c1994e0
cc8e757
a4a1b19
ca5d10a
edeb3f1
dc46de0
dcbed7a
cc7af16
c49b501
8289c4d
34906ee
0502ea4
638e13f
382597a
1c24ba1
99e0545
21fe82d
a019437
d561a05
5b95691
69f2936
786b0c9
3e79fbe
54e3da0
2144eec
53c8dab
8d8609f
d44d334
6eb0b03
9fcc848
1fbb736
f0fa260
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
cmake_minimum_required(VERSION 2.8.3) | ||
project(leonardo_battery_guard) | ||
|
||
find_package(catkin REQUIRED COMPONENTS kobuki_msgs actionlib_msgs diagnostic_msgs) | ||
|
||
catkin_package(CATKIN_DEPENDS kobuki_msgs actionlib_msgs diagnostic_msgs) | ||
|
||
catkin_install_python( | ||
PROGRAMS | ||
scripts/battery_guard.py | ||
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} | ||
) | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extra line. |
||
<launch> | ||
<node name="dock_drive_client" pkg="leonardo_battery_guard" type="battery_guard.py" clear_params="true" output="screen"> | ||
<param name="battery_threshold" value="10" /> | ||
</node> | ||
</launch> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<package> | ||
<name>leonardo_battery_guard</name> | ||
<version>0.1.103</version> | ||
|
||
<description> | ||
Package that watch Leonardo's battery and dock it if necessary. | ||
</description> | ||
<maintainer email="[email protected]">Ernesto Corbellini</maintainer> | ||
<maintainer email="[email protected]">Julian Mateu</maintainer> | ||
<maintainer email="[email protected]">Patricio Tula</maintainer> | ||
<author>Patricio Tula</author> | ||
<license>BSD</license> | ||
|
||
<buildtool_depend>catkin</buildtool_depend> | ||
<build_depend>kobuki_msgs</build_depend> | ||
<build_depend>actionlib_msgs</build_depend> | ||
<build_depend>diagnostic_msgs</build_depend> | ||
|
||
<run_depend>actionlib</run_depend> | ||
<run_depend>roslib</run_depend> | ||
<run_depend>rospy</run_depend> | ||
|
||
<run_depend>kobuki_msgs</run_depend> | ||
<run_depend>actionlib_msgs</run_depend> | ||
<run_depend>diagnostic_msgs</run_depend> | ||
|
||
</package> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#!/usr/bin/env python | ||
# | ||
# Software License Agreement (BSD License) | ||
# | ||
# Description: This code creates a ros node in charge of watching the turtlebot Leonardo's batteries | ||
# and autodocking it in it's charging station if the battery level is too low. This code has been influenced by the kobuki | ||
# autodocking routine form https://github.com/yujinrobot/kobuki/blob/devel/kobuki_auto_docking/scripts/DockDriveActionClient.py | ||
# | ||
# author: Patricio Tula | ||
# reviewed by: Ernesto Corbellini / Julian Mateu | ||
|
||
import rospy | ||
|
||
import actionlib | ||
from kobuki_msgs.msg import AutoDockingAction, AutoDockingGoal | ||
from actionlib_msgs.msg import GoalStatus | ||
from diagnostic_msgs.msg import DiagnosticArray | ||
|
||
|
||
class AutoDocking(object): | ||
def __init__(self): | ||
self._ros_node = rospy.init_node("dock_drive_client", anonymous=True) | ||
self._client = actionlib.SimpleActionClient("dock_drive_action", AutoDockingAction) | ||
self._diagnostic_agg_sub = rospy.Subscriber("/diagnostics_agg", DiagnosticArray, self._listen_batteries) | ||
self._doing_docking = False | ||
self.BATTERY_THRESHOLD = rospy.get_param("~battery_threshold", 10) | ||
|
||
def _doneCb(self, status, result): | ||
"""Callback that prints the action goal status and change the state of _doing_docking attribute. | ||
This function is called when the action goal is reached.""" | ||
if status == GoalStatus.PENDING: state="PENDING" | ||
elif status == GoalStatus.ACTIVE: state="ACTIVE" | ||
elif status == GoalStatus.PREEMPTED: state="PREEMPTED" | ||
elif status == GoalStatus.SUCCEEDED: state="SUCCEEDED" | ||
elif status == GoalStatus.ABORTED: state="ABORTED" | ||
elif status == GoalStatus.REJECTED: state="REJECTED" | ||
elif status == GoalStatus.PREEMPTING: state="PREEMPTING" | ||
elif status == GoalStatus.RECALLING: state="RECALLING" | ||
elif status == GoalStatus.RECALLED: state="RECALLED" | ||
elif status == GoalStatus.LOST: state="LOST" | ||
rospy.logdebug("Result - [ActionServer: " + state + "]: " + result.text) | ||
self._doing_docking = False | ||
|
||
def _feedbackCb(self, feedback): | ||
"""Callback that just prints the action feedback.""" | ||
rospy.logdebug("Feedback: [DockDrive: " + feedback.state + "]: " + feedback.text) | ||
|
||
def _go_dock(self): | ||
"""Runs auto docking routine for a turtlebot.""" | ||
if rospy.is_shutdown(): | ||
return | ||
goal = AutoDockingGoal() | ||
self._client.send_goal(goal, done_cb=self._doneCb, feedback_cb=self._feedbackCb) | ||
rospy.logdebug("Goal: Sent.") | ||
rospy.on_shutdown(self._client.cancel_goal) | ||
self._doing_docking = False | ||
|
||
def _listen_batteries(self, data): | ||
"""Callback that checks the batteries charge and triggers the auto docking routine if the charge is low.""" | ||
batteries_names = ["/Power System/Laptop Battery", "/Power System/Battery"] | ||
batteries_values = [element.values for element in data.status if element.name in batteries_names] | ||
laptop_battery_percentage = float(filter(lambda x: x.key == "Percentage (%)", batteries_values[0])[0].value) | ||
kobuki_battery_percentage = float(filter(lambda x: x.key == "Percent", batteries_values[1])[0].value) | ||
|
||
if self._doing_docking is False: | ||
if kobuki_battery_percentage < self.BATTERY_THRESHOLD or laptop_battery_percentage < self.BATTERY_THRESHOLD: | ||
self._go_dock() | ||
self._doing_docking = True | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens here if the robot is docked and charging but the battery level is below the threshold? Does the docking action get triggered? Have you tested this case? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point @julianmateu ! I added some logic to prevent that case. |
||
|
||
def run(self): | ||
rospy.spin() | ||
|
||
|
||
if __name__ == "__main__": | ||
try: | ||
autodock = AutoDocking() | ||
autodock.run() | ||
except rospy.ROSInterruptException: | ||
rospy.logdebug("program interrupted before completion") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing new line at the end of the file.