Skip to content

Commit bd6ea7b

Browse files
Pass time since last call to method one_iteration.
1 parent c00d402 commit bd6ea7b

File tree

6 files changed

+18
-12
lines changed

6 files changed

+18
-12
lines changed

src/roscontrol-sot-controller.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,7 @@ void RCSotController::readControl(
955955
}
956956
}
957957

958-
void RCSotController::one_iteration() {
958+
void RCSotController::one_iteration(const ros::Duration &period) {
959959
sotComputing_ = true;
960960
// Chrono start
961961
RcSotLog_.start_it();
@@ -975,7 +975,7 @@ void RCSotController::one_iteration() {
975975
throw e;
976976
}
977977
try {
978-
sotController_->getControl(controlValues_copy_);
978+
sotController_->getControl(controlValues_copy_, period.toSec());
979979
} catch (std::exception &e) {
980980
std::cerr << "Failure happened during one_iteration(): "
981981
<< "when calling getControl " << std::endl;
@@ -1115,15 +1115,15 @@ void RCSotController::update(const ros::Time &, const ros::Duration &period) {
11151115
// If subsampling is equal to 1, i.e. no subsampling, evaluate
11161116
// control graph in this thread
11171117
if (subSampling_ == 1) {
1118-
one_iteration();
1118+
one_iteration(period);
11191119
readControl(controlValues_);
11201120
} else {
11211121
if (step_ == 0) {
11221122
// If previous graph evaluation is not finished, do not start a new
11231123
// one.
11241124
if (!sotComputing_) {
11251125
io_service_.post(
1126-
boost::bind(&RCSotController::one_iteration, this));
1126+
boost::bind(&RCSotController::one_iteration, this, period));
11271127
} else {
11281128
ROS_INFO_STREAM("Sot computation not finished yet.");
11291129
}

src/roscontrol-sot-controller.hh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,9 @@ class RCSotController : public lci::ControllerBase, SotLoaderBasic {
279279
void localStandbyPositionControlMode();
280280

281281
///@}
282-
/// Extract control values to send to the simulator.
282+
/// Extract control values to send to the motors.
283+
/// \param controlValues map string to vector of double. The function will fill in
284+
/// controlValues["control"]
283285
void readControl(std::map<std::string, dgs::ControlValues> &controlValues);
284286

285287
/// Map of sensor readings
@@ -298,7 +300,8 @@ class RCSotController : public lci::ControllerBase, SotLoaderBasic {
298300
std::vector<double> command_;
299301

300302
/// One iteration: read sensor, compute the control law, apply control.
301-
void one_iteration();
303+
/// \param period time since last call. Useful when realtime is not enforced correctly.
304+
void one_iteration(const ros::Duration &period);
302305

303306
/// Read URDF model from /robot_description parameter.
304307
bool readUrdf(ros::NodeHandle &robot_nh);

tests/sot-test-controller.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ void SoTTestController::cleanupSetSensors(
8989
}
9090

9191
void SoTTestController::getControl(
92-
map<string, dgsot::ControlValues> &controlOut) {
92+
map<string, dgsot::ControlValues> &controlOut, const double& period) {
9393
try {
9494
sotDEBUG(25) << __FILE__ << __FUNCTION__ << "(#" << __LINE__ << ")" << endl;
95-
device_->getControl(controlOut);
95+
device_->getControl(controlOut, period);
9696
sotDEBUG(25) << __FILE__ << __FUNCTION__ << "(#" << __LINE__ << ")" << endl;
9797
} catch (dynamicgraph::sot::ExceptionAbstract &err) {
9898
std::cout << __FILE__ << " " << __FUNCTION__ << " (" << __LINE__ << ") "

tests/sot-test-controller.hh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ class SoTTestController : public dgsot::AbstractSotExternalInterface {
3838

3939
void cleanupSetSensors(std::map<std::string, dgsot::SensorValues> &sensorsIn);
4040

41-
void getControl(std::map<std::string, dgsot::ControlValues> &anglesOut);
41+
void getControl(std::map<std::string, dgsot::ControlValues> &anglesOut,
42+
const double& period);
4243

4344
void setNoIntegration(void);
4445
void setSecondOrderIntegration(void);

tests/sot-test-device.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,14 +296,15 @@ void SoTTestDevice::cleanupSetSensors(
296296
setSensors(SensorsIn);
297297
}
298298

299-
void SoTTestDevice::getControl(map<string, dgsot::ControlValues> &controlOut) {
299+
void SoTTestDevice::getControl(map<string, dgsot::ControlValues> &controlOut,
300+
const double& period) {
300301
ODEBUG5FULL("start");
301302
sotDEBUGIN(25);
302303
vector<double> anglesOut;
303304
anglesOut.resize(state_.size());
304305

305306
// Integrate control
306-
increment(timestep_);
307+
increment(period);
307308
sotDEBUG(25) << "state = " << state_ << std::endl;
308309
sotDEBUG(25) << "diff = "
309310
<< ((previousState_.size() == state_.size())

tests/sot-test-device.hh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ class SoTTestDevice : public dgsot::Device {
4141

4242
void cleanupSetSensors(std::map<std::string, dgsot::SensorValues> &sensorsIn);
4343

44-
void getControl(std::map<std::string, dgsot::ControlValues> &anglesOut);
44+
void getControl(std::map<std::string, dgsot::ControlValues> &anglesOut,
45+
const double& period);
4546

4647
void timeStep(double ts) { timestep_ = ts; }
4748

0 commit comments

Comments
 (0)