jackal_hardware.cpp
Go to the documentation of this file.
00001 
00034 #include <boost/assign.hpp>
00035 #include "jackal_base/jackal_hardware.h"
00036 
00037 namespace jackal_base
00038 {
00039 
00040 JackalHardware::JackalHardware()
00041 {
00042   ros::V_string joint_names = boost::assign::list_of("front_left_wheel")
00043       ("front_right_wheel")("rear_left_wheel")("rear_right_wheel");
00044 
00045   for (unsigned int i = 0; i < joint_names.size(); i++)
00046   {
00047     hardware_interface::JointStateHandle joint_state_handle(joint_names[i],
00048         &joints_[i].position, &joints_[i].velocity, &joints_[i].effort);
00049     joint_state_interface_.registerHandle(joint_state_handle);
00050 
00051     hardware_interface::JointHandle joint_handle(
00052         joint_state_handle, &joints_[i].velocity_command);
00053     velocity_joint_interface_.registerHandle(joint_handle);
00054   }
00055   registerInterface(&joint_state_interface_);
00056   registerInterface(&velocity_joint_interface_);
00057 
00058   feedback_sub_ = nh_.subscribe("feedback", 1, &JackalHardware::feedbackCallback, this);
00059 
00060   // Realtime publisher, initializes differently from regular ros::Publisher
00061   cmd_drive_pub_.init(nh_, "cmd_drive", 1);
00062 }
00063 
00070 void JackalHardware::copyJointsFromHardware()
00071 {
00072   boost::mutex::scoped_lock feedback_msg_lock(feedback_msg_mutex_, boost::try_to_lock);
00073   if (feedback_msg_ && feedback_msg_lock)
00074   {
00075     for (int i = 0; i < 4; i++)
00076     {
00077       joints_[i].position = feedback_msg_->drivers[i % 2].measured_travel;
00078       joints_[i].velocity = feedback_msg_->drivers[i % 2].measured_velocity;
00079       joints_[i].effort = 0;  // TODO(mikepurvis): determine this from amperage data.
00080     }
00081   }
00082 }
00083 
00089 void JackalHardware::publishDriveFromController()
00090 {
00091   if (cmd_drive_pub_.trylock())
00092   {
00093     cmd_drive_pub_.msg_.mode = jackal_msgs::Drive::MODE_VELOCITY;
00094     cmd_drive_pub_.msg_.drivers[jackal_msgs::Drive::LEFT] = joints_[0].velocity_command;
00095     cmd_drive_pub_.msg_.drivers[jackal_msgs::Drive::RIGHT] = joints_[1].velocity_command;
00096     cmd_drive_pub_.unlockAndPublish();
00097   }
00098 }
00099 
00100 void JackalHardware::feedbackCallback(const jackal_msgs::Feedback::ConstPtr& msg)
00101 {
00102   // Update the feedback message pointer to point to the current message. Block
00103   // until the control thread is not using the lock.
00104   boost::mutex::scoped_lock lock(feedback_msg_mutex_);
00105   feedback_msg_ = msg;
00106 }
00107 
00108 }  // namespace jackal_base


jackal_base
Author(s): Mike Purvis
autogenerated on Thu Jul 4 2019 19:48:56