36 #include <boost/foreach.hpp> 37 #include <std_msgs/Int16.h> 42 #include <sr_utilities/sr_math_utils.hpp> 45 using std::stringstream;
50 #include <boost/static_assert.hpp> 59 #define ETHERCAT_STATUS_DATA_SIZE sizeof(ETHERCAT_DATA_STRUCTURE_0230_PALM_EDC_STATUS) 60 #define ETHERCAT_COMMAND_DATA_SIZE sizeof(ETHERCAT_DATA_STRUCTURE_0230_PALM_EDC_COMMAND) 62 #define ETHERCAT_CAN_BRIDGE_DATA_SIZE sizeof(ETHERCAT_CAN_BRIDGE_DATA) 64 #define ETHERCAT_COMMAND_DATA_ADDRESS PALM_0230_ETHERCAT_COMMAND_DATA_ADDRESS 65 #define ETHERCAT_STATUS_DATA_ADDRESS PALM_0230_ETHERCAT_STATUS_DATA_ADDRESS 66 #define ETHERCAT_CAN_BRIDGE_DATA_COMMAND_ADDRESS PALM_0230_ETHERCAT_CAN_BRIDGE_DATA_COMMAND_ADDRESS 67 #define ETHERCAT_CAN_BRIDGE_DATA_STATUS_ADDRESS PALM_0230_ETHERCAT_CAN_BRIDGE_DATA_STATUS_ADDRESS 79 : zero_buffer_read(0),
135 ROS_INFO(
"Finished constructing the SR08 driver");
151 ETHERCAT_DATA_STRUCTURE_0230_PALM_EDC_COMMAND> >(
183 d.name = prefix +
"EtherCAT Dual CAN Palm";
186 hwid << sh_->get_product_code() <<
"-" << sh_->get_serial();
187 d.hardware_id = hwid.str();
190 d.
addf(
"Position",
"%02d", sh_->get_ring_position());
191 d.
addf(
"Product Code",
"%d", sh_->get_product_code());
192 d.
addf(
"Serial Number",
"%d", sh_->get_serial());
193 d.
addf(
"Revision",
"%d", sh_->get_revision());
196 d.
addf(
"PIC idle time (in microsecs)",
"%d",
sr_hand_lib->main_pic_idle_time);
197 d.
addf(
"Min PIC idle time (since last diagnostics)",
"%d",
sr_hand_lib->main_pic_idle_time_min);
201 this->ethercatDiagnostics(d, 2);
231 SrEdc::packCommand(buffer, halt, reset);
233 ETHERCAT_DATA_STRUCTURE_0230_PALM_EDC_COMMAND *
command =
234 reinterpret_cast<ETHERCAT_DATA_STRUCTURE_0230_PALM_EDC_COMMAND *
>(buffer);
256 "Sending command : Type : 0x%02X ; data : 0x%04X 0x%04X 0x%04X 0x%04X 0x%04X 0x%04X 0x%04X 0x%04X 0x%04X" 257 " 0x%04X 0x%04X 0x%04X 0x%04X 0x%04X 0x%04X 0x%04X 0x%04X 0x%04X 0x%04X 0x%04X",
258 command->to_motor_data_type,
259 command->motor_data[0],
260 command->motor_data[1],
261 command->motor_data[2],
262 command->motor_data[3],
263 command->motor_data[4],
264 command->motor_data[5],
265 command->motor_data[6],
266 command->motor_data[7],
267 command->motor_data[8],
268 command->motor_data[9],
269 command->motor_data[10],
270 command->motor_data[11],
271 command->motor_data[12],
272 command->motor_data[13],
273 command->motor_data[14],
274 command->motor_data[15],
275 command->motor_data[16],
276 command->motor_data[17],
277 command->motor_data[18],
278 command->motor_data[19]);
303 ETHERCAT_DATA_STRUCTURE_0230_PALM_EDC_STATUS *status_data =
304 reinterpret_cast<ETHERCAT_DATA_STRUCTURE_0230_PALM_EDC_STATUS *
>(this_buffer + command_size_);
305 ETHERCAT_CAN_BRIDGE_DATA *can_data =
308 static unsigned int num_rxed_packets = 0;
324 debug_publisher->msg_.motor_data_type.data =
static_cast<int> (status_data->motor_data_type);
326 debug_publisher->msg_.which_motor_data_arrived = status_data->which_motor_data_arrived;
327 debug_publisher->msg_.which_motor_data_had_errors = status_data->which_motor_data_had_errors;
331 for (
unsigned int i = 0; i < 10; ++i)
333 debug_publisher->msg_.motor_data_packet_torque.push_back(status_data->motor_data_packet[i].torque);
334 debug_publisher->msg_.motor_data_packet_misc.push_back(status_data->motor_data_packet[i].misc);
338 static_cast<int32u>(status_data->tactile_data_type));
340 static_cast<int16u> (status_data->tactile_data_valid));
342 for (
unsigned int i = 0; i < 5; ++i)
345 static_cast<unsigned int> (static_cast<int16u> (status_data->tactile[i].word[0])));
357 float percentage_packet_loss = 100.f * (
static_cast<float>(
zero_buffer_read) /
358 static_cast<float>(num_rxed_packets));
360 ROS_DEBUG(
"Reception error detected : %d errors out of %d rxed packets (%2.3f%%) ; idle time %dus",
361 zero_buffer_read, num_rxed_packets, percentage_packet_loss, status_data->idle_time_us);
380 std_msgs::Float64MultiArray extra_analog_msg;
381 extra_analog_msg.layout.dim.resize(3);
382 extra_analog_msg.data.resize(3 + 3 + 4);
383 std::vector<double>
data;
385 extra_analog_msg.layout.dim[0].label =
"accelerometer";
386 extra_analog_msg.layout.dim[0].size = 3;
387 extra_analog_msg.data[0] = status_data->sensors[
ACCX];
388 extra_analog_msg.data[1] = status_data->sensors[
ACCY];
389 extra_analog_msg.data[2] = status_data->sensors[
ACCZ];
391 extra_analog_msg.layout.dim[1].label =
"gyrometer";
392 extra_analog_msg.layout.dim[1].size = 3;
393 extra_analog_msg.data[3] = status_data->sensors[
GYRX];
394 extra_analog_msg.data[4] = status_data->sensors[
GYRY];
395 extra_analog_msg.data[5] = status_data->sensors[
GYRZ];
397 extra_analog_msg.layout.dim[2].label =
"analog_inputs";
398 extra_analog_msg.layout.dim[2].size = 4;
399 extra_analog_msg.data[6] = status_data->sensors[
ANA0];
400 extra_analog_msg.data[7] = status_data->sensors[
ANA1];
401 extra_analog_msg.data[8] = status_data->sensors[
ANA2];
402 extra_analog_msg.data[9] = status_data->sensors[
ANA3];
438 int motor_id_tmp = board_id;
439 if (motor_id_tmp > 9)
449 *board_can_id = motor_id_tmp;
ros::NodeHandle nh_tilde_
virtual int initialize(hardware_interface::HardwareInterface *hw, bool allow_unprogrammed=true)
void summary(unsigned char lvl, const std::string s)
#define ETHERCAT_COMMAND_0230_AGREED_SIZE
virtual void get_board_id_and_can_bus(int board_id, int *can_bus, unsigned int *board_can_id)
boost::shared_ptr< realtime_tools::RealtimePublisher< std_msgs::Float64MultiArray > > extra_analog_inputs_publisher
Extra analog inputs real time publisher (+ accelerometer and gyroscope)
This is a ROS driver for Shadow Robot #8 EtherCAT product ID.
SR08()
Constructor of the SR08 driver.
virtual void construct(EtherCAT_SlaveHandler *sh, int &start_address)
Construct function, run at startup to set SyncManagers and FMMUs.
#define ETHERCAT_STATUS_0230_AGREED_SIZE
boost::shared_ptr< shadow_robot::SrMotorHandLib< ETHERCAT_DATA_STRUCTURE_0230_PALM_EDC_STATUS, ETHERCAT_DATA_STRUCTURE_0230_PALM_EDC_COMMAND > > sr_hand_lib
#define ETHERCAT_STATUS_DATA_SIZE
void addf(const std::string &key, const char *format,...)
virtual void packCommand(unsigned char *buffer, bool halt, bool reset)
packs the commands before sending them to the EtherCAT bus
BOOST_STATIC_ASSERT(sizeof(EDC_COMMAND)==4)
EDC_COMMAND_CAN_DIRECT_MODE
virtual void construct(EtherCAT_SlaveHandler *sh, int &start_address, unsigned int ethercat_command_data_size, unsigned int ethercat_status_data_size, unsigned int ethercat_can_bridge_data_size, unsigned int ethercat_command_data_address, unsigned int ethercat_status_data_address, unsigned int ethercat_can_bridge_data_command_address, unsigned int ethercat_can_bridge_data_status_address)
Construct function, run at startup to set SyncManagers and FMMUs.
#define ETHERCAT_COMMAND_DATA_ADDRESS
virtual int initialize(hardware_interface::HardwareInterface *hw, bool allow_unprogrammed=true)
ROSLIB_DECL std::string command(const std::string &cmd)
ros::NodeHandle nodehandle_
virtual void reinitialize_boards()
This function will call the reinitialization function for the boards attached to the CAN bus...
void build_CAN_message(ETHERCAT_CAN_BRIDGE_DATA *message)
#define ETHERCAT_COMMAND_DATA_SIZE
#define ETHERCAT_CAN_BRIDGE_DATA_COMMAND_ADDRESS
bool can_data_is_ack(ETHERCAT_CAN_BRIDGE_DATA *packet)
This function checks if the can packet in the unpackState() this_buffer is an ACK.
PLUGINLIB_EXPORT_CLASS(SR08, EthercatDevice)
#define ETHERCAT_CAN_BRIDGE_DATA_SIZE
TACTILE_SENSOR_TYPE_MCP320x_TACTILE
std::string device_joint_prefix_
virtual void multiDiagnostics(vector< diagnostic_msgs::DiagnosticStatus > &vec, unsigned char *buffer)
This function gives some diagnostics data.
virtual bool unpackState(unsigned char *this_buffer, unsigned char *prev_buffer)
This functions receives data from the EtherCAT bus.
#define ETHERCAT_STATUS_DATA_ADDRESS
#define ETHERCAT_CAN_BRIDGE_DATA_STATUS_ADDRESS
unsigned int zero_buffer_read
boost::shared_ptr< realtime_tools::RealtimePublisher< sr_robot_msgs::EthercatDebug > > debug_publisher
Debug real time publisher: publishes the raw ethercat data.