-
Notifications
You must be signed in to change notification settings - Fork 23
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
[RFC] [WIP] Add feature to reboot using a service call #19
base: master
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
|
@@ -50,6 +50,9 @@ | |
// ROS control | ||
#include <controller_manager/controller_manager.h> | ||
|
||
// Service to reboot (only for Protocol2) | ||
#include <dynamixel_control_hw/Reboot.h> | ||
|
||
// The hardware interface to dynamixels | ||
#include <dynamixel_control_hw/dynamixel_hardware_interface.hpp> | ||
|
||
|
@@ -88,6 +91,24 @@ namespace dynamixel { | |
// Start timer that will periodically call DynamixelLoop::update | ||
_desired_update_freq = ros::Duration(1 / _loop_hz); | ||
_non_realtime_loop = _nh.createTimer(_desired_update_freq, &DynamixelLoop::update, this); | ||
_service_server = _nh.advertiseService("reboot", &DynamixelLoop::reboot_joints, this); | ||
} | ||
|
||
bool reboot_joints(dynamixel_control_hw::Reboot::Request& req, | ||
dynamixel_control_hw::Reboot::Response& res) | ||
{ | ||
bool all_success = true; | ||
for (const auto& servo_id : req.servos) { | ||
auto id = static_cast<typename hw_int::id_t>(servo_id.id); | ||
|
||
dynamixel_access_mutex.lock(); | ||
auto result = _hardware_interface->reboot_joint(id); | ||
dynamixel_access_mutex.unlock(); | ||
|
||
res.results.push_back(result); | ||
all_success = all_success && result; | ||
} | ||
return all_success; | ||
} | ||
|
||
/** Timed method that reads current hardware's state, runs the controller | ||
|
@@ -117,15 +138,19 @@ namespace dynamixel { | |
|
||
// Input | ||
// get the hardware's state | ||
dynamixel_access_mutex.lock(); | ||
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. I believe that it would be preferable to use trylock (but have little experience in threads) because we would not want the warning messages that are generated when this method takes too much time to execute. |
||
_hardware_interface->read_joints(); | ||
dynamixel_access_mutex.unlock(); | ||
|
||
// Control | ||
// let the controller compute the new command (via the controller manager) | ||
_controller_manager->update(ros::Time::now(), _elapsed_time); | ||
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. Maybe we should not call this method either when the mutex is already locked by the thread doing the reboot. |
||
|
||
// Output | ||
// send the new command to hardware | ||
dynamixel_access_mutex.lock(); | ||
_hardware_interface->write_joints(); | ||
dynamixel_access_mutex.unlock(); | ||
} | ||
|
||
private: | ||
|
@@ -142,6 +167,8 @@ namespace dynamixel { | |
double _loop_hz; | ||
steady_clock::time_point _last_time; | ||
steady_clock::time_point _current_time; | ||
boost::mutex dynamixel_access_mutex; | ||
ros::ServiceServer _service_server; | ||
|
||
/** ROS Controller Manager and Runner | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
uint8 id |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
dynamixel_control_hw/ServoID[] servos | ||
--- | ||
bool[] results |
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 this line and also line 418, I believe that we should use the template parameter
Protocol
.