-
Notifications
You must be signed in to change notification settings - Fork 20
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
Fix communication error handling #64
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
383cf17
Drop support for yp-spur<1.17.0
at-wat 201966d
Fix communication error handling
at-wat d3166b0
Show error on exit
at-wat 880d346
Fix exit code on communication failure
at-wat af66b93
Don't get_force on simulate_control mode
at-wat 64edc4b
Merge branch 'master' into fix-communication-error-handling
at-wat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -742,17 +742,17 @@ class YpspurRosNode | |
} | ||
~YpspurRosNode() | ||
{ | ||
if (pid_ > 0) | ||
// Kill ypspur-coordinator if the communication is still active. | ||
if (pid_ > 0 && YP::YP_get_error_state() == 0) | ||
{ | ||
ROS_INFO("killing ypspur-coordinator (%d)", (int)pid_); | ||
kill(pid_, SIGINT); | ||
int status; | ||
waitpid(pid_, &status, 0); | ||
ROS_INFO("ypspur-coordinator is killed (status: %d)", status); | ||
} | ||
ros::shutdown(); | ||
} | ||
void spin() | ||
bool spin() | ||
{ | ||
geometry_msgs::TransformStamped odom_trans; | ||
odom_trans.header.frame_id = frames_["odom"]; | ||
|
@@ -819,8 +819,8 @@ class YpspurRosNode | |
if (!simulate_control_) | ||
{ | ||
t = YP::YPSpur_get_pos(YP::CS_BS, &x, &y, &yaw); | ||
if (t == 0.0) | ||
t = now.toSec(); | ||
if (t <= 0.0) | ||
break; | ||
YP::YPSpur_get_vel(&v, &w); | ||
} | ||
else | ||
|
@@ -853,9 +853,12 @@ class YpspurRosNode | |
odom_trans.transform.rotation = tf::createQuaternionMsgFromYaw(yaw); | ||
tf_broadcaster_.sendTransform(odom_trans); | ||
|
||
t = YP::YPSpur_get_force(&wrench.wrench.force.x, &wrench.wrench.torque.z); | ||
if (t == 0.0) | ||
t = now.toSec(); | ||
if (!simulate_control_) | ||
{ | ||
t = YP::YPSpur_get_force(&wrench.wrench.force.x, &wrench.wrench.torque.z); | ||
if (t <= 0.0) | ||
break; | ||
} | ||
wrench.header.stamp = ros::Time(t); | ||
wrench.wrench.force.y = 0; | ||
wrench.wrench.force.z = 0; | ||
|
@@ -917,9 +920,9 @@ class YpspurRosNode | |
} | ||
i++; | ||
} | ||
if (t == 0.0) | ||
t = ros::Time::now().toSec(); | ||
} | ||
if (t <= 0.0) | ||
break; | ||
joint.header.stamp = ros::Time(t); | ||
} | ||
else | ||
|
@@ -1192,10 +1195,8 @@ class YpspurRosNode | |
updateDiagnostics(now); | ||
|
||
if (YP::YP_get_error_state()) | ||
{ | ||
ROS_ERROR("ypspur-coordinator is not active"); | ||
break; | ||
} | ||
|
||
ros::spinOnce(); | ||
loop.sleep(); | ||
|
||
|
@@ -1223,25 +1224,35 @@ class YpspurRosNode | |
} | ||
} | ||
ROS_INFO("ypspur_ros main loop terminated"); | ||
|
||
if (YP::YP_get_error_state()) | ||
{ | ||
ROS_ERROR("ypspur-coordinator is not active"); | ||
return false; | ||
} | ||
return true; | ||
} | ||
}; | ||
|
||
int main(int argc, char* argv[]) | ||
{ | ||
ros::init(argc, argv, "ypspur_ros"); | ||
ros::NodeHandle nh; | ||
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. for |
||
|
||
int ret = 0; | ||
|
||
try | ||
{ | ||
YpspurRosNode yr; | ||
yr.spin(); | ||
if (!yr.spin()) | ||
ret = 1; | ||
} | ||
catch (std::runtime_error& e) | ||
{ | ||
ROS_ERROR("%s", e.what()); | ||
ros::WallDuration(0.1).sleep(); | ||
return -1; | ||
ret = 1; | ||
} | ||
|
||
ros::WallDuration(0.1).sleep(); | ||
return 0; | ||
return ret; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Exit on inter process communication error.