5 #include <sensor_msgs/JointState.h> 8 #include "phidgets_msgs/EncoderDecimatedSpeed.h" 14 : nh_(nh), nh_private_(nh_private)
21 sprintf(str,
"joint%u_name", i);
24 sprintf(str,
"joint%u_tick2rad", i);
27 ROS_INFO(
"Channel %u Name: '%s', Tick2rad: '%f'", i,
31 int serial_number = -1;
32 if (serial_number == -1)
47 const std::string topic_path =
"joint_states";
48 ROS_INFO(
"Publishing state to topic: %s", topic_path.c_str());
53 if (serial_number == -1)
55 ROS_INFO(
"Waiting for any High Speed Encoder Phidget to be attached.");
58 ROS_INFO(
"Waiting for High Speed Encoder Phidget %d to be attached....",
68 ROS_FATAL(
"Problem waiting for attachment: %s", sError.c_str());
91 sensor_msgs::JointState js_msg;
92 static uint32_t seq_cnt = 0;
93 js_msg.header.seq = (seq_cnt++);
97 js_msg.name.resize(N);
98 for (
unsigned int i = 0; i < std::min<size_t>(
joint_names_.size(), N); i++)
103 js_msg.position.resize(N);
104 js_msg.velocity.resize(N);
105 js_msg.effort.clear();
107 for (
unsigned int i = 0; i < N; i++)
123 phidgets_msgs::EncoderDecimatedSpeed e;
142 phidgets_msgs::EncoderDecimatedSpeed e;
163 ROS_INFO(
"Device type : %s", dev_type.c_str());
164 ROS_INFO(
"Device serial : %d", serial_number);
165 ROS_INFO(
"Device version : %d", version);
166 ROS_INFO(
"Number of encoders: %d", num_encoders);
167 ROS_INFO(
"Number of inputs : %d", num_inputs);
175 const std::string topic_path =
"joint_states";
181 for (
int i = 0; i < inputcount; i++)
183 std::string
s = topic_path;
185 sprintf(buf,
"_ch%u_decim_speed", i);
187 ROS_INFO(
"Publishing decimated speed of channel %u to topic: %s", i,
190 nh_.
advertise<phidgets_msgs::EncoderDecimatedSpeed>(s, 10);
193 ROS_INFO(
"%s Serial number %d attached with %d encoders!", name.c_str(),
194 serial_number, inputcount);
198 for (
int i = 0; i < inputcount; i++)
208 ROS_INFO(
"%s Serial number %d detached!", name.c_str(), serial_number);
217 ROS_ERROR(
"Error handled. %d - %s", errorCode,
225 ROS_DEBUG(
"Encoder %d Count %d", index, Position);
int loops_without_update_speed_buffer
int openAndWaitForAttachment(int serial_number, int timeout)
int speed_filter_idle_iter_loops_before_reset_
void publish(const boost::shared_ptr< M > &message) const
void display_properties()
void detachHandler() override
ros::NodeHandle nh_private_
std::vector< double > speeds_buffer
HighSpeedEncoderRosI(ros::NodeHandle nh, ros::NodeHandle nh_private)
ros::Publisher encoder_pub_
int getDeviceSerialNumber()
void timerCallback(const ros::TimerEvent &event)
std::vector< ros::Publisher > encoder_decimspeed_pubs_
std::vector< double > joint_tick2rad_
std::mutex encoder_states_mutex_
void setEnabled(int index, bool enabled)
bool speed_buffer_updated
static std::string getErrorDescription(int errorCode)
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
Timer createTimer(Rate r, Handler h, Obj o, bool oneshot=false, bool autostart=true) const
void positionChangeHandler(int index, int time, int positionChange) override
std::string getDeviceType()
std::vector< TStatePerChannel > encoder_states_
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
int getPosition(int index)
void errorHandler(int errorCode) override
void attachHandler() override
bool getParam(const std::string &key, std::string &s) const
ROSCPP_DECL void shutdown()
double instantaneousSpeed
std::vector< std::string > joint_names_
std::string getDeviceName()
int speed_filter_samples_len_