Go to the documentation of this file.00001 #include "r2_controllers_ros/R2RosArbiter.hpp"
00002
00003 R2RosArbiter::R2RosArbiter(ros::NodeHandle nh)
00004 {
00005 nh = nh;
00006 modeIn = nh.subscribe("/mode", 1, &R2RosArbiter::modeCallback, this);
00007 labeledJointSettingsIn = nh.subscribe("/joint_ref_settings", 1, &R2RosArbiter::labeledJointSettingsCallback, this);
00008 labeledPoseSettingsIn = nh.subscribe("/pose_ref_settings", 1, &R2RosArbiter::labeledPoseSettingsCallback, this);
00009 labeledJointStateIn = nh.subscribe("/desired_torque_limits", 1, &R2RosArbiter::labeledJointStateCallback, this);
00010 labeledGainsIn = nh.subscribe("/joint_desired_dynamics", 1, &R2RosArbiter::labeledGainsCallback, this);
00011 labeledJointTrajIn = nh.subscribe("/joint_refs", 32, &R2RosArbiter::labeledJointTrajectoryCallback, this);
00012 labeledPoseTrajIn = nh.subscribe("/pose_refs", 32, &R2RosArbiter::labeledPoseTrajectoryCallback, this);
00013
00014 jointSettingsOut = nh.advertise<nasa_r2_common_msgs::ControllerJointSettings>("joint_ref_settings", 1);
00015 poseSettingsOut = nh.advertise<nasa_r2_common_msgs::ControllerPoseSettings>("pose_ref_settings", 1);
00016 jointStateOut = nh.advertise<sensor_msgs::JointState>("joint_states", 1);
00017 gainsOut = nh.advertise<nasa_r2_common_msgs::Gains>("gains", 1);
00018 jointTrajOut = nh.advertise<nasa_r2_common_msgs::JointTrajectoryReplan>("joint_refs", 1);
00019 poseTrajOut = nh.advertise<nasa_r2_common_msgs::PoseTrajectoryReplan>("pose_refs", 10);
00020
00021 goalStatusOut = nh.advertise<actionlib_msgs::GoalStatusArray>("/arbiter_goal_status", 1);
00022 }
00023
00024 void R2RosArbiter::writeSuccessStatus(std::string id)
00025 {
00026 actionlib_msgs::GoalStatusArray goalStatusMsg;
00027 actionlib_msgs::GoalStatus gStatus;
00028 gStatus.status = actionlib_msgs::GoalStatus::SUCCEEDED;
00029 gStatus.text = "Successful command pass-thru";
00030 gStatus.goal_id.id = id;
00031
00032 goalStatusMsg.status_list.push_back(gStatus);
00033 goalStatusOut.publish(goalStatusMsg);
00034 }
00035
00036 void R2RosArbiter::modeCallback(const nasa_r2_common_msgs::Modes &msg)
00037 {
00038 writeSuccessStatus("Mode");
00039 }
00040
00041 void R2RosArbiter::labeledJointSettingsCallback(const nasa_r2_common_msgs::LabeledControllerJointSettings &msg)
00042 {
00043 nasa_r2_common_msgs::ControllerJointSettings passthrough;
00044 passthrough.joint_names = msg.joint_names;
00045 passthrough.jointVelocityLimits = msg.jointVelocityLimits;
00046 passthrough.jointAccelerationLimits = msg.jointAccelerationLimits;
00047 jointSettingsOut.publish(passthrough);
00048
00049 writeSuccessStatus("JointSettings");
00050 }
00051
00052 void R2RosArbiter::labeledPoseSettingsCallback(const nasa_r2_common_msgs::LabeledControllerPoseSettings &msg)
00053 {
00054 nasa_r2_common_msgs::ControllerPoseSettings passthrough;
00055 passthrough.maxLinearAcceleration = msg.maxLinearAcceleration;
00056 passthrough.maxLinearVelocity = msg.maxLinearVelocity;
00057 passthrough.maxRotationalAcceleration = msg.maxRotationalAcceleration;
00058 passthrough.maxRotationalVelocity = msg.maxRotationalVelocity;
00059 poseSettingsOut.publish(passthrough);
00060 writeSuccessStatus("PoseSettings");
00061 }
00062
00063 void R2RosArbiter::labeledJointStateCallback(const nasa_r2_common_msgs::LabeledJointState &msg)
00064 {
00065 sensor_msgs::JointState passthrough;
00066 passthrough.effort = msg.effort;
00067 passthrough.header = msg.header;
00068 passthrough.name = msg.name;
00069 passthrough.position = msg.position;
00070 passthrough.velocity = msg.velocity;
00071 jointStateOut.publish(passthrough);
00072 writeSuccessStatus("JointTorqueLimits");
00073 }
00074
00075 void R2RosArbiter::labeledGainsCallback(const nasa_r2_common_msgs::LabeledGains &msg)
00076 {
00077 nasa_r2_common_msgs::Gains passthrough;
00078 passthrough.D = msg.D;
00079 passthrough.I = msg.I;
00080 passthrough.joint_names = msg.joint_names;
00081 passthrough.K = msg.K;
00082 passthrough.naturalFreq = msg.naturalFreq;
00083 passthrough.windupLimit = msg.windupLimit;
00084 gainsOut.publish(passthrough);
00085 writeSuccessStatus("Gains");
00086 }
00087
00088 void R2RosArbiter::labeledJointTrajectoryCallback(const nasa_r2_common_msgs::LabeledJointTrajectory &msg)
00089 {
00090 nasa_r2_common_msgs::JointTrajectoryReplan passthrough;
00091 trajectory_msgs::JointTrajectory trajectory;
00092 trajectory.header = msg.header;
00093 trajectory.joint_names = msg.joint_names;
00094 trajectory.points = msg.points;
00095 passthrough.header = msg.header;
00096 passthrough.trajectory = trajectory;
00097 jointTrajOut.publish(passthrough);
00098 writeSuccessStatus("JointRef");
00099 }
00100
00101 void R2RosArbiter::labeledPoseTrajectoryCallback(const nasa_r2_common_msgs::LabeledPoseTrajectory &msg)
00102 {
00103 ROS_INFO("got labeled pose traj");
00104 nasa_r2_common_msgs::PoseTrajectoryReplan passthrough;
00105 nasa_r2_common_msgs::PoseTrajectory trajectory;
00106 trajectory.header = msg.header;
00107 trajectory.nodes = msg.nodes;
00108 trajectory.node_priorities = msg.node_priorities;
00109 trajectory.points = msg.points;
00110 trajectory.refFrames = msg.refFrames;
00111 passthrough.header = msg.header;
00112 passthrough.trajectory = trajectory;
00113 poseTrajOut.publish(passthrough);
00114 ROS_INFO("wrote posetraj");
00115 writeSuccessStatus("PoseTraj");
00116 }