Go to the documentation of this file.00001
00027 #ifndef SR06_H
00028 #define SR06_H
00029
00030 #include <ethercat_hardware/ethercat_device.h>
00031 #include <sr_edc_ethercat_drivers/sr0x.h>
00032 #include <realtime_tools/realtime_publisher.h>
00033 #include <std_msgs/Int16.h>
00034 #include <std_msgs/Float64MultiArray.h>
00035 #include <sr_robot_msgs/SimpleMotorFlasher.h>
00036 #include <pthread.h>
00037 #include <bfd.h>
00038 #include <boost/smart_ptr.hpp>
00039 #include <map>
00040 #include <boost/assign.hpp>
00041 #include <boost/algorithm/string.hpp>
00042 #include <boost/algorithm/string/find_iterator.hpp>
00043
00044 #include <sr_robot_lib/sr_hand_lib.hpp>
00045
00046 #include <sr_robot_msgs/EthercatDebug.h>
00047
00048 #include <sr_external_dependencies/types_for_external.h>
00049 extern "C"
00050 {
00051 #include <sr_external_dependencies/external/0220_palm_edc/0220_palm_edc_ethercat_protocol.h>
00052 }
00053
00054
00055 class SR06 : public SR0X
00056 {
00057 public:
00058 SR06();
00059 ~SR06();
00060
00061 void construct(EtherCAT_SlaveHandler *sh, int &start_address);
00062 int initialize(pr2_hardware_interface::HardwareInterface *hw, bool allow_unprogrammed=true);
00063 void multiDiagnostics(vector<diagnostic_msgs::DiagnosticStatus> &vec, unsigned char *buffer);
00064
00065 bool simple_motor_flasher(sr_robot_msgs::SimpleMotorFlasher::Request &req, sr_robot_msgs::SimpleMotorFlasher::Response &res);
00066 void packCommand(unsigned char *buffer, bool halt, bool reset);
00067 bool unpackState(unsigned char *this_buffer, unsigned char *prev_buffer);
00068 bool can_data_is_ack(ETHERCAT_CAN_BRIDGE_DATA * packet);
00069 void erase_flash();
00070
00071 bool read_flash(unsigned int offset, unsigned int baddr);
00072
00073 protected:
00074 int counter_;
00075 ETHERCAT_DATA_STRUCTURE_0200_PALM_EDC_STATUS data_;
00076 ros::NodeHandle nodehandle_;
00077
00078 typedef realtime_tools::RealtimePublisher<std_msgs::Int16> rt_pub_int16_t;
00079 std::vector< boost::shared_ptr<rt_pub_int16_t> > realtime_pub_;
00080
00082 boost::shared_ptr<realtime_tools::RealtimePublisher<std_msgs::Float64MultiArray> > extra_analog_inputs_publisher;
00083
00084 private:
00085
00086 static const unsigned int nb_sensors_const;
00087 static const unsigned int max_retry;
00088 static const unsigned short int max_iter_const;
00089 static const unsigned short int ros_pub_freq_const;
00090 static const unsigned short int device_pub_freq_const;
00091 static const unsigned char nb_publish_by_unpack_const;
00092 std::string firmware_file_name;
00093 pthread_mutex_t producing;
00094 ros::ServiceServer serviceServer;
00095
00096 bool flashing;
00097 ETHERCAT_CAN_BRIDGE_DATA can_message_;
00098 bool can_message_sent;
00099 bool can_packet_acked;
00100 bfd_byte *binary_content;
00101 unsigned int pos;
00102 unsigned int motor_being_flashed;
00103
00105 unsigned int zero_buffer_read;
00106
00107 boost::shared_ptr<shadow_robot::SrHandLib> sr_hand_lib;
00108
00113 short cycle_count;
00114
00116 boost::shared_ptr<realtime_tools::RealtimePublisher<sr_robot_msgs::EthercatDebug> > debug_publisher;
00117
00119 int can_bus_;
00120
00132 void send_CAN_msg(int8u can_bus, int16u msg_id, int8u msg_length, int8u msg_data[], int timeout, bool *timedout);
00133
00142 bool read_back_and_check_flash(unsigned int baddr, unsigned int total_size);
00143
00157 void find_address_range(bfd *fd, unsigned int *smallest_start_address, unsigned int *biggest_end_address);
00158
00168 bool read_content_from_object_file(bfd *fd, bfd_byte *content, unsigned int base_addr);
00169
00178 bool write_flash_data(unsigned int base_addr, unsigned int total_size);
00179
00187 static inline std::string get_filename( std::string full_path )
00188 {
00189 std::vector<std::string> splitted_string;
00190 boost::split(splitted_string, full_path, boost::is_any_of("/"));
00191 return splitted_string.back();
00192 }
00193
00194 };
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204 #endif
00205