34 #include <boost/foreach.hpp> 35 #include <std_msgs/Int16.h> 41 #include <sr_utilities/sr_math_utils.hpp> 44 using std::stringstream;
49 #include <boost/static_assert.hpp> 58 #define ETHERCAT_STATUS_DATA_SIZE sizeof(ETHERCAT_DATA_STRUCTURE_0300_PALM_EDC_STATUS) 59 #define ETHERCAT_COMMAND_DATA_SIZE sizeof(ETHERCAT_DATA_STRUCTURE_0300_PALM_EDC_COMMAND) 61 #define ETHERCAT_CAN_BRIDGE_DATA_SIZE sizeof(ETHERCAT_CAN_BRIDGE_DATA) 63 #define ETHERCAT_COMMAND_DATA_ADDRESS PALM_0300_ETHERCAT_COMMAND_DATA_ADDRESS 64 #define ETHERCAT_STATUS_DATA_ADDRESS PALM_0300_ETHERCAT_STATUS_DATA_ADDRESS 65 #define ETHERCAT_CAN_BRIDGE_DATA_COMMAND_ADDRESS PALM_0300_ETHERCAT_CAN_BRIDGE_DATA_COMMAND_ADDRESS 66 #define ETHERCAT_CAN_BRIDGE_DATA_STATUS_ADDRESS PALM_0300_ETHERCAT_CAN_BRIDGE_DATA_STATUS_ADDRESS 78 : zero_buffer_read(0),
134 ROS_INFO(
"Finished constructing the SrEdcMuscle driver");
150 ETHERCAT_DATA_STRUCTURE_0300_PALM_EDC_COMMAND> >(
182 d.name = prefix +
"EtherCAT Dual CAN Palm";
185 hwid << sh_->get_product_code() <<
"-" << sh_->get_serial();
186 d.hardware_id = hwid.str();
189 d.
addf(
"Position",
"%02d", sh_->get_ring_position());
190 d.
addf(
"Product Code",
"%d", sh_->get_product_code());
191 d.
addf(
"Serial Number",
"%d", sh_->get_serial());
192 d.
addf(
"Revision",
"%d", sh_->get_revision());
195 d.
addf(
"PIC idle time (in microsecs)",
"%d",
sr_hand_lib->main_pic_idle_time);
196 d.
addf(
"Min PIC idle time (since last diagnostics)",
"%d",
sr_hand_lib->main_pic_idle_time_min);
200 this->ethercatDiagnostics(d, 2);
230 SrEdc::packCommand(buffer, halt, reset);
232 ETHERCAT_DATA_STRUCTURE_0300_PALM_EDC_COMMAND *
command =
233 reinterpret_cast<ETHERCAT_DATA_STRUCTURE_0300_PALM_EDC_COMMAND *
>(buffer);
250 "Sending command : Type : 0x%02X ; data : 0x%04X 0x%04X 0x%04X 0x%04X 0x%04X 0x%04X 0x%04X 0x%04X 0x%04X " 251 "0x%04X 0x%04X 0x%04X 0x%04X 0x%04X 0x%04X 0x%04X 0x%04X 0x%04X 0x%04X 0x%04X",
252 command->to_muscle_data_type,
253 command->muscle_data[0],
254 command->muscle_data[1],
255 command->muscle_data[2],
256 command->muscle_data[3],
257 command->muscle_data[4],
258 command->muscle_data[5],
259 command->muscle_data[6],
260 command->muscle_data[7],
261 command->muscle_data[8],
262 command->muscle_data[9],
263 command->muscle_data[10],
264 command->muscle_data[11],
265 command->muscle_data[12],
266 command->muscle_data[13],
267 command->muscle_data[14],
268 command->muscle_data[15],
269 command->muscle_data[16],
270 command->muscle_data[17],
271 command->muscle_data[18],
272 command->muscle_data[19]);
297 ETHERCAT_DATA_STRUCTURE_0300_PALM_EDC_STATUS *status_data =
298 reinterpret_cast<ETHERCAT_DATA_STRUCTURE_0300_PALM_EDC_STATUS *
>(this_buffer + command_size_);
299 ETHERCAT_CAN_BRIDGE_DATA *can_data =
302 static unsigned int num_rxed_packets = 0;
326 for (
unsigned int i = 0; i < 8; ++i)
329 (status_data->muscle_data_packet[i].packed.pressure0_H << 8) +
330 (status_data->muscle_data_packet[i].packed.pressure0_M << 4) +
331 status_data->muscle_data_packet[i].packed.pressure0_L);
333 (status_data->muscle_data_packet[i].packed.pressure1_H << 8) +
334 (status_data->muscle_data_packet[i].packed.pressure1_M << 4) +
335 status_data->muscle_data_packet[i].packed.pressure1_L);
337 (status_data->muscle_data_packet[i].packed.pressure2_H << 8) +
338 (status_data->muscle_data_packet[i].packed.pressure2_M << 4) +
339 status_data->muscle_data_packet[i].packed.pressure2_L);
341 (status_data->muscle_data_packet[i].packed.pressure3_H << 8) +
342 (status_data->muscle_data_packet[i].packed.pressure3_M << 4) +
343 status_data->muscle_data_packet[i].packed.pressure3_L);
345 (status_data->muscle_data_packet[i].packed.pressure4_H << 8) +
346 (status_data->muscle_data_packet[i].packed.pressure4_M << 4) +
347 status_data->muscle_data_packet[i].packed.pressure4_L);
357 static_cast<unsigned int> (
static_cast<int32u> (status_data->tactile_data_type));
359 static_cast<unsigned int> (
static_cast<int16u> (status_data->tactile_data_valid));
361 for (
unsigned int i = 0; i < 5; ++i)
364 static_cast<unsigned int> (static_cast<int16u> (status_data->tactile[i].word[0])));
376 float percentage_packet_loss = 100.f * (
static_cast<float>(
zero_buffer_read)/ static_cast<float>(num_rxed_packets));
378 ROS_DEBUG(
"Reception error detected : %d errors out of %d rxed packets (%2.3f%%) ; idle time %dus",
379 zero_buffer_read, num_rxed_packets, percentage_packet_loss, status_data->idle_time_us);
398 std_msgs::Float64MultiArray extra_analog_msg;
399 extra_analog_msg.layout.dim.resize(3);
400 extra_analog_msg.data.resize(3 + 3 + 4);
401 std::vector<double>
data;
403 extra_analog_msg.layout.dim[0].label =
"accelerometer";
404 extra_analog_msg.layout.dim[0].size = 3;
405 extra_analog_msg.data[0] = status_data->sensors[
ACCX];
406 extra_analog_msg.data[1] = status_data->sensors[
ACCY];
407 extra_analog_msg.data[2] = status_data->sensors[
ACCZ];
409 extra_analog_msg.layout.dim[1].label =
"gyrometer";
410 extra_analog_msg.layout.dim[1].size = 3;
411 extra_analog_msg.data[3] = status_data->sensors[
GYRX];
412 extra_analog_msg.data[4] = status_data->sensors[
GYRY];
413 extra_analog_msg.data[5] = status_data->sensors[
GYRZ];
415 extra_analog_msg.layout.dim[2].label =
"analog_inputs";
416 extra_analog_msg.layout.dim[2].size = 4;
417 extra_analog_msg.data[6] = status_data->sensors[
ANA0];
418 extra_analog_msg.data[7] = status_data->sensors[
ANA1];
419 extra_analog_msg.data[8] = status_data->sensors[
ANA2];
420 extra_analog_msg.data[9] = status_data->sensors[
ANA3];
456 int muscle_driver_board_id_tmp = board_id;
457 if (muscle_driver_board_id_tmp > 1)
459 muscle_driver_board_id_tmp -= 2;
467 *board_can_id = muscle_driver_board_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_CAN_BRIDGE_DATA_COMMAND_ADDRESS
void addf(const std::string &key, const char *format,...)
boost::shared_ptr< realtime_tools::RealtimePublisher< sr_robot_msgs::EthercatDebug > > debug_publisher
Debug real time publisher: publishes the raw ethercat data.
#define ETHERCAT_COMMAND_0300_AGREED_SIZE
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.
virtual void reinitialize_boards()
This function will call the reinitialization function for the boards attached to the CAN bus...
#define ETHERCAT_COMMAND_DATA_SIZE
ROSLIB_DECL std::string command(const std::string &cmd)
#define ETHERCAT_CAN_BRIDGE_DATA_SIZE
#define ETHERCAT_STATUS_0300_AGREED_SIZE
#define ETHERCAT_STATUS_DATA_SIZE
ros::NodeHandle nodehandle_
#define ETHERCAT_CAN_BRIDGE_DATA_STATUS_ADDRESS
void build_CAN_message(ETHERCAT_CAN_BRIDGE_DATA *message)
virtual void get_board_id_and_can_bus(int board_id, int *can_bus, unsigned int *board_can_id)
This is a ROS driver for Shadow Robot EtherCAT dual CAN muscle hand.
virtual void construct(EtherCAT_SlaveHandler *sh, int &start_address)
Construct function, run at startup to set SyncManagers and FMMUs.
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.
#define ETHERCAT_COMMAND_DATA_ADDRESS
#define ETHERCAT_STATUS_DATA_ADDRESS
virtual void multiDiagnostics(vector< diagnostic_msgs::DiagnosticStatus > &vec, unsigned char *buffer)
This function gives some diagnostics data.
std::string device_joint_prefix_
virtual bool unpackState(unsigned char *this_buffer, unsigned char *prev_buffer)
This functions receives data from the EtherCAT bus.
virtual int initialize(hardware_interface::HardwareInterface *hw, bool allow_unprogrammed=true)
PLUGINLIB_EXPORT_CLASS(SrEdcMuscle, EthercatDevice)
unsigned int zero_buffer_read
boost::shared_ptr< shadow_robot::SrMuscleHandLib< ETHERCAT_DATA_STRUCTURE_0300_PALM_EDC_STATUS, ETHERCAT_DATA_STRUCTURE_0300_PALM_EDC_COMMAND > > sr_hand_lib
boost::shared_ptr< realtime_tools::RealtimePublisher< std_msgs::Float64MultiArray > > extra_analog_inputs_publisher
Extra analog inputs real time publisher (+ accelerometer and gyroscope)
virtual void packCommand(unsigned char *buffer, bool halt, bool reset)
packs the commands before sending them to the EtherCAT bus
SrEdcMuscle()
Constructor of the SrEdcMuscle driver.