-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Distance segfault #642
Distance segfault #642
Changes from 13 commits
f0306ec
f948f48
1088b78
b58a168
f6267e3
eff2b2c
1a13b59
88a558f
61d1b02
ee34ff0
7ea2aac
ab3185e
7489e48
bc03832
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -17,6 +17,7 @@ | |||||||||||||||
|
||||||||||||||||
#include <yaml-cpp/yaml.h> | ||||||||||||||||
#include <ros/ros.h> | ||||||||||||||||
#include <rosbag/recorder.h> | ||||||||||||||||
|
||||||||||||||||
#include <ignition/msgs/boolean.pb.h> | ||||||||||||||||
#include <ignition/msgs/float.pb.h> | ||||||||||||||||
|
@@ -162,6 +163,9 @@ class subt::GameLogicPluginPrivate | |||||||||||||||
/// \param[in] _event Unused. | ||||||||||||||||
public: void PublishScore(); | ||||||||||||||||
|
||||||||||||||||
/// \brief Function that runs the ROS bag recorder. | ||||||||||||||||
public: void RosBag(); | ||||||||||||||||
|
||||||||||||||||
/// \brief Log robot pos data | ||||||||||||||||
public: void LogRobotPosData(); | ||||||||||||||||
|
||||||||||||||||
|
@@ -314,6 +318,9 @@ class subt::GameLogicPluginPrivate | |||||||||||||||
/// \brief Thread on which scores are published | ||||||||||||||||
public: std::unique_ptr<std::thread> publishThread = nullptr; | ||||||||||||||||
|
||||||||||||||||
/// \brief Thread on which the ROS bag recorder runs. | ||||||||||||||||
public: std::unique_ptr<std::thread> bagThread = nullptr; | ||||||||||||||||
|
||||||||||||||||
/// \brief Whether the task has started. | ||||||||||||||||
public: bool started = false; | ||||||||||||||||
|
||||||||||||||||
|
@@ -439,6 +446,9 @@ class subt::GameLogicPluginPrivate | |||||||||||||||
/// \brief A mutex. | ||||||||||||||||
public: std::mutex mutex; | ||||||||||||||||
|
||||||||||||||||
/// \brief Mutex to protect the poses data structure. | ||||||||||||||||
public: std::mutex posesMutex; | ||||||||||||||||
|
||||||||||||||||
/// \brief Log file output stream. | ||||||||||||||||
public: std::ofstream logStream; | ||||||||||||||||
|
||||||||||||||||
|
@@ -554,6 +564,10 @@ class subt::GameLogicPluginPrivate | |||||||||||||||
public: ros::Publisher rosRegionEventPub; | ||||||||||||||||
public: std::map<std::string, ros::Publisher> rosRobotPosePubs; | ||||||||||||||||
public: std::map<std::string, ros::Publisher> rosRobotKinematicPubs; | ||||||||||||||||
|
||||||||||||||||
/// \brief Pointer to the ROS bag recorder. | ||||||||||||||||
public: std::unique_ptr<rosbag::Recorder> rosRecorder; | ||||||||||||||||
|
||||||||||||||||
public: std::string prevPhase = ""; | ||||||||||||||||
|
||||||||||||||||
/// \brief Counter to create unique id for events | ||||||||||||||||
|
@@ -576,6 +590,13 @@ GameLogicPlugin::~GameLogicPlugin() | |||||||||||||||
this->dataPtr->finished = true; | ||||||||||||||||
if (this->dataPtr->publishThread) | ||||||||||||||||
this->dataPtr->publishThread->join(); | ||||||||||||||||
|
||||||||||||||||
if (this->dataPtr->bagThread) | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is already done in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually when running this, I get a segfault because it's trying to join the thread twice for some reason, I have a fix inbound. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Look at bc03832 |
||||||||||||||||
{ | ||||||||||||||||
// Shutdown ros. this makes the ROS bag recorder stop. | ||||||||||||||||
ros::shutdown(); | ||||||||||||||||
this->dataPtr->bagThread->join(); | ||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
////////////////////////////////////////////////// | ||||||||||||||||
|
@@ -663,6 +684,17 @@ void GameLogicPlugin::Configure(const ignition::gazebo::Entity & /*_entity*/, | |||||||||||||||
this->dataPtr->rosRegionEventPub = | ||||||||||||||||
this->dataPtr->rosnode->advertise<subt_ros::RegionEvent>( | ||||||||||||||||
"region_event", 100); | ||||||||||||||||
|
||||||||||||||||
// Setup a ros bag recorder. | ||||||||||||||||
rosbag::RecorderOptions recorderOptions; | ||||||||||||||||
recorderOptions.append_date=false; | ||||||||||||||||
recorderOptions.prefix="/tmp/ign/logs/cloudsim"; | ||||||||||||||||
recorderOptions.regex=true; | ||||||||||||||||
recorderOptions.topics.push_back("/subt/.*"); | ||||||||||||||||
|
||||||||||||||||
this->dataPtr->rosRecorder.reset(new rosbag::Recorder(recorderOptions)); | ||||||||||||||||
this->dataPtr->bagThread.reset(new std::thread( | ||||||||||||||||
&GameLogicPluginPrivate::RosBag, this->dataPtr.get())); | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I think you can save yourself a member function here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also did this in bc03832 since I was in there. |
||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
|
@@ -1099,7 +1131,8 @@ void GameLogicPlugin::PostUpdate( | |||||||||||||||
auto mPose = | ||||||||||||||||
_ecm.Component<gazebo::components::Pose>(model->Data()); | ||||||||||||||||
// Execute the start logic if a robot has moved into the tunnel. | ||||||||||||||||
if (baseIter->second.Pos().Distance(mPose->Data().Pos()) > | ||||||||||||||||
if (mPose && | ||||||||||||||||
baseIter->second.Pos().Distance(mPose->Data().Pos()) > | ||||||||||||||||
this->dataPtr->allowedDistanceFromBase) | ||||||||||||||||
{ | ||||||||||||||||
ignition::msgs::Boolean req, res; | ||||||||||||||||
|
@@ -1206,7 +1239,11 @@ void GameLogicPlugin::PostUpdate( | |||||||||||||||
this->dataPtr.get()); | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
this->dataPtr->poses[_nameComp->Data()] = _poseComp->Data(); | ||||||||||||||||
{ | ||||||||||||||||
std::lock_guard<std::mutex> lock(this->dataPtr->posesMutex); | ||||||||||||||||
this->dataPtr->poses[_nameComp->Data()] = _poseComp->Data(); | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
for (std::pair<const subt::ArtifactType, | ||||||||||||||||
std::map<std::string, ignition::math::Pose3d>> &artifactPair : | ||||||||||||||||
this->dataPtr->artifacts) | ||||||||||||||||
|
@@ -1297,7 +1334,8 @@ void GameLogicPlugin::PostUpdate( | |||||||||||||||
this->dataPtr->robotPrevPose[name] = pose; | ||||||||||||||||
return true; | ||||||||||||||||
} | ||||||||||||||||
else if (robotPoseDataIt->second.back().second.Pos().Distance( | ||||||||||||||||
else if (!robotPoseDataIt->second.empty() && | ||||||||||||||||
robotPoseDataIt->second.back().second.Pos().Distance( | ||||||||||||||||
pose.Pos()) > 1.0) | ||||||||||||||||
{ | ||||||||||||||||
// time passed since last pose sample | ||||||||||||||||
|
@@ -1475,6 +1513,7 @@ void GameLogicPlugin::PostUpdate( | |||||||||||||||
{ | ||||||||||||||||
static bool errorSent = false; | ||||||||||||||||
|
||||||||||||||||
std::lock_guard<std::mutex> lock(this->dataPtr->posesMutex); | ||||||||||||||||
// Get the artifact origin's pose. | ||||||||||||||||
std::map<std::string, ignition::math::Pose3d>::iterator originIter = | ||||||||||||||||
this->dataPtr->poses.find(subt::kArtifactOriginName); | ||||||||||||||||
|
@@ -2108,6 +2147,12 @@ void GameLogicPluginPrivate::ParseArtifacts( | |||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
///////////////////////////////////////////////// | ||||||||||||||||
void GameLogicPluginPrivate::RosBag() | ||||||||||||||||
{ | ||||||||||||||||
this->rosRecorder->run(); | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
///////////////////////////////////////////////// | ||||||||||||||||
void GameLogicPluginPrivate::PublishScore() | ||||||||||||||||
{ | ||||||||||||||||
|
@@ -2273,7 +2318,24 @@ void GameLogicPluginPrivate::Finish(const ignition::msgs::Time &_simTime) | |||||||||||||||
statusMsg.timestamp.sec = _simTime.sec(); | ||||||||||||||||
statusMsg.timestamp.nsec = _simTime.nsec(); | ||||||||||||||||
this->rosStatusPub.publish(statusMsg); | ||||||||||||||||
|
||||||||||||||||
if (this->bagThread) | ||||||||||||||||
{ | ||||||||||||||||
// Shutdown ros. this makes the ROS bag recorder stop. | ||||||||||||||||
ros::shutdown(); | ||||||||||||||||
this->bagThread->join(); | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
// Send the recording_complete message after ROS has shutdown, if ROS | ||||||||||||||||
// has been enabled. | ||||||||||||||||
ignition::msgs::StringMsg completeMsg; | ||||||||||||||||
completeMsg.mutable_header()->mutable_stamp()->CopyFrom( | ||||||||||||||||
this->simTime); | ||||||||||||||||
completeMsg.set_data("recording_complete"); | ||||||||||||||||
this->startPub.Publish(completeMsg); | ||||||||||||||||
|
||||||||||||||||
this->eventCounter++; | ||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
|
@@ -2625,42 +2687,49 @@ void GameLogicPluginPrivate::LogRobotArtifactData( | |||||||||||||||
bool GameLogicPluginPrivate::PoseFromArtifactHelper(const std::string &_robot, | ||||||||||||||||
ignition::math::Pose3d &_result) | ||||||||||||||||
{ | ||||||||||||||||
// Get an iterator to the robot's pose. | ||||||||||||||||
std::map<std::string, ignition::math::Pose3d>::iterator robotIter = | ||||||||||||||||
this->poses.find(_robot); | ||||||||||||||||
ignition::math::Pose3d robotPose, basePose; | ||||||||||||||||
|
||||||||||||||||
if (robotIter == this->poses.end()) | ||||||||||||||||
{ | ||||||||||||||||
ignerr << "[GameLogicPlugin]: Unable to find robot with name [" | ||||||||||||||||
<< _robot << "]. Ignoring PoseFromArtifact request" << std::endl; | ||||||||||||||||
return false; | ||||||||||||||||
} | ||||||||||||||||
std::lock_guard<std::mutex> lock(this->posesMutex); | ||||||||||||||||
// Get an iterator to the robot's pose. | ||||||||||||||||
std::map<std::string, ignition::math::Pose3d>::iterator robotIter = | ||||||||||||||||
this->poses.find(_robot); | ||||||||||||||||
|
||||||||||||||||
// Get an iterator to the base station's pose. | ||||||||||||||||
std::map<std::string, ignition::math::Pose3d>::iterator baseIter = | ||||||||||||||||
this->poses.find(subt::kBaseStationName); | ||||||||||||||||
if (robotIter == this->poses.end()) | ||||||||||||||||
{ | ||||||||||||||||
ignerr << "[GameLogicPlugin]: Unable to find robot with name [" | ||||||||||||||||
<< _robot << "]. Ignoring PoseFromArtifact request" << std::endl; | ||||||||||||||||
return false; | ||||||||||||||||
} | ||||||||||||||||
robotPose = robotIter->second; | ||||||||||||||||
|
||||||||||||||||
// Sanity check: Make sure that the robot is in the staging area, as this | ||||||||||||||||
// service is only available in that zone. | ||||||||||||||||
if (baseIter == this->poses.end()) | ||||||||||||||||
{ | ||||||||||||||||
ignerr << "[GameLogicPlugin]: Unable to find the staging area [" | ||||||||||||||||
<< subt::kBaseStationName | ||||||||||||||||
<< "]. Ignoring PoseFromArtifact request" << std::endl; | ||||||||||||||||
return false; | ||||||||||||||||
// Get an iterator to the base station's pose. | ||||||||||||||||
std::map<std::string, ignition::math::Pose3d>::iterator baseIter = | ||||||||||||||||
this->poses.find(subt::kBaseStationName); | ||||||||||||||||
|
||||||||||||||||
// Sanity check: Make sure that the robot is in the staging area, as this | ||||||||||||||||
// service is only available in that zone. | ||||||||||||||||
if (baseIter == this->poses.end()) | ||||||||||||||||
{ | ||||||||||||||||
ignerr << "[GameLogicPlugin]: Unable to find the staging area [" | ||||||||||||||||
<< subt::kBaseStationName | ||||||||||||||||
<< "]. Ignoring PoseFromArtifact request" << std::endl; | ||||||||||||||||
return false; | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
basePose = baseIter->second; | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
if (baseIter->second.Pos().Distance(robotIter->second.Pos()) > | ||||||||||||||||
if (basePose.Pos().Distance(robotPose.Pos()) > | ||||||||||||||||
this->allowedDistanceFromBase) | ||||||||||||||||
{ | ||||||||||||||||
ignerr << "[GameLogicPlugin]: Robot [" << _robot << "] is too far from the " | ||||||||||||||||
<< "staging area. Ignoring PoseFromArtifact request" << std::endl; | ||||||||||||||||
return false; | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
|
||||||||||||||||
// Pose. | ||||||||||||||||
_result = robotIter->second - this->artifactOriginPose; | ||||||||||||||||
_result = robotPose - this->artifactOriginPose; | ||||||||||||||||
return true; | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reminder to reset this branch before merging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we didn't want this part merged as is, right?