Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00030 #ifndef _COD_DECOD_STD_IO_HPP_
00031 #define _COD_DECOD_STD_IO_HPP_
00032
00033 #include "sr_ronex_drivers/cod_decod/cod_decod.hpp"
00034 #include <sr_ronex_msgs/BoolArray.h>
00035 #include <std_msgs/UInt16MultiArray.h>
00036 #include "realtime_tools/realtime_box.h"
00037 #include "realtime_tools/realtime_publisher.h"
00038 #include <vector>
00039
00040 namespace sr_cod_decod_std_io
00041 {
00042 enum DigitalIo
00043 {
00044 DigitalIo0,
00045 DigitalIo1,
00046 DigitalIo2,
00047 DigitalIo3
00048 };
00049
00050 enum AnalogOutput
00051 {
00052 AnalogOutput0,
00053 AnalogOutput1
00054 };
00055
00056 enum AnalogInput
00057 {
00058 AnlogInput0,
00059 AnlogInput1,
00060 AnlogInput2,
00061 AnlogInput3
00062 };
00063 }
00064
00065 namespace sr_cod_decod
00066 {
00067 class CodDecodStdIo: public CodDecod
00068 {
00069 public:
00070 CodDecodStdIo();
00071
00072 virtual void construct(hardware_interface::HardwareInterface *hw, EtherCAT_SlaveHandler *sh, int n_digital_outputs,
00073 int n_analog_outputs, int n_digital_inputs, int n_analog_inputs, int n_PWM_outputs);
00080 virtual void update(unsigned char *status_buffer);
00087 virtual void build_command(unsigned char *command_buffer);
00088 virtual void add_diagnostics(std::vector<diagnostic_msgs::DiagnosticStatus> &vec,
00089 diagnostic_updater::DiagnosticStatusWrapper &d);
00090
00096 virtual void setPinAsDigitalInput(sr_cod_decod_std_io::DigitalIo pin);
00097
00104 virtual bool digitalInputToBool(sr_cod_decod_std_io::DigitalIo input_pin);
00105
00112 virtual void digitalInputToBool(sr_cod_decod_std_io::DigitalIo input_pin, bool *where_to_store_it);
00113
00120 virtual double analogInputToDouble(sr_cod_decod_std_io::AnalogInput input_pin);
00121
00128 virtual void analogInputToDouble(sr_cod_decod_std_io::AnalogInput input_pin, double *where_to_store_it);
00129
00136 uint16_t analogInputToUint16(sr_cod_decod_std_io::AnalogInput input_pin);
00137
00144 virtual void analogInputToUint16(sr_cod_decod_std_io::AnalogInput input_pin, uint16_t *where_to_store_it);
00145
00152 int analogInputToInt(sr_cod_decod_std_io::AnalogInput input_pin);
00153
00160 virtual void analogInputToInt(sr_cod_decod_std_io::AnalogInput input_pin, int *where_to_store_it);
00161
00168 virtual void signToDigitalOutput(sr_cod_decod_std_io::DigitalIo output_pin, double value);
00175 virtual void boolToDigitalOutput(sr_cod_decod_std_io::DigitalIo output_pin, bool value);
00176
00183 virtual void doubleToAnalogOutput(sr_cod_decod_std_io::AnalogOutput output_pin, double value);
00184
00191 virtual void uint16ToAnalogOutput(sr_cod_decod_std_io::AnalogOutput output_pin, uint16_t value);
00192
00200 virtual void doubleToPWMOutput(sr_cod_decod_std_io::DigitalIo output_pin, uint16_t PWM_period, double PWM_ON_time);
00201
00209 virtual void uint16ToPWMOutput(sr_cod_decod_std_io::DigitalIo output_pin, uint16_t PWM_period, uint16_t PWM_ON_time);
00210
00211 protected:
00212
00213
00214
00215 unsigned n_digital_outputs_;
00216 unsigned n_analog_outputs_;
00217 unsigned n_digital_inputs_;
00218 unsigned n_analog_inputs_;
00219 unsigned n_PWM_outputs_;
00220
00221 unsigned int command_size_;
00222 unsigned int status_size_;
00223
00224 void digitalOutputCommandCB(const sr_ronex_msgs::BoolArrayConstPtr& msg);
00225 void analogOutputCommandCB(const std_msgs::UInt16MultiArrayConstPtr& msg);
00226 void PWMOutputCommandCB(const std_msgs::UInt16MultiArrayConstPtr& msg);
00227
00228
00229 boost::scoped_ptr<realtime_tools::RealtimePublisher<sr_ronex_msgs::BoolArray> > digital_input_state_publisher_;
00230 boost::scoped_ptr<realtime_tools::RealtimePublisher<std_msgs::UInt16MultiArray> >analog_input_state_publisher_;
00231
00232 realtime_tools::RealtimeBox<boost::shared_ptr<sr_ronex_msgs::BoolArray> > digital_output_;
00233 realtime_tools::RealtimeBox<boost::shared_ptr<std_msgs::UInt16MultiArray> > analog_output_;
00234 realtime_tools::RealtimeBox<boost::shared_ptr<std_msgs::UInt16MultiArray> > PWM_output_;
00235
00236 sr_ronex_msgs::BoolArray d_in_;
00237 std_msgs::UInt16MultiArray a_in_;
00238
00239 ros::Subscriber sub_digital_output_command_;
00240 ros::Subscriber sub_analog_output_command_;
00241 ros::Subscriber sub_PWM_output_command_;
00242
00243 ros::NodeHandle node_;
00244 };
00245 }
00246
00247
00248 #endif