35 #include <sys/select.h>
36 #include <sys/types.h>
43 #include <boost/thread/thread.hpp>
46 #include <sys/types.h>
47 #include <sys/socket.h>
48 #include <netinet/in.h>
49 #include <arpa/inet.h>
50 #include <sys/socket.h>
52 #include <sys/ioctl.h>
56 #include "diagnostic_msgs/DiagnosticMessage.h"
74 #define PRINT_IF_CHANGED(val) \
75 for (int counter = 0; counter < 3; counter++) \
77 if (tmsg.cb[counter].val##_count != newtmsg.cb[counter].val##_count) \
79 ROS_INFO("Power board: CB%i "#val" event count changed to %i.", counter, newtmsg.cb[counter].val##_count);\
92 #undef PRINT_IF_CHANGED
104 #define PRINT_IF_CHANGED(val) \
105 if (pmsg.status.val##_status != newpmsg.status.val##_status) \
107 ROS_INFO("Power board: status of "#val" changed to %i.", newpmsg.status.val##_status); \
116 #undef PRINT_IF_CHANGED
127 fprintf(stderr,
"No devices to send command to\n");
131 int selected_device = -1;
133 for (
unsigned i = 0; i<
Devices.size(); ++i) {
134 if (
Devices[i]->getPowerMessage().
header.serial_num == serial_number) {
140 if ((selected_device < 0) || (selected_device >= (
int)
Devices.size())) {
141 fprintf(stderr,
"Device number must be between 0 and %u\n",
Devices.size()-1);
146 assert(device != NULL);
149 if ((circuit_breaker < 0) || (circuit_breaker > 2)) {
150 fprintf(stderr,
"Circuit breaker number must be between 0 and 2\n");
157 char command_enum =
NONE;
167 else if (
command ==
"disable") {
184 CommandMessage cmdmsg;
185 memset(&cmdmsg, 0,
sizeof(cmdmsg));
188 cmdmsg.header.serial_num = device->
getPowerMessage().header.serial_num;
190 strncpy(cmdmsg.header.text,
"power command message",
sizeof(cmdmsg.header.text));
191 cmdmsg.command.CB0_command =
NONE;
192 cmdmsg.command.CB1_command =
NONE;
193 cmdmsg.command.CB2_command =
NONE;
194 if (circuit_breaker==0) {
195 cmdmsg.command.CB0_command = command_enum;
197 else if (circuit_breaker==1) {
198 cmdmsg.command.CB1_command = command_enum;
200 else if (circuit_breaker==2) {
201 cmdmsg.command.CB2_command = command_enum;
203 else if (circuit_breaker==-1) {
204 cmdmsg.command.CB0_command = command_enum;
205 cmdmsg.command.CB1_command = command_enum;
206 cmdmsg.command.CB2_command = command_enum;
209 cmdmsg.command.flags =
flags;
215 ROS_DEBUG(
"Send to Serial=%u, revision=%u", cmdmsg.header.serial_num, cmdmsg.header.message_revision);
216 ROS_DEBUG(
"Sent command %s(%d) to device %d, circuit %d",
217 command.c_str(), command_enum, selected_device, circuit_breaker);
264 ROS_WARN(
"Got message with incorrect message revision %u\n",
msg->header.message_revision);
269 for (
unsigned i = 0; i<
Devices.size(); ++i) {
270 if (
Devices[i]->getPowerMessage().
header.serial_num ==
msg->header.serial_num) {
271 boost::mutex::scoped_lock(library_lock_);
273 Devices[i]->setPowerMessage(*msg);
289 ROS_WARN(
"Got message with incorrect message revision %u\n",
msg->header.message_revision);
294 for (
unsigned i = 0; i<
Devices.size(); ++i) {
295 if (
Devices[i]->getPowerMessage().
header.serial_num ==
msg->header.serial_num) {
296 boost::mutex::scoped_lock(library_lock_);
297 Devices[i]->setTransitionMessage(*msg);
313 log4cxx::LoggerPtr my_logger = log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME);
315 if( my_logger->getLevel() == 0 )
322 advertise<diagnostic_msgs::DiagnosticMessage>(
"/diagnostics", 2);
326 pr2_power_board::PowerBoardCommand::Response &res_)
333 void PowerBoard::sendDiagnostic()
342 for (
unsigned i = 0; i<
Devices.size(); ++i)
344 diagnostic_msgs::DiagnosticArray msg_out;
351 ss <<
"Power board " << pmesg->header.serial_num;
352 stat.name = ss.str();
362 const StatusStruct *status = &pmesg->status;
365 ROS_DEBUG(
" Serial = %u", pmesg->header.serial_num);
367 stat.
add(
"Serial Number", pmesg->header.serial_num);
369 ROS_DEBUG(
" Current = %f", status->input_current);
370 stat.
add(
"Input Current", status->input_current);
373 ROS_DEBUG(
" Input = %f", status->input_voltage);
374 stat.
add(
"Input Voltage", status->input_voltage);
376 ROS_DEBUG(
" DCDC 12 = %f", status->DCDC_12V_out_voltage);
377 stat.
add(
"DCDC12", status->DCDC_12V_out_voltage);
379 ROS_DEBUG(
" DCDC 15 = %f", status->DCDC_19V_out_voltage);
380 stat.
add(
"DCDC 15", status->DCDC_19V_out_voltage);
382 ROS_DEBUG(
" CB0 (Base) = %f", status->CB0_voltage);
383 stat.
add(
"Breaker 0 Voltage", status->CB0_voltage);
385 ROS_DEBUG(
" CB1 (R-arm) = %f", status->CB1_voltage);
386 stat.
add(
"Breaker 1 Voltage", status->CB1_voltage);
388 ROS_DEBUG(
" CB2 (L-arm) = %f", status->CB2_voltage);
389 stat.
add(
"Breaker 2 Voltage", status->CB2_voltage);
391 ROS_DEBUG(
" Board Temp = %f", status->ambient_temp);
392 stat.
add(
"Board Temperature", status->ambient_temp);
395 ROS_DEBUG(
" Fan 0 = %u", status->fan0_speed);
396 stat.
add(
"Fan 0 Speed", status->fan0_speed);
398 ROS_DEBUG(
" Fan 1 = %u", status->fan1_speed);
399 stat.
add(
"Fan 1 Speed", status->fan1_speed);
401 ROS_DEBUG(
" Fan 2 = %u", status->fan2_speed);
402 stat.
add(
"Fan 2 Speed", status->fan2_speed);
404 ROS_DEBUG(
" Fan 3 = %u", status->fan3_speed);
405 stat.
add(
"Fan 3 Speed", status->fan3_speed);
421 ROS_DEBUG(
" CB0 (Base) = %s", (status->CB0_status) ?
"On" :
"Off");
422 stat.
add(
"Breaker 0 Status", (status->CB0_status) ?
"On" :
"Off");
424 ROS_DEBUG(
" CB1 (R-arm) = %s", (status->CB1_status) ?
"On" :
"Off");
425 stat.
add(
"Breaker 1 Status", (status->CB1_status) ?
"On" :
"Off");
427 ROS_DEBUG(
" CB2 (L-arm) = %s", (status->CB2_status) ?
"On" :
"Off");
428 stat.
add(
"Breaker 2 Status", (status->CB2_status) ?
"On" :
"Off");
430 ROS_DEBUG(
" estop_button= %x", (status->estop_button_status));
431 stat.
add(
"RunStop Button Status", status->estop_button_status);
433 ROS_DEBUG(
" estop_status= %x", (status->estop_status));
434 stat.
add(
"RunStop Status", status->estop_status);
438 stat.
add(
"PCA", status->pca_rev);
441 stat.
add(
"PCB", status->pcb_rev);
443 ROS_DEBUG(
" Major = %c", status->major_rev);
444 stat.
add(
"Major Revision", status->major_rev);
446 ROS_DEBUG(
" Minor = %c", status->minor_rev);
447 stat.
add(
"Minor Revision", status->minor_rev);
449 stat.
add(
"Min Voltage", status->min_input_voltage);
450 stat.
add(
"Max Current", status->max_input_current);
453 for(
int cb_index=0; cb_index < 3; ++cb_index)
455 const TransitionCount *trans = &tmsg->cb[cb_index];
458 ss <<
"CB" << cb_index <<
" Stop Count";
459 stat.
add(ss.str(), trans->stop_count);
462 ss <<
"CB" << cb_index <<
" E-Stop Count";
463 stat.
add(ss.str(), trans->estop_count);
466 ss <<
"CB" << cb_index <<
" Trip Count";
467 stat.
add(ss.str(), trans->trip_count);
470 ss <<
"CB" << cb_index <<
" 18V Fail Count";
471 stat.
add(ss.str(), trans->fail_18V_count);
474 ss <<
"CB" << cb_index <<
" Disable Count";
475 stat.
add(ss.str(), trans->disable_count);
478 ss <<
"CB" << cb_index <<
" Start Count";
479 stat.
add(ss.str(), trans->start_count);
482 ss <<
"CB" << cb_index <<
" Pump Fail Count";
483 stat.
add(ss.str(), trans->pump_fail_count);
486 ss <<
"CB" << cb_index <<
" Reset Count";
487 stat.
add(ss.str(), trans->reset_count);
490 msg_out.status.push_back(stat);
493 pub.publish(msg_out);
505 for (
unsigned i=0; i<
Devices.size(); ++i){
521 static PowerMessage pm;
524 pm.header.serial_num = 0xDADABABA;
527 pm.header.data_length =
sizeof(pm.status);
578 int main(
int argc,
char** argv)