Go to the documentation of this file.00001 #include "robodyn_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 labeledJointRefIn = nh.subscribe("/joint_refs", 32, &R2RosArbiter::labeledJointRefCallback, this);
00012 labeledJointTrajIn = nh.subscribe("/joint_traj", 32, &R2RosArbiter::labeledJointTrajCallback, this);
00013 labeledPoseTrajIn = nh.subscribe("/pose_refs", 32, &R2RosArbiter::labeledPoseTrajectoryCallback, this);
00014 labeledGripperCommandIn = nh.subscribe("/gripper_commands", 10, &R2RosArbiter::labeledGripperCommandCallback, this);
00015
00016 jointSettingsOut = nh.advertise<r2_msgs::ControllerJointSettings>("joint_ref_settings", 1);
00017 poseSettingsOut = nh.advertise<r2_msgs::ControllerPoseSettings>("pose_ref_settings", 1);
00018 jointStateOut = nh.advertise<sensor_msgs::JointState>("joint_states", 1);
00019 gainsOut = nh.advertise<r2_msgs::Gains>("gains", 1);
00020 jointRefsOut = nh.advertise<r2_msgs::JointTrajectoryReplan>("joint_refs", 32);
00021 jointTrajOut = nh.advertise<trajectory_msgs::JointTrajectory>("joint_traj", 32);
00022 poseTrajOut = nh.advertise<r2_msgs::PoseTrajectoryReplan>("pose_refs", 32);
00023 gripperCmdOut = nh.advertise<r2_msgs::GripperPositionCommand>("gripper_cmd", 10);
00024
00025 goalStatusOut = nh.advertise<actionlib_msgs::GoalStatusArray>("/arbiter_goal_status", 1);
00026 }
00027
00028 void R2RosArbiter::writeSuccessStatus(std::string id)
00029 {
00030 actionlib_msgs::GoalStatusArray goalStatusMsg;
00031 actionlib_msgs::GoalStatus gStatus;
00032 gStatus.status = actionlib_msgs::GoalStatus::SUCCEEDED;
00033 gStatus.text = "Successful command pass-thru";
00034 gStatus.goal_id.id = id;
00035
00036 goalStatusMsg.status_list.push_back(gStatus);
00037 goalStatusOut.publish(goalStatusMsg);
00038 }
00039
00040 void R2RosArbiter::modeCallback(const r2_msgs::Modes& msg)
00041 {
00042 writeSuccessStatus("Mode");
00043 }
00044
00045 void R2RosArbiter::labeledJointSettingsCallback(const r2_msgs::LabeledControllerJointSettings& msg)
00046 {
00047 r2_msgs::ControllerJointSettings passthrough;
00048 passthrough.joint_names = msg.joint_names;
00049 passthrough.jointVelocityLimits = msg.jointVelocityLimits;
00050 passthrough.jointAccelerationLimits = msg.jointAccelerationLimits;
00051 jointSettingsOut.publish(passthrough);
00052
00053 writeSuccessStatus("JointSettings");
00054 }
00055
00056 void R2RosArbiter::labeledPoseSettingsCallback(const r2_msgs::LabeledControllerPoseSettings& msg)
00057 {
00058 r2_msgs::ControllerPoseSettings passthrough;
00059 passthrough.maxLinearAcceleration = msg.maxLinearAcceleration;
00060 passthrough.maxLinearVelocity = msg.maxLinearVelocity;
00061 passthrough.maxRotationalAcceleration = msg.maxRotationalAcceleration;
00062 passthrough.maxRotationalVelocity = msg.maxRotationalVelocity;
00063 poseSettingsOut.publish(passthrough);
00064 writeSuccessStatus("PoseSettings");
00065 }
00066
00067 void R2RosArbiter::labeledJointStateCallback(const r2_msgs::LabeledJointState& msg)
00068 {
00069 sensor_msgs::JointState passthrough;
00070 passthrough.effort = msg.effort;
00071 passthrough.header = msg.header;
00072 passthrough.name = msg.name;
00073 passthrough.position = msg.position;
00074 passthrough.velocity = msg.velocity;
00075 jointStateOut.publish(passthrough);
00076 writeSuccessStatus("JointTorqueLimits");
00077 }
00078
00079 void R2RosArbiter::labeledGainsCallback(const r2_msgs::LabeledGains& msg)
00080 {
00081 r2_msgs::Gains passthrough;
00082 passthrough.D = msg.D;
00083 passthrough.I = msg.I;
00084 passthrough.joint_names = msg.joint_names;
00085 passthrough.K = msg.K;
00086 passthrough.naturalFreq = msg.naturalFreq;
00087 passthrough.windupLimit = msg.windupLimit;
00088 gainsOut.publish(passthrough);
00089 writeSuccessStatus("Gains");
00090 }
00091
00092 void R2RosArbiter::labeledJointRefCallback(const r2_msgs::LabeledJointTrajectory& msg)
00093 {
00094 r2_msgs::JointTrajectoryReplan passthrough;
00095 trajectory_msgs::JointTrajectory trajectory;
00096 trajectory.header = msg.header;
00097 trajectory.joint_names = msg.joint_names;
00098 trajectory.points = msg.points;
00099 passthrough.header = msg.header;
00100 passthrough.trajectory = trajectory;
00101 jointRefsOut.publish(passthrough);
00102 writeSuccessStatus("JointRef");
00103 }
00104
00105 void R2RosArbiter::labeledJointTrajCallback(const r2_msgs::LabeledJointTrajectory& msg)
00106 {
00107 trajectory_msgs::JointTrajectory passthrough;
00108 passthrough.header = msg.header;
00109 passthrough.joint_names = msg.joint_names;
00110 passthrough.points = msg.points;
00111 jointTrajOut.publish(passthrough);
00112 writeSuccessStatus("JointTraj");
00113 }
00114
00115 void R2RosArbiter::labeledPoseTrajectoryCallback(const r2_msgs::LabeledPoseTrajectory& msg)
00116 {
00117 ROS_INFO("got labeled pose traj");
00118 r2_msgs::PoseTrajectoryReplan passthrough;
00119 r2_msgs::PoseTrajectory trajectory;
00120 trajectory.header = msg.header;
00121 trajectory.nodes = msg.nodes;
00122 trajectory.node_priorities = msg.node_priorities;
00123 trajectory.points = msg.points;
00124 trajectory.refFrames = msg.refFrames;
00125 passthrough.header = msg.header;
00126 passthrough.trajectory = trajectory;
00127 poseTrajOut.publish(passthrough);
00128 ROS_INFO("wrote posetraj");
00129 writeSuccessStatus("PoseTraj");
00130 }
00131
00132 void R2RosArbiter::labeledGripperCommandCallback(const r2_msgs::LabeledGripperPositionCommand& msg)
00133 {
00134 ROS_INFO("got labeled gripper command");
00135 r2_msgs::GripperPositionCommand passthrough;
00136
00137 passthrough.header = msg.header;
00138 passthrough.name = msg.name;
00139 passthrough.setpoint = msg.setpoint;
00140 passthrough.command = msg.command;
00141 passthrough.dutyCycle = msg.dutyCycle;
00142 gripperCmdOut.publish(passthrough);
00143 writeSuccessStatus("GripperCmd");
00144 }