@@ -70,12 +70,16 @@ void ControlPDMotorControlData::read_from_xmlrpc_value(
70
70
}
71
71
72
72
RCSotController::RCSotController ()
73
- : // Store 32 DoFs for 5 minutes (1 Khz: 5*60*1000)
74
- // -> 124 Mo of data.
75
- type_name_ (" RCSotController" ), simulation_mode_(false ),
76
- subSampling_ (0 ), step_(0 ), verbosity_level_(0 ), io_service_(),
77
- io_work_ (io_service_), sotComputing_(false )
78
- {
73
+ : // Store 32 DoFs for 5 minutes (1 Khz: 5*60*1000)
74
+ // -> 124 Mo of data.
75
+ type_name_ (" RCSotController" ),
76
+ simulation_mode_ (false ),
77
+ subSampling_ (0 ),
78
+ step_ (0 ),
79
+ verbosity_level_ (0 ),
80
+ io_service_ (),
81
+ io_work_ (io_service_),
82
+ sotComputing_ (false ) {
79
83
RESETDEBUG4 ();
80
84
}
81
85
@@ -935,7 +939,7 @@ void RCSotController::readControl(
935
939
DataOneIter_.controls [i] = command_[i];
936
940
}
937
941
938
- } else {
942
+ } else {
939
943
ROS_INFO_STREAM (" no control." );
940
944
localStandbyEffortControlMode (ros::Duration (dtRos_));
941
945
localStandbyVelocityControlMode (ros::Duration (dtRos_));
@@ -973,8 +977,8 @@ void RCSotController::one_iteration() {
973
977
}
974
978
975
979
// Wait until last subsampling step to write result in controlValues_
976
- while (step_ != subSampling_ - 1 ){
977
- ros::Duration (.01 * dtRos_).sleep ();
980
+ while (step_ != subSampling_ - 1 ) {
981
+ ros::Duration (.01 * dtRos_).sleep ();
978
982
}
979
983
// mutex
980
984
mutex_.lock ();
@@ -1078,79 +1082,79 @@ void RCSotController::localStandbyPositionControlMode() {
1078
1082
first_time = false ;
1079
1083
}
1080
1084
1081
- void RCSotController::computeSubSampling (const ros::Duration &period)
1082
- {
1083
- if (subSampling_ != 0 ) return ; // already computed
1085
+ void RCSotController::computeSubSampling (const ros::Duration &period) {
1086
+ if (subSampling_ != 0 ) return ; // already computed
1084
1087
dtRos_ = period.toSec ();
1085
- double ratio = dt_/ dtRos_;
1086
- if (fabs (ratio - std::round (ratio)) > 1e-8 ){
1088
+ double ratio = dt_ / dtRos_;
1089
+ if (fabs (ratio - std::round (ratio)) > 1e-8 ) {
1087
1090
std::ostringstream os;
1088
1091
os << " SoT period (" << dt_ << " ) is not a multiple of roscontrol period ("
1089
- << dtRos_ << " ). Modify rosparam /sot_controller/dt to a "
1090
- " multiple of roscontrol period." ;
1092
+ << dtRos_
1093
+ << " ). Modify rosparam /sot_controller/dt to a "
1094
+ " multiple of roscontrol period." ;
1091
1095
throw std::runtime_error (os.str ().c_str ());
1092
1096
}
1093
1097
subSampling_ = static_cast <std::size_t >(std::round (ratio));
1094
1098
// First time method update is called, step_ will turn to 1.
1095
- step_ = subSampling_ -1 ;
1099
+ step_ = subSampling_ - 1 ;
1096
1100
ROS_INFO_STREAM (" Subsampling SoT graph computation by ratio "
1097
- << subSampling_);
1098
- if (subSampling_ != 1 ){
1101
+ << subSampling_);
1102
+ if (subSampling_ != 1 ) {
1099
1103
// create thread in this method instead of in constructor to inherit the
1100
1104
// same priority level.
1101
1105
// If subsampling is equal to one, the control graph is evaluated in the
1102
1106
// same thread.
1103
- thread_pool_.create_thread (boost::bind (&boost::asio::io_service::run,
1104
- &io_service_));
1107
+ thread_pool_.create_thread (
1108
+ boost::bind (&boost::asio::io_service::run, &io_service_));
1105
1109
}
1106
-
1107
1110
}
1108
1111
void RCSotController::update (const ros::Time &, const ros::Duration &period) {
1109
1112
// Do not send any control if the dynamic graph is not started
1110
1113
if (!isDynamicGraphStopped ()) {
1111
1114
// Increment step at beginning of this method since the end time may
1112
1115
// vary a lot.
1113
- ++ step_;
1116
+ ++step_;
1114
1117
if (step_ == subSampling_) step_ = 0 ;
1115
1118
try {
1116
1119
// If subsampling is equal to 1, i.e. no subsampling, evaluate
1117
1120
// control graph in this thread
1118
- if (subSampling_ == 1 ){
1119
- one_iteration ();
1121
+ if (subSampling_ == 1 ) {
1122
+ one_iteration ();
1120
1123
} else {
1121
- if (step_ == 0 ){
1122
- // If previous graph evaluation is not finished, do not start a new
1123
- // one.
1124
- if (!sotComputing_){
1125
- io_service_.post (boost::bind (&RCSotController::one_iteration,this ));
1126
- } else {
1127
- ROS_INFO_STREAM (" Sot computation not finished yet." );
1128
- }
1129
- // protected read control
1130
- mutex_.lock ();
1131
- // / Read the control values
1132
- readControl (controlValues_);
1133
- mutex_.unlock ();
1134
- } else {
1135
- // protected read control
1136
- mutex_.lock ();
1137
- // If the robot is controlled in position, update the reference
1138
- // posture with the latest velocity.
1139
- // Note that the entry "velocity" only exists if the robot is
1140
- // controlled in position.
1141
- if (controlValues_.find (" velocity" ) != controlValues_.end ()){
1142
- std::vector<double > control = controlValues_[" control" ].getValues ();
1143
- const std::vector<double >& velocity = controlValues_[" velocity" ].
1144
- getValues ();
1145
- for (std::size_t i=0 ; i<control.size (); ++i){
1146
- control[i] += dtRos_ * velocity[i];
1147
- }
1148
- controlValues_[" control" ].setValues (control);
1149
- }
1150
- // / Read the control values
1151
- readControl (controlValues_);
1152
- mutex_.unlock ();
1153
- }
1124
+ if (step_ == 0 ) {
1125
+ // If previous graph evaluation is not finished, do not start a new
1126
+ // one.
1127
+ if (!sotComputing_) {
1128
+ io_service_.post (
1129
+ boost::bind (&RCSotController::one_iteration, this ));
1130
+ } else {
1131
+ ROS_INFO_STREAM (" Sot computation not finished yet." );
1132
+ }
1133
+ // protected read control
1134
+ mutex_.lock ();
1135
+ // / Read the control values
1136
+ readControl (controlValues_);
1137
+ mutex_.unlock ();
1138
+ } else {
1139
+ // protected read control
1140
+ mutex_.lock ();
1141
+ // If the robot is controlled in position, update the reference
1142
+ // posture with the latest velocity.
1143
+ // Note that the entry "velocity" only exists if the robot is
1144
+ // controlled in position.
1145
+ if (controlValues_.find (" velocity" ) != controlValues_.end ()) {
1146
+ std::vector<double > control = controlValues_[" control" ].getValues ();
1147
+ const std::vector<double > &velocity =
1148
+ controlValues_[" velocity" ].getValues ();
1149
+ for (std::size_t i = 0 ; i < control.size (); ++i) {
1150
+ control[i] += dtRos_ * velocity[i];
1151
+ }
1152
+ controlValues_[" control" ].setValues (control);
1153
+ }
1154
+ // / Read the control values
1155
+ readControl (controlValues_);
1156
+ mutex_.unlock ();
1157
+ }
1154
1158
}
1155
1159
1156
1160
} catch (std::exception const &exc) {
0 commit comments