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 using namespace std;
00040
00041 namespace sr_cod_decod_std_io
00042 {
00043 enum DigitalIo
00044 {
00045 DigitalIo0,
00046 DigitalIo1,
00047 DigitalIo2,
00048 DigitalIo3
00049 };
00050
00051 enum AnalogOutput
00052 {
00053 AnalogOutput0,
00054 AnalogOutput1
00055 };
00056
00057 enum AnalogInput
00058 {
00059 AnlogInput0,
00060 AnlogInput1,
00061 AnlogInput2,
00062 AnlogInput3
00063 };
00064 }
00065
00066 namespace sr_cod_decod
00067 {
00068 class CodDecodStdIo: public CodDecod
00069 {
00070 public:
00071 CodDecodStdIo();
00072
00073 virtual void construct(hardware_interface::HardwareInterface *hw, EtherCAT_SlaveHandler *sh, int n_digital_outputs, 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 unsigned n_digital_outputs_;
00215 unsigned n_analog_outputs_;
00216 unsigned n_digital_inputs_;
00217 unsigned n_analog_inputs_;
00218 unsigned n_PWM_outputs_;
00219
00220 unsigned int command_size_;
00221 unsigned int status_size_;
00222
00223 void digitalOutputCommandCB(const sr_ronex_msgs::BoolArrayConstPtr& msg);
00224 void analogOutputCommandCB(const std_msgs::UInt16MultiArrayConstPtr& msg);
00225 void PWMOutputCommandCB(const std_msgs::UInt16MultiArrayConstPtr& msg);
00226
00227
00228 boost::scoped_ptr<realtime_tools::RealtimePublisher<sr_ronex_msgs::BoolArray> > digital_input_state_publisher_;
00229 boost::scoped_ptr<realtime_tools::RealtimePublisher<std_msgs::UInt16MultiArray> >analog_input_state_publisher_;
00230
00231 realtime_tools::RealtimeBox<boost::shared_ptr<sr_ronex_msgs::BoolArray> > digital_output_;
00232 realtime_tools::RealtimeBox<boost::shared_ptr<std_msgs::UInt16MultiArray> > analog_output_;
00233 realtime_tools::RealtimeBox<boost::shared_ptr<std_msgs::UInt16MultiArray> > PWM_output_;
00234
00235 sr_ronex_msgs::BoolArray d_in_;
00236 std_msgs::UInt16MultiArray a_in_;
00237
00238 ros::Subscriber sub_digital_output_command_;
00239 ros::Subscriber sub_analog_output_command_;
00240 ros::Subscriber sub_PWM_output_command_;
00241
00242 ros::NodeHandle node_;
00243
00244
00245 };
00246 }
00247
00248
00249 #endif