Merge lp:~shadowrobot/sr-ros-interface-ethercat/Feature_update_controller_params into lp:sr-ros-interface-ethercat

Proposed by Toni Oliver
Status: Merged
Approved by: Toni Oliver
Approved revision: 564
Merged at revision: 564
Proposed branch: lp:~shadowrobot/sr-ros-interface-ethercat/Feature_update_controller_params
Merge into: lp:sr-ros-interface-ethercat
Diff against target: 138 lines (+87/-3)
3 files modified
sr_robot_lib/include/sr_robot_lib/sr_hand_lib.hpp (+25/-0)
sr_robot_lib/src/sr_hand_lib.cpp (+61/-2)
sr_robot_lib/src/sr_robot_lib.cpp (+1/-1)
To merge this branch: bzr merge lp:~shadowrobot/sr-ros-interface-ethercat/Feature_update_controller_params
Reviewer Review Type Date Requested Status
markpitchless Pending
Review via email: mp+133457@code.launchpad.net

Commit message

Update params in param server when changing controller parameters.

Description of the change

Update params in param server when changing controller parameters.

To post a comment you must log in.
Revision history for this message
markpitchless (markpitchless) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'sr_robot_lib/include/sr_robot_lib/sr_hand_lib.hpp'
--- sr_robot_lib/include/sr_robot_lib/sr_hand_lib.hpp 2012-08-20 09:38:26 +0000
+++ sr_robot_lib/include/sr_robot_lib/sr_hand_lib.hpp 2012-11-08 11:55:23 +0000
@@ -100,6 +100,31 @@
100 std::vector<shadow_joints::JointToSensor> joint_to_sensors,100 std::vector<shadow_joints::JointToSensor> joint_to_sensors,
101 std::vector<sr_actuator::SrActuator*> actuators);101 std::vector<sr_actuator::SrActuator*> actuators);
102102
103 /**
104 * Updates the parameter values for the force control in the Parameter Server
105 *
106 * @param joint_name The name of the joint.
107 * @param max_pwm The max pwm the motor will apply
108 * @param sg_left Strain gauge left
109 * @param sg_right Strain gauge right
110 * @param f The feedforward term (directly adds f*error to the output of the PID)
111 * @param p The p value.
112 * @param i the i value.
113 * @param d the d value.
114 * @param imax the imax value.
115 * @param deadband the deadband on the force.
116 * @param sign can be 0 or 1 depending on the way the motor is plugged in.
117 */
118 void update_force_control_in_param_server(std::string joint_name, int max_pwm, int sg_left, int sg_right, int f, int p,
119 int i, int d, int imax, int deadband, int sign);
120
121 /**
122 * Finds the joint name for a certain motor index
123 *
124 * @param motor_index The integer motor index
125 */
126 std::string find_joint_name(int motor_index);
127
103 private:128 private:
104 ros::NodeHandle nodehandle_;129 ros::NodeHandle nodehandle_;
105130
106131
=== modified file 'sr_robot_lib/src/sr_hand_lib.cpp'
--- sr_robot_lib/src/sr_hand_lib.cpp 2012-08-20 09:38:26 +0000
+++ sr_robot_lib/src/sr_hand_lib.cpp 2012-11-08 11:55:23 +0000
@@ -283,10 +283,10 @@
283 full_param << "/" << act_name << "/pid/max_pwm";283 full_param << "/" << act_name << "/pid/max_pwm";
284 nodehandle_.param<int>(full_param.str(), max_pwm, 0);284 nodehandle_.param<int>(full_param.str(), max_pwm, 0);
285 full_param.str("");285 full_param.str("");
286 full_param << "/" << act_name << "/pid/sg_left";286 full_param << "/" << act_name << "/pid/sgleftref";
287 nodehandle_.param<int>(full_param.str(), sg_left, 0);287 nodehandle_.param<int>(full_param.str(), sg_left, 0);
288 full_param.str("");288 full_param.str("");
289 full_param << "/" << act_name << "/pid/sg_right";289 full_param << "/" << act_name << "/pid/sgrightref";
290 nodehandle_.param<int>(full_param.str(), sg_right, 0);290 nodehandle_.param<int>(full_param.str(), sg_right, 0);
291 full_param.str("");291 full_param.str("");
292 full_param << "/" << act_name << "/pid/deadband";292 full_param << "/" << act_name << "/pid/deadband";
@@ -432,6 +432,10 @@
432 generate_force_control_config( motor_index, request.maxpwm, request.sgleftref,432 generate_force_control_config( motor_index, request.maxpwm, request.sgleftref,
433 request.sgrightref, request.f, request.p, request.i,433 request.sgrightref, request.f, request.p, request.i,
434 request.d, request.imax, request.deadband, request.sign );434 request.d, request.imax, request.deadband, request.sign );
435
436 update_force_control_in_param_server( find_joint_name(motor_index), request.maxpwm, request.sgleftref,
437 request.sgrightref, request.f, request.p, request.i,
438 request.d, request.imax, request.deadband, request.sign);
435 response.configured = true;439 response.configured = true;
436440
437 //Reinitialize motors information441 //Reinitialize motors information
@@ -440,6 +444,61 @@
440 return true;444 return true;
441 }445 }
442446
447 std::string SrHandLib::find_joint_name(int motor_index)
448 {
449 for( boost::ptr_vector<shadow_joints::Joint>::iterator joint = joints_vector.begin();
450 joint != joints_vector.end(); ++joint )
451 {
452 if( !boost::is_null(joint) ) // check for validity
453 {
454 if(joint->motor->motor_id == motor_index)
455 return joint->joint_name;
456 }
457 }
458 ROS_ERROR("Could not find joint name for motor index: %d", motor_index);
459 return "";
460 }
461
462 void SrHandLib::update_force_control_in_param_server(std::string joint_name, int max_pwm, int sg_left, int sg_right, int f, int p,
463 int i, int d, int imax, int deadband, int sign)
464 {
465 if(joint_name != "")
466 {
467 std::stringstream full_param;
468 std::string act_name = boost::to_lower_copy(joint_name);
469
470 full_param << "/" << act_name << "/pid/f";
471 nodehandle_.setParam(full_param.str(), f);
472 full_param.str("");
473 full_param << "/" << act_name << "/pid/p";
474 nodehandle_.setParam(full_param.str(), p);
475 full_param.str("");
476 full_param << "/" << act_name << "/pid/i";
477 nodehandle_.setParam(full_param.str(), i);
478 full_param.str("");
479 full_param << "/" << act_name << "/pid/d";
480 nodehandle_.setParam(full_param.str(), d);
481 full_param.str("");
482 full_param << "/" << act_name << "/pid/imax";
483 nodehandle_.setParam(full_param.str(), imax);
484 full_param.str("");
485 full_param << "/" << act_name << "/pid/max_pwm";
486 nodehandle_.setParam(full_param.str(), max_pwm);
487 full_param.str("");
488 full_param << "/" << act_name << "/pid/sgleftref";
489 nodehandle_.setParam(full_param.str(), sg_left);
490 full_param.str("");
491 full_param << "/" << act_name << "/pid/sgrightref";
492 nodehandle_.setParam(full_param.str(), sg_right);
493 full_param.str("");
494 full_param << "/" << act_name << "/pid/deadband";
495 nodehandle_.setParam(full_param.str(), deadband);
496 full_param.str("");
497 full_param << "/" << act_name << "/pid/sign";
498 nodehandle_.setParam(full_param.str(), sign);
499 }
500 }
501
443502
444 std::vector<shadow_joints::JointToSensor> SrHandLib::read_joint_to_sensor_mapping()503 std::vector<shadow_joints::JointToSensor> SrHandLib::read_joint_to_sensor_mapping()
445 {504 {
446505
=== modified file 'sr_robot_lib/src/sr_robot_lib.cpp'
--- sr_robot_lib/src/sr_robot_lib.cpp 2012-10-29 14:18:42 +0000
+++ sr_robot_lib/src/sr_robot_lib.cpp 2012-11-08 11:55:23 +0000
@@ -934,7 +934,7 @@
934 int i, int d, int imax, int deadband, int sign)934 int i, int d, int imax, int deadband, int sign)
935 {935 {
936 ROS_INFO_STREAM(936 ROS_INFO_STREAM(
937 "Setting new pid values for motor" << motor_index << ": max_pwm="<< max_pwm <<" sg_left=" << sg_left << " sg_right=" << sg_right << " f=" << f << " p=" << p << " i=" << i << " d="<< d << " imax=" << imax << " deadband="<< deadband << " sign=" << sign);937 "Setting new pid values for motor" << motor_index << ": max_pwm="<< max_pwm <<" sgleftref=" << sg_left << " sgrightref=" << sg_right << " f=" << f << " p=" << p << " i=" << i << " d="<< d << " imax=" << imax << " deadband="<< deadband << " sign=" << sign);
938938
939 //the vector is of the size of the TO_MOTOR_DATA_TYPE enum.939 //the vector is of the size of the TO_MOTOR_DATA_TYPE enum.
940 //the value of the element at a given index is the value940 //the value of the element at a given index is the value

Subscribers

People subscribed via source and target branches

to all changes: