00001
00030 #ifndef SHADOWHAND_H_
00031 # define SHADOWHAND_H_
00032
00033 #include <ros/ros.h>
00034 #include <string>
00035 #include <vector>
00036 #include <map>
00037
00038
00039 #include "diagnostic_msgs/SelfTest.h"
00040 #include "self_test/self_test.h"
00041
00042 #include <boost/smart_ptr.hpp>
00043 #include <boost/thread.hpp>
00044 #include <boost/noncopyable.hpp>
00045 #include <boost/assign.hpp>
00046
00047 #ifdef GAZEBO
00048 #include <sensor_msgs/JointState.h>
00049 #endif
00050
00051
00052 namespace debug_values
00053 {
00055 static const std::map<const std::string, const unsigned int> names_and_offsets
00056 = boost::assign::map_list_of ("Sensor PID last in", 0) \
00057 ("Sensor PID iState", 1) \
00058 ("Sensor PID last D", 2) \
00059 ("Sensor PID last out", 3) \
00060 ("PID last in", 4) \
00061 ("PID iState", 5) \
00062 ("PID last D", 6) \
00063 ("PID last out", 7) \
00064 ("Strain Gauge Offset 0", 8) \
00065 ("Strain Gauge Offset 1", 9) \
00066 ("Num setup Msgs received", 10) \
00067 ("Num sensor Msgs received", 11) \
00068 ("Sensor Val (motor set P)", 12) \
00069 ("Sensor Val (motor sensor)", 13) \
00070 ("H-Bridge Duty", 14) \
00071 ("Duty Temp", 15) ;
00072 }
00073
00074
00075 namespace shadowrobot
00076 {
00080 struct JointData
00081 {
00082 double position;
00083 double target;
00084 double temperature;
00085 double current;
00086 double force;
00087 std::string flags;
00088 int jointIndex;
00089 double min;
00090 double max;
00091 short isJointZero;
00092
00099 int publisher_index;
00100 ros::Time last_pos_time;
00101 double last_pos;
00102 double velocity;
00103
00104 JointData() :
00105 position(0.0), target(0.0), temperature(0.0), current(0.0), force(0.0), flags(""), jointIndex(0), min(0.0), max(90.0), isJointZero(0), publisher_index(0), last_pos_time(0.0), last_pos(0.0), velocity(0.0)
00106 {
00107 }
00108
00109 JointData(JointData& jd) :
00110 position(jd.position), target(jd.target), temperature(jd.temperature), current(jd.current), force(jd.force),
00111 flags(jd.flags), jointIndex(jd.jointIndex), min(jd.min), max(jd.max), isJointZero(jd.isJointZero), publisher_index(jd.publisher_index), last_pos_time(jd.last_pos_time), last_pos(jd.last_pos), velocity(jd.velocity)
00112 {
00113 }
00114
00115 JointData(const JointData& jd) :
00116 position(jd.position), target(jd.target), temperature(jd.temperature), current(jd.current), force(jd.force),
00117 flags(jd.flags), jointIndex(jd.jointIndex), min(jd.min), max(jd.max), isJointZero(jd.isJointZero), publisher_index(jd.publisher_index), last_pos_time(jd.last_pos_time), last_pos(jd.last_pos), velocity(jd.velocity)
00118 {
00119 }
00120 };
00121
00125 enum controller_parameters
00126 {
00127 PARAM_sensor,
00128 PARAM_target,
00129 PARAM_valve,
00130 PARAM_deadband,
00131 PARAM_p,
00132 PARAM_i,
00133 PARAM_d,
00134 PARAM_imax,
00135 PARAM_output_offset,
00136 PARAM_shift,
00137 PARAM_output_max,
00138
00139 PARAM_motor_maxforce,
00140 PARAM_motor_safeforce,
00141 PARAM_force_p,
00142 PARAM_force_i,
00143 PARAM_force_d,
00144 PARAM_force_imax,
00145 PARAM_force_out_shift,
00146 PARAM_force_deadband,
00147 PARAM_force_offset,
00148 PARAM_sensor_imax,
00149 PARAM_sensor_out_shift,
00150 PARAM_sensor_deadband,
00151 PARAM_sensor_offset,
00152 PARAM_max_temperature,
00153 PARAM_max_current,
00154 PARAM_type_of_sensor,
00155 PARAM_type_of_setpoint
00157
00158 };
00159
00163 struct Parameters
00164 {
00166 std::string name;
00168 std::string value;
00169
00170 Parameters() :
00171 name(""), value("")
00172 {
00173 }
00174
00175 Parameters( Parameters& param ) :
00176 name(param.name), value(param.value)
00177 {
00178 }
00179
00180 Parameters( const Parameters& param ) :
00181 name(param.name), value(param.value)
00182 {
00183 }
00184 };
00185
00189 struct JointControllerData
00190 {
00191 std::vector<Parameters> data;
00192
00193 JointControllerData() :
00194 data()
00195 {
00196 }
00197
00198 JointControllerData( JointControllerData& jcd ) :
00199 data(jcd.data)
00200 {
00201 }
00202
00203 JointControllerData( const JointControllerData& jcd ) :
00204 data(jcd.data)
00205 {
00206 }
00207 };
00208
00209
00210
00214 struct DiagnosticData
00215 {
00217 std::string joint_name;
00219 short level;
00220
00222 std::string flags;
00223
00225 int target_sensor_num;
00227 int position_sensor_num;
00229 double target;
00230
00232 std::map<std::string, int> debug_values;
00234 double position;
00235
00237 double temperature;
00239 double current;
00241 double force;
00242
00243
00244 uint64_t num_sensor_msgs_received;
00245
00246 };
00247
00255 class SRArticulatedRobot : boost::noncopyable
00256 {
00257 public:
00261 SRArticulatedRobot()
00262 {
00263 }
00264 ;
00265
00269 ~SRArticulatedRobot()
00270 {
00271 }
00272 ;
00273
00275 typedef std::map<std::string, JointData> JointsMap;
00277 typedef std::map<std::string, enum controller_parameters> ParametersMap;
00278
00285 virtual short sendupdate( std::string joint_name, double target ) = 0;
00286
00292 virtual JointData getJointData( std::string joint_name ) = 0;
00293
00298 virtual JointsMap getAllJointsData() = 0;
00299
00306 virtual short setContrl( std::string contrlr_name, JointControllerData ctrlr_data ) = 0;
00307
00313 virtual JointControllerData getContrl( std::string contrlr_name ) = 0;
00314
00322 virtual short setConfig( std::vector<std::string> myConfig ) = 0;
00323
00330 virtual void getConfig( std::string joint_name ) = 0;
00331
00336 virtual std::vector<DiagnosticData> getDiagnostics() = 0;
00337
00339 JointsMap joints_map;
00340
00342 ParametersMap parameters_map;
00343
00344 boost::mutex joints_map_mutex;
00345 boost::mutex parameters_map_mutex;
00346 boost::mutex controllers_map_mutex;
00347
00348 protected:
00350 boost::shared_ptr<self_test::TestRunner> self_test;
00351 #ifdef GAZEBO
00352 std::vector<ros::Publisher> gazebo_publishers;
00353 ros::Subscriber gazebo_subscriber;
00354 #endif
00355 };
00356
00357 }
00358
00359
00360
00361
00362
00363
00364
00365
00366 #endif