-
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
Conversation
@@ -249,6 +249,8 @@ def __init__(self): | |||
|
|||
# Battery info | |||
self._batt_acpi_path = rospy.get_param('~acpi_path', "/sys/class/power_supply/BAT0") | |||
# self._batt_acpi_path = rospy.get_param('~acpi_path', "/home/tul1/Desktop/MOCK_BAT") |
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.
Please remove, this file should not be changed.
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.
done!
@julianmateu the code is ready for a review. |
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.
Well done @tul1! I left some comments. There are some of them that apply for future work (you could address them in a different CL). The logging and style ones should be addressed before merging this one.
elif status == GoalStatus.RECALLED : state='RECALLED' | ||
elif status == GoalStatus.LOST : state='LOST' | ||
# Print state of action server | ||
print 'Result - [ActionServer: ' + state + ']: ' + result.text |
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.
ROS provides a rosout
topic for logging information from nodes. I think that is the preferred method, right @ernestmc?
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.
Yes, you can use
rospy.logdebug("Whatever you want to log")
self._go_docking = False | ||
|
||
def _doneCb(self, status, result): | ||
if status == GoalStatus.PENDING : state='PENDING' |
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.
Style: alignment is inconsistent in these lines.
rospy.on_shutdown(self._client.cancel_goal) | ||
self._go_docking = False | ||
|
||
|
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.
Extra line
rospy.spin() | ||
|
||
|
||
|
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.
Extra line. See PEP-8:
Surround top-level function and class definitions with two blank lines.
Method definitions inside a class are surrounded by a single blank line.
self._ros_node = rospy.init_node('dock_drive_client_py', anonymous=True) | ||
self._client = actionlib.SimpleActionClient('dock_drive_action', AutoDockingAction) | ||
self._diagnostic_agg_sub = rospy.Subscriber("/diagnostics_agg", DiagnosticArray, self._listen_batteries) | ||
self._go_docking = False |
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.
For a first version this might be OK, but I would suggest to use a more descriptive name, and make sure the behavior is the intended one. With the current implementation the robot will go docking only once and never dock again.
For example, here this variable will be set to true when the docking action has started, so a more descriptive name would be _docking_action_started
or _docking_in_progress
. In that case, you would need to make sure that it is set to false again once the action finishes. But you would also need another flag that tells you if the robot is already docked and charging, so that you don't trigger the auto docking in the case it is charging (you could read the battery state for that).
So the logic will be something like:
If not charging and not docking_in_progress then dock (if the battery level is low).
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.
I forgot to change the state of _go_docking
when is called _doneCb
. Changing that state there I think the Leonardo is going to behave as expected.
|
||
|
||
class AutoDocking: | ||
BATTERY_THRESHOLD = 4 |
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.
This is OK for now, but it would be good to make it a parameter configurable from the launch file.
@ernestmc I'd added the autodocking routine to a package. Would you give a look of what I've done? |
@ernestmc I could be able to build the whole project with However, I cannot run the
So the package isn't in the namespace. I pushed the code so you can have a look @ernestmc . Let me know if you find anything wrong that could cause this problem. Thanks :-) |
@tul1 did you source the |
Hey @julianmateu ! Yes, I did. Maybe the problem wasn't the package but the python script. I'm getting the following error when running:
(the autocomplete |
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.
I left some comments. Please address them and let me know if you need any help.
src/auto_docking/package.xml
Outdated
@@ -0,0 +1,27 @@ | |||
<package> | |||
<name>auto_docking</name> |
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.
The name of the package seems too generic. I think what we are doing is monitoring the battery state and executing actions, maybe it can be something like leonardo_battery_guard
or something similar.
src/auto_docking/package.xml
Outdated
<version>0.1.103</version> | ||
|
||
<description> | ||
The auto_docking package |
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.
Please add a better description of what the package does.
src/auto_docking/package.xml
Outdated
<buildtool_depend>catkin</buildtool_depend> | ||
<build_depend>kobuki_msgs</build_depend> | ||
<build_depend>actionlib_msgs</build_depend> | ||
<build_depend>diagnostic_msgs</build_depend> |
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.
Since this is a python package and nothing gets compiled, the build_depends
are not really needed.
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.
I don't really know why but apparently these build deps are necessary to build the package. The laptop monitor package also includes them.
@@ -0,0 +1,69 @@ | |||
#!/usr/bin/env python |
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.
Again, a better and more descriptive name other than auto_docking_client
which is too generic.
@@ -0,0 +1,69 @@ | |||
#!/usr/bin/env python | |||
|
|||
import roslib; roslib.load_manifest('kobuki_auto_docking') |
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.
This is not needed. Please remove the line. (Also why are you using ;
this is not C++!!)
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) | ||
kuboki_battery_percentage = float(filter(lambda x: x.key == "Percent", batteries_values[1])[0].value) |
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.
kuboki
--> kobuki
|
||
|
||
class AutoDocking: | ||
BATTERY_THRESHOLD = 4 |
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.
Use ros parameters for these values.
|
||
if self._go_docking is False: | ||
if kuboki_battery_percentage < self.BATTERY_THRESHOLD or laptop_battery_percentage < self.BATTERY_THRESHOLD: | ||
print kuboki_battery_percentage |
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.
Remove debugging code or use ros logging
if self._go_docking is False: | ||
if kuboki_battery_percentage < self.BATTERY_THRESHOLD or laptop_battery_percentage < self.BATTERY_THRESHOLD: | ||
print kuboki_battery_percentage | ||
self._dock_drive_client() |
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.
It seems reasonable that this method is called do_docking
or go_dock
since it invokes the action, doesn't it?
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.
It does!
if kuboki_battery_percentage < self.BATTERY_THRESHOLD or laptop_battery_percentage < self.BATTERY_THRESHOLD: | ||
print kuboki_battery_percentage | ||
self._dock_drive_client() | ||
self._go_docking = True |
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.
I understand correctly this flag is actually telling if the robot is in auto docking mode, right? Shouldn't it then be called something like docking
, doing_docking
, docking_invoked
or something like that?
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.
I like doing_docking
. I'm going to change it.
@julianmateu We solved the problem with @ernestmc just changing permissions of the python script auto_docking_client.py to be executable. |
@ernestmc trying to set argument from the launch file I've gotten the following error:
would you have any idea where is this coming from? |
@ernestmc @julianmateu I'm ready for a new review! |
PROGRAMS | ||
scripts/battery_guard.py | ||
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} | ||
) |
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.
@@ -0,0 +1,6 @@ | |||
|
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.
Extra line.
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Good point @julianmateu ! I added some logic to prevent that case.
@julianmateu @ernestmc I added a navigation action client to the node to send Leonardo close to the dock station before it starts autodocking. |
@julianmateu @ernestmc the code is ready for a new review. |
@julianmateu FYI with @ernestmc we handled to correct the last code errors and we were able to autodock Leonardo. |
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.
changes done
This code here is ready to be reviewed, it's "working" and it has been tested several times in Leonardo. I quoted "working" because the code or system is going to need further adjustments. For instance, the biggest issue we have lies in the autodocking routine. In fact, Leonardo rarely docks, it just approaches the dock and hits the base. Another possible issue is that we think that the routine is being triggered in condition where it shouldn't. For example, while the turtlebot is charging. We couldn't verify this but it happened twice that Leonardo was running the autodocking routine after being docked. Also we talked offline with @ernestmc about some changes that occurred from master to dev, and before merging this branch the file system should be reorganized. Last comment, in order to run the routine for debugging proposes I added a service named |
Autodocking routine: when the battery of Leonardo is running low, Leonardo have to go docking.