Skip to content
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

Open
wants to merge 39 commits into
base: dev
Choose a base branch
from
Open

Autodocking #2

wants to merge 39 commits into from

Conversation

tul1
Copy link

@tul1 tul1 commented Jul 26, 2018

Autodocking routine: when the battery of Leonardo is running low, Leonardo have to go docking.

@tul1 tul1 self-assigned this Jul 26, 2018
@tul1 tul1 requested review from julianmateu and ernestmc July 26, 2018 18:37
@@ -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")
Copy link
Contributor

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

@tul1
Copy link
Author

tul1 commented Jul 27, 2018

@julianmateu the code is ready for a review.

Copy link
Contributor

@julianmateu julianmateu left a 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
Copy link
Contributor

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?

Copy link
Contributor

@ernestmc ernestmc Jul 30, 2018

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'
Copy link
Contributor

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


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra line

rospy.spin()



Copy link
Contributor

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
Copy link
Contributor

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).

Copy link
Author

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
Copy link
Contributor

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.

@tul1
Copy link
Author

tul1 commented Jul 30, 2018

@ernestmc I'd added the autodocking routine to a package. Would you give a look of what I've done?

@tul1
Copy link
Author

tul1 commented Jul 30, 2018

@ernestmc I could be able to build the whole project with catkin_make as you can see in the screenshot beneath:

image

However, I cannot run the auto_docking with rosrun, it doesn't even show this package as an option when I press tab. Running rosrun auto_docking I get the following error:

Usage: rosrun [--prefix cmd] [--debug] PACKAGE EXECUTABLE [ARGS]
  rosrun will locate PACKAGE and try to find
  an executable named EXECUTABLE in the PACKAGE tree.
  If it finds it, it will run it with ARGS.

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 :-)

@julianmateu
Copy link
Contributor

@tul1 did you source the setup.sh file?

@tul1
Copy link
Author

tul1 commented Jul 30, 2018

Hey @julianmateu ! Yes, I did. Maybe the problem wasn't the package but the python script. I'm getting the following error when running: rosrun auto_docking auto_docking_client.py

[rosrun] Couldn't find executable named auto_docking_client.py below /home/tul1/Desktop/proyectos/leonardo_turtlebot/src/auto_docking
[rosrun] Found the following, but they're either not files,
[rosrun] or not executable:
[rosrun]   /home/tul1/Desktop/proyectos/leonardo_turtlebot/src/auto_docking/scripts/auto_docking_client.py

(the autocomplete tab just works until auto_docking)

Copy link
Contributor

@ernestmc ernestmc left a 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.

@@ -0,0 +1,27 @@
<package>
<name>auto_docking</name>
Copy link
Contributor

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.

<version>0.1.103</version>

<description>
The auto_docking package
Copy link
Contributor

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.

<buildtool_depend>catkin</buildtool_depend>
<build_depend>kobuki_msgs</build_depend>
<build_depend>actionlib_msgs</build_depend>
<build_depend>diagnostic_msgs</build_depend>
Copy link
Contributor

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.

Copy link
Author

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
Copy link
Contributor

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')
Copy link
Contributor

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)
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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()
Copy link
Contributor

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?

Copy link
Author

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
Copy link
Contributor

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?

Copy link
Author

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.

@tul1
Copy link
Author

tul1 commented Jul 30, 2018

@julianmateu We solved the problem with @ernestmc just changing permissions of the python script auto_docking_client.py to be executable.

@tul1
Copy link
Author

tul1 commented Jul 31, 2018

@ernestmc trying to set argument from the launch file I've gotten the following error:

ERROR: cannot launch node of type [leonardo_battery_guard/dock_drive_client_py]: can't locate node [dock_drive_client_py] in package [leonardo_battery_guard]

would you have any idea where is this coming from?
I've just pushed the launch file.

@tul1
Copy link
Author

tul1 commented Jul 31, 2018

@ernestmc @julianmateu I'm ready for a new review!

PROGRAMS
scripts/battery_guard.py
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)
Copy link
Contributor

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 @@

Copy link
Contributor

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
Copy link
Contributor

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?

Copy link
Author

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.

@tul1
Copy link
Author

tul1 commented Aug 1, 2018

@julianmateu @ernestmc I added a navigation action client to the node to send Leonardo close to the dock station before it starts autodocking.
I tried the code in Leonardo and in the turtlebot gazebo simulation but I could make it work and no error were printed. Tomorrow I'll continue testing different alternatives but I think that by this point the code I pushed is ready for a new review.
I added some TODO comments in the code, please let me know what do you think about them.

@tul1
Copy link
Author

tul1 commented Aug 9, 2018

@julianmateu @ernestmc the code is ready for a new review.
It's working and it has been tested satisfactory twice on Leonardo. It's going to need further field tests to adjust details.

@tul1
Copy link
Author

tul1 commented Aug 9, 2018

@julianmateu FYI with @ernestmc we handled to correct the last code errors and we were able to autodock Leonardo.

Copy link
Author

@tul1 tul1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changes done

@tul1
Copy link
Author

tul1 commented Aug 15, 2018

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 /run_autodocking and to call it the following line should be invoked in the terminal: rosservice call /run_autodocking "{}"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants