19 if(!ros::isInitialized())
27 "single_motor_controller_node",
28 ros::init_options::NoSigintHandler
32 node_handle.reset(
new ros::NodeHandle(
"single_motor_controller_node"));
60 "/motor/confirmation",
82 ROS_INFO(
"initROS complete");
101 double angle_goal_pos = _msg.data*M_PI/180.0;
123 const double &_percentage,
124 const double &_period,
125 const double &_max_travel,
131 double a = 30.0*_max_travel;
132 double b = -15.0*_max_travel;
133 double c = 1.875*_max_travel;
134 double d = -_max_travel*7.0/16.0;
136 _x = 0.2*
a*pow((_percentage - 0.5), 5.0) +
b*pow((_percentage - 0.5), 3.0)/3.0 +
c*_percentage + d;
137 _x_d = (
a*pow((_percentage - 0.5), 4.0) +
b*pow((_percentage - 0.5), 2.0) +
c)/_period;
138 _x_dd = (4.0*
a*pow((_percentage - 0.5), 3.0) + 2.0*
b*(_percentage - 0.5))/(_period*_period);
143 double desired_angle_travel;
152 sensor_msgs::JointState joint_command_msg;
158 joint_command_msg.header.stamp = ros::Time::now();
165 sensor_msgs::JointState joint_command_msg;
171 joint_command_msg.effort.push_back(
torque_ref);
173 joint_command_msg.header.stamp = ros::Time::now();
195 ros::Rate publish_position_command_rate(10);
197 sensor_msgs::JointState joint_command_msg;
199 joint_command_msg.position.push_back(0.0);
203 joint_command_msg.header.stamp = ros::Time::now();
211 publish_position_command_rate.sleep();
217 sensor_msgs::JointState joint_command_msg;
221 joint_command_msg.position.push_back(_joint_pos);
225 joint_command_msg.header.stamp = ros::Time::now();
232 sensor_msgs::JointState joint_command_msg;
237 joint_command_msg.velocity.push_back(_joint_vel);
240 joint_command_msg.header.stamp = ros::Time::now();
249 sensor_msgs::JointState joint_command_msg;
253 joint_command_msg.effort.push_back(_torque);
255 joint_command_msg.header.stamp = ros::Time::now();
262 ros::Rate set_gain_rate(0.5);
266 std_msgs::Float64MultiArray motor_gains_msg;
268 motor_gains_msg.data.push_back(_k_p_pos);
269 motor_gains_msg.data.push_back(_k_i_pos);
270 motor_gains_msg.data.push_back(_k_p_vel);
271 motor_gains_msg.data.push_back(_k_i_vel);
272 motor_gains_msg.data.push_back(_k_p_torque);
273 motor_gains_msg.data.push_back(_k_i_torque);
275 ROS_INFO(
"Trying to set motor gains");
281 ROS_INFO(
"Requisting motor reply");
283 set_gain_rate.sleep();
288 ROS_INFO(
"Motor setup complete");
327 ROS_INFO(
"I: %f\tq: %f\tq_ref: %f\tq_d: %f\tq_d_ref: %f\tq_dd_ref: %f\tT: %f\tT_ref: %f",
333 sensor_msgs::JointState joint_state_msg;
335 joint_state_msg.position.push_back(
angle_pos);
336 joint_state_msg.velocity.push_back(
angle_vel);
337 joint_state_msg.effort.push_back(
torque);
339 joint_state_msg.header.stamp = ros::Time::now();
341 sensor_msgs::JointState joint_reference_msg;
345 joint_reference_msg.effort.push_back(
torque_ref);
347 joint_reference_msg.header.stamp = ros::Time::now();
ros::Subscriber ready_to_proceed_subscriber
void checkForNewMessages()
ros::Subscriber motor_confirmation_subscriber
bool initialStateReceived()
void readyToProceedCallback(const std_msgs::Bool &_msg)
ros::Subscriber set_goal_subscriber
void calculateSingleAxisTrajectory(const double &_percentage, const double &_period, const double &_max_travel, double &_x, double &_x_d, double &_x_dd)
void sendJointTorqueCommand()
ros::Subscriber keep_logging_subscriber
void sendJointPositionCommand()
std::unique_ptr< ros::NodeHandle > node_handle
void setPositionDirectly(double _joint_pos)
void setTorqueDirectly(double _torque)
ros::Publisher joint_command_publisher
ros::Subscriber motor_state_subscriber
void setVelocityDirectly(double _joint_vel)
ros::Publisher motor_gain_publisher
ros::Publisher log_motor_state_publisher
void keepLoggingCallback(const std_msgs::Bool &_msg)
void motorConfirmationCallback(const std_msgs::Bool &_msg)
SingleMotorController(double _publish_frequency, bool _use_position_control)
const double UNINITIALIZED_STATE
void motorStateCallback(const sensor_msgs::JointStatePtr &_msg)
void setGoalCallback(const std_msgs::Float32 &_msg)
ros::Publisher log_motor_reference_publisher
const double IDLE_COMMAND