Skip to content

Commit 56f167d

Browse files
Merge pull request #39 from florent-lamiraux/devel
Make package more robust.
2 parents 54b3509 + 3a9cb28 commit 56f167d

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

src/log.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,28 +90,35 @@ void Log::record(DataToLog &aDataToLog) {
9090
StoredData_.controls[JointID + lref_] = aDataToLog.controls[JointID];
9191
}
9292
for (unsigned int axis = 0; axis < 3; axis++) {
93-
StoredData_.accelerometer[lrefts_ * 3 + axis] =
94-
aDataToLog.accelerometer[axis];
95-
StoredData_.gyrometer[lrefts_ * 3 + axis] = aDataToLog.gyrometer[axis];
93+
if (StoredData_.accelerometer.size() >= lrefts_ * 3 + 3)
94+
StoredData_.accelerometer[lrefts_ * 3 + axis] =
95+
aDataToLog.accelerometer[axis];
96+
}
97+
for (unsigned int axis = 0; axis < 3; axis++) {
98+
if (StoredData_.gyrometer.size() >= lrefts_ * 3 + 3)
99+
StoredData_.gyrometer[lrefts_ * 3 + axis] = aDataToLog.gyrometer[axis];
96100
}
97101
std::size_t width_pad = 6 * profileLog_.nbForceSensors;
98102

99103
for (unsigned int fsID = 0; fsID < profileLog_.nbForceSensors; fsID++) {
100104
for (unsigned int axis = 0; axis < 6; axis++) {
101-
StoredData_.force_sensors[lrefts_ * width_pad + fsID * 6 + axis] =
102-
aDataToLog.force_sensors[fsID * 6 + axis];
105+
if (StoredData_.force_sensors.size() >
106+
lrefts_ * width_pad + (profileLog_.nbForceSensors - 1) * 6 + 5)
107+
StoredData_.force_sensors[lrefts_ * width_pad + fsID * 6 + axis] =
108+
aDataToLog.force_sensors[fsID * 6 + axis];
103109
}
104110
}
105111

106112
struct timeval current;
107113
gettimeofday(&current, 0);
108114

109-
StoredData_.timestamp[lrefts_] =
110-
((double)current.tv_sec + 0.000001 * (double)current.tv_usec) -
111-
timeorigin_;
112-
113-
StoredData_.duration[lrefts_] = time_stop_it_ - time_start_it_;
115+
if (StoredData_.timestamp.size() > lrefts_) {
116+
StoredData_.timestamp[lrefts_] =
117+
((double)current.tv_sec + 0.000001 * (double)current.tv_usec) -
118+
timeorigin_;
114119

120+
StoredData_.duration[lrefts_] = time_stop_it_ - time_start_it_;
121+
}
115122
lref_ += profileLog_.nbDofs;
116123
lrefts_++;
117124
if (lref_ >= profileLog_.nbDofs * profileLog_.length) {

src/roscontrol-sot-controller.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,8 +556,11 @@ bool RCSotController::readParamsJointNames(ros::NodeHandle &robot_nh) {
556556
return false;
557557
}
558558
}
559-
} else
559+
} else {
560+
ROS_ERROR(
561+
"ROS parameter \"/sot_controller/joint_names\" shoud be defined.");
560562
return false;
563+
}
561564

562565
/// Deduce from this the degree of freedom number.
563566
nbDofs_ = joints_name_.size();
@@ -938,7 +941,8 @@ void RCSotController::readControl(
938941
std::string &lmapRC2Sot = it_mapRC2Sot->second;
939942
command_ = controlValues[lmapRC2Sot].getValues();
940943
ODEBUG4("angleControl_.size() = " << command_.size());
941-
for (unsigned int i = 0; i < command_.size(); ++i) {
944+
for (unsigned int i = 0; i < std::min(command_.size(), joints_.size());
945+
++i) {
942946
joints_[joints_name_[i]].joint.setCommand(command_[i]);
943947
DataOneIter_.controls[i] = command_[i];
944948
}

0 commit comments

Comments
 (0)