Skip to content

Commit 4705360

Browse files
author
Peter Fankhauser
committed
Fixing segfaults when rendering end effector trajectories.
1 parent c10cf2a commit 4705360

File tree

5 files changed

+28
-26
lines changed

5 files changed

+28
-26
lines changed

free_gait_core/include/free_gait_core/executor/BatchExecutor.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class BatchExecutor
3232
bool isProcessing();
3333
void cancelProcessing();
3434

35-
StateBatch getStateBatch() const;
35+
const StateBatch& getStateBatch() const;
3636

3737
private:
3838
void processInThread();

free_gait_core/src/executor/BatchExecutor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void BatchExecutor::cancelProcessing()
6060
requestForCancelling_ = true;
6161
}
6262

63-
StateBatch BatchExecutor::getStateBatch() const
63+
const StateBatch& BatchExecutor::getStateBatch() const
6464
{
6565
if (isProcessing_) throw std::runtime_error("Batch executor error: Cannot access state during processing.");
6666
return stateBatch_;

free_gait_rviz_plugin/src/FreeGaitPreviewDisplay.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,17 +254,17 @@ void FreeGaitPreviewDisplay::jumpToTime()
254254
void FreeGaitPreviewDisplay::newGoalAvailable()
255255
{
256256
ROS_DEBUG("FreeGaitPreviewDisplay::newGoalAvailable: New preview available.");
257+
257258
// Auto-enable visuals.
259+
ROS_DEBUG("FreeGaitPreviewDisplay::newGoalAvailable: Drawing visualizations.");
260+
visual_->setStateBatch(playback_.getStateBatch());
258261
if (autoEnableVisualsProperty_->getBool()) {
259262
setEnabledRobotModel(true);
260263
visualsTree_->setBool(true);
264+
} else {
265+
visual_->showEnabled();
261266
}
262267

263-
// Visuals.
264-
ROS_DEBUG("FreeGaitPreviewDisplay::newGoalAvailable: Drawing visualizations.");
265-
visual_->setStateBatch(playback_.getStateBatch());
266-
visual_->showEnabled();
267-
268268
// Playback.
269269
ROS_DEBUG("FreeGaitPreviewDisplay::newGoalAvailable: Setting up control.");
270270
playButtonProperty_->setReadOnly(false);

free_gait_rviz_plugin/src/FreeGaitPreviewPlayback.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ void FreeGaitPreviewPlayback::processingCallback(bool success)
146146
if (!success) return;
147147
Lock lock(dataMutex_);
148148
clear();
149-
stateBatch_ = batchExecutor_->getStateBatch();
149+
stateBatch_ = batchExecutor_->getStateBatch(); // Deep copy.
150150
stateBatchComputer_.computeEndEffectorTrajectories(stateBatch_);
151151
time_.fromSec(stateBatch_.getStartTime());
152152
ROS_DEBUG_STREAM("Resetting time to " << time_ << ".");

free_gait_rviz_plugin/src/FreeGaitPreviewVisual.cpp

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ void FreeGaitPreviewVisual::setEnabledModul(Modul modul, bool enable)
4949

5050
void FreeGaitPreviewVisual::showEnabled()
5151
{
52+
ROS_DEBUG("FreeGaitPreviewVisual::showEnabled()");
5253
for (const auto& modul : enabledModuls_) {
5354
switch (modul) {
5455
case Modul::EndEffectorTrajectories:
@@ -75,36 +76,37 @@ void FreeGaitPreviewVisual::hideEnabled()
7576

7677
void FreeGaitPreviewVisual::showEndEffectorTrajectories(const float width, const Ogre::ColourValue& color)
7778
{
79+
ROS_DEBUG("Rendering end effector trajectories.");
7880
if (!stateBatchPtr_) return;
7981

8082
// Define size.
8183
const size_t nEndEffectors(stateBatchPtr_->getEndEffectorPositions().size());
8284
const size_t nStates(stateBatchPtr_->getStates().size());
8385

8486
// Cleanup.
85-
// TODO Segfaults. Whats the problem?
86-
// if (endEffectorTrajectories_.size() != nEndEffectors) {
87-
// endEffectorTrajectories_.clear();
88-
// for (size_t i; i < nEndEffectors; ++i) {
89-
// endEffectorTrajectories_.push_back(std::unique_ptr<rviz::BillboardLine>(new rviz::BillboardLine(sceneManager_, frameNode_)));
90-
// }
91-
// }
87+
if (endEffectorTrajectories_.size() != nEndEffectors) {
88+
endEffectorTrajectories_.clear();
89+
for (size_t i = 0; i < nEndEffectors; ++i) {
90+
endEffectorTrajectories_.push_back(std::unique_ptr<rviz::BillboardLine>(new rviz::BillboardLine(sceneManager_, frameNode_)));
91+
}
92+
}
9293

93-
for (size_t i; i < nEndEffectors; ++i) {
94+
for (size_t i = 0; i < nEndEffectors; ++i) {
95+
auto& trajectory = endEffectorTrajectories_[i];
9496
// For each foot trajectory.
95-
endEffectorTrajectories_.push_back(std::unique_ptr<rviz::BillboardLine>(new rviz::BillboardLine(sceneManager_, frameNode_)));
96-
endEffectorTrajectories_[i]->clear();
97-
endEffectorTrajectories_[i]->setLineWidth(width);
98-
endEffectorTrajectories_[i]->setColor(color.r, color.g, color.b, color.a);
99-
endEffectorTrajectories_[i]->setNumLines(1);
100-
endEffectorTrajectories_[i]->setMaxPointsPerLine(nStates);
97+
trajectory->clear();
98+
trajectory->setLineWidth(width);
99+
trajectory->setColor(color.r, color.g, color.b, color.a);
100+
trajectory->setNumLines(1);
101+
trajectory->setMaxPointsPerLine(nStates);
101102

102-
free_gait::Position previousPosition;
103+
free_gait::Position previousPosition(free_gait::Position::Zero());
103104
for (const auto& positionElement : stateBatchPtr_->getEndEffectorPositions()[i]) {
104-
auto& position = positionElement.second;
105-
if ((position - previousPosition).norm() < 0.01) continue;
105+
const auto& position = positionElement.second;
106+
if ((position - previousPosition).norm() < 0.01) continue; // TODO Set as parameter.
107+
previousPosition = position;
106108
const auto point = Ogre::Vector3(position.x(), position.y(), position.z());
107-
endEffectorTrajectories_[i]->addPoint(point);
109+
trajectory->addPoint(point);
108110
}
109111
}
110112
}

0 commit comments

Comments
 (0)