Skip to content

Commit ce5d419

Browse files
committed
Major refactoring of diagnostics (CCNYRoboticsLab#20)
- Remove all diagnostics logic from phidget_api - Add diagnostics to phidgets_imu - Connect/disconnect/error states are propogated from callbacks - Periodic updates for diagnostics through processImuData() - Add Frequency and Timestamp (drift) diagnostics for imu/data_raw topic
1 parent 337ef11 commit ce5d419

File tree

7 files changed

+119
-72
lines changed

7 files changed

+119
-72
lines changed

phidgets_api/include/phidgets_api/phidget.h

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333

3434
#include <libphidgets/phidget21.h>
3535

36-
#include <diagnostic_updater/diagnostic_updater.h>
37-
#include <diagnostic_updater/publisher.h>
3836
#include <iostream>
3937
#include <algorithm>
4038
#include <string>
@@ -50,21 +48,6 @@ class Phidget
5048
Phidget();
5149
~Phidget();
5250

53-
/**@brief updater object of class Update. Used to add diagnostic tasks, set ID etc. refer package API.
54-
* Added for diagnostics */
55-
diagnostic_updater::Updater updater;
56-
57-
/**@brief This bool is public to allow to know when 1000s condition in imu_ros_i.cpp is over and need
58-
* to report a connection error.
59-
* Added for diagnostics */
60-
bool is_connected;
61-
62-
/**@brief Main diagnostic method that takes care of collecting diagnostic data.
63-
* @param stat The stat param is what is the diagnostic tasks are added two. Internally published by the
64-
* diagnostic_updater package.
65-
* Added for diagnostics */
66-
void phidgetsDiagnostics(diagnostic_updater::DiagnosticStatusWrapper &stat);
67-
6851
/**@brief Open a connection to a Phidget
6952
* @param serial_number The serial number of the phidget to which to attach (-1 will connect to any)*/
7053
int open(int serial_number);
@@ -111,10 +94,6 @@ class Phidget
11194

11295
private:
11396

114-
// Added for diagnostics
115-
bool is_error;
116-
int error_number;
117-
11897
static int AttachHandler(CPhidgetHandle handle, void *userptr);
11998
static int DetachHandler(CPhidgetHandle handle, void *userptr);
12099
static int ErrorHandler (CPhidgetHandle handle, void *userptr, int ErrorCode, const char *unknown);

phidgets_api/package.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@
1414
<author>Ivan Dryanovski</author>
1515

1616
<buildtool_depend>catkin</buildtool_depend>
17-
<build_depend>diagnostics_updater</build_depend>
18-
<build_depend>diagnostics_msgs</build_depend>
19-
20-
<run_depend>diagnostics_updater</run_depend>
21-
<run_depend>diagnostics_msgs</run_depend>
2217

2318
<build_depend>libusb-1.0-dev</build_depend>
2419
<build_depend>libphidgets</build_depend>

phidgets_api/src/phidget.cpp

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ namespace phidgets {
44

55
Phidget::Phidget()
66
{
7-
updater.add("IMU Driver Status", this, &phidgets::Phidget::phidgetsDiagnostics);
87

98
}
109

@@ -18,7 +17,7 @@ void Phidget::registerHandlers()
1817
{
1918
CPhidget_set_OnAttach_Handler(handle_, &Phidget::AttachHandler, this);
2019
CPhidget_set_OnDetach_Handler(handle_, &Phidget::DetachHandler, this);
21-
CPhidget_set_OnError_Handler (handle_, &Phidget::ErrorHandler, this);
20+
CPhidget_set_OnError_Handler (handle_, &Phidget::ErrorHandler, this);
2221
}
2322

2423
void Phidget::init(CPhidgetHandle handle)
@@ -28,7 +27,6 @@ void Phidget::init(CPhidgetHandle handle)
2827

2928
int Phidget::open(int serial_number)
3029
{
31-
updater.setHardwareID("none");
3230
return CPhidget_open(handle_, serial_number);
3331
}
3432

@@ -97,23 +95,16 @@ std::string Phidget::getErrorDescription(int errorCode)
9795

9896
void Phidget::attachHandler()
9997
{
100-
is_connected = true;
101-
updater.force_update();
10298
printf("Phidget attached (serial# %d)\n", getDeviceSerialNumber());
10399
}
104100

105101
void Phidget::detachHandler()
106102
{
107103
printf("Phidget detached (serial# %d)\n", getDeviceSerialNumber());
108-
is_connected = false;
109-
updater.force_update();
110104
}
111105

112106
void Phidget::errorHandler(int error)
113107
{
114-
is_error = true;
115-
updater.force_update();
116-
is_error = false;
117108
printf("Phidget error [%d]: %s\n", error, getErrorDescription(error).c_str());
118109
}
119110

@@ -135,27 +126,4 @@ int Phidget::ErrorHandler(CPhidgetHandle handle, void *userptr, int ErrorCode, c
135126
return 0;
136127
}
137128

138-
// Added for diagnostics
139-
void Phidget::phidgetsDiagnostics(diagnostic_updater::DiagnosticStatusWrapper &stat)
140-
{
141-
if (is_connected)
142-
{
143-
stat.summary(diagnostic_msgs::DiagnosticStatus::OK, "The Phidget is connected.");
144-
stat.add("Device Serial Number", getDeviceSerialNumber());
145-
stat.add("Device Name", getDeviceName());
146-
stat.add("Device Type", getDeviceType());
147-
}
148-
else
149-
{
150-
stat.summary(diagnostic_msgs::DiagnosticStatus::ERROR, "The Phidget is not connected. Check USB.");
151-
}
152-
153-
if (is_error && error_number != 0)
154-
{
155-
stat.summary(diagnostic_msgs::DiagnosticStatus::ERROR, "The Phidget is in Error.");
156-
stat.addf("Error Number","%f",error_number);
157-
stat.add("Error message",getErrorDescription(error_number));
158-
}
159-
}
160-
161129
} //namespace phidgets

phidgets_imu/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
cmake_minimum_required(VERSION 2.8.3)
22
project(phidgets_imu)
33

4-
find_package(catkin REQUIRED COMPONENTS geometry_msgs nodelet pluginlib phidgets_api roscpp sensor_msgs std_msgs std_srvs tf)
4+
find_package(catkin REQUIRED COMPONENTS diagnostic_msgs diagnostic_updater geometry_msgs nodelet pluginlib phidgets_api roscpp sensor_msgs std_msgs std_srvs tf)
55

66
find_package(Boost REQUIRED COMPONENTS thread)
77

88
catkin_package(
99
INCLUDE_DIRS include
1010
LIBRARIES phidgets_imu
1111
DEPENDS Boost
12-
CATKIN_DEPENDS geometry_msgs nodelet pluginlib phidgets_api roscpp sensor_msgs std_msgs std_srvs tf
12+
CATKIN_DEPENDS diagnostic_msgs diagnostic_updater geometry_msgs nodelet pluginlib phidgets_api roscpp sensor_msgs std_msgs std_srvs tf
1313
)
1414

1515
include_directories(include ${catkin_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS})

phidgets_imu/include/phidgets_imu/imu_ros_i.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44
#include <ros/ros.h>
55
#include <ros/service_server.h>
66
#include <boost/thread/mutex.hpp>
7+
#include <boost/shared_ptr.hpp>
78
#include <tf/transform_datatypes.h>
89
#include <sensor_msgs/Imu.h>
910
#include <std_srvs/Empty.h>
1011
#include <std_msgs/Bool.h>
1112
#include <geometry_msgs/Vector3Stamped.h>
13+
#include <diagnostic_updater/diagnostic_updater.h>
14+
#include <diagnostic_updater/publisher.h>
1215
#include <phidgets_api/imu.h>
1316

1417
using namespace std;
@@ -38,6 +41,16 @@ class ImuRosI : public Imu
3841
ros::Publisher cal_publisher_;
3942
ros::ServiceServer cal_srv_;
4043

44+
/**@brief updater object of class Update. Used to add diagnostic tasks, set ID etc. refer package API.
45+
* Added for diagnostics */
46+
diagnostic_updater::Updater diag_updater_;
47+
boost::shared_ptr<diagnostic_updater::TopicDiagnostic> imu_publisher_diag_ptr_;
48+
49+
// diagnostics
50+
bool is_connected_;
51+
int error_number_;
52+
double target_publish_freq_;
53+
4154
bool initialized_;
4255
boost::mutex mutex_;
4356
ros::Time last_imu_time_;
@@ -72,7 +85,16 @@ class ImuRosI : public Imu
7285
void calibrate();
7386
void initDevice();
7487
void dataHandler(CPhidgetSpatial_SpatialEventDataHandle* data, int count);
88+
void attachHandler();
89+
void detachHandler();
90+
void errorHandler(int error);
7591
void processImuData(CPhidgetSpatial_SpatialEventDataHandle* data, int i);
92+
93+
/**@brief Main diagnostic method that takes care of collecting diagnostic data.
94+
* @param stat The stat param is what is the diagnostic tasks are added two. Internally published by the
95+
* diagnostic_updater package.
96+
* Added for diagnostics */
97+
void phidgetsDiagnostics(diagnostic_updater::DiagnosticStatusWrapper &stat);
7698
};
7799

78100
} //namespace phidgets

phidgets_imu/package.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
<build_depend>std_msgs</build_depend>
2424
<build_depend>std_srvs</build_depend>
2525
<build_depend>tf</build_depend>
26+
<build_depend>diagnostic_updater</build_depend>
27+
<build_depend>diagnostic_msgs</build_depend>
28+
2629
<run_depend>geometry_msgs</run_depend>
2730
<run_depend>nodelet</run_depend>
2831
<run_depend>pluginlib</run_depend>
@@ -32,6 +35,8 @@
3235
<run_depend>std_msgs</run_depend>
3336
<run_depend>std_srvs</run_depend>
3437
<run_depend>tf</run_depend>
38+
<run_depend>diagnostic_updater</run_depend>
39+
<run_depend>diagnostic_msgs</run_depend>
3540

3641
<export>
3742
<nodelet plugin="${prefix}/phidgets_imu_nodelet.xml" />

0 commit comments

Comments
 (0)