00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00034 #ifndef SERVOHUMANOID_H
00035 #define SERVOHUMANOID_H
00036
00037 #define PI 3.141592653589793238462643383279502884197
00038
00039
00040 #define LEFT 1
00041 #define RIGHT -1
00042
00043
00044 #define ARM_LENGTH 100
00045 #define FOREARM_LENGTH 110
00046 #define LEG_LENGTH 200
00047 #define THIGH_LENGTH 210
00048 #define FOOT_LENGTH 220
00049 #define ANKLE_HEIGHT 230
00050 #define FOOT_WIDTH 240
00051
00052
00053
00054
00055 #include <math.h>
00056 #include <stdio.h>
00057 #include <stdlib.h>
00058 #include <iostream>
00059 #include <ros/ros.h>
00060
00061 #include <Eigen/Dense>
00062 #include <hitec5980sg/hitec5980sg.h>
00063
00064
00065 class ServoHumanoid
00066 {
00067
00068 public:
00069 ServoHumanoid(const char* path);
00070
00071 void HomePosition(void);
00072
00073 short unsigned int MoveJoint(short int id, double joint_angle);
00074
00075 short unsigned int SetJointSpeed(short int id, unsigned int speed);
00076
00077 short unsigned int Torso_Rotation_Movement(double joint_angle);
00078
00079 short unsigned int Torso_Flexion_Extension_Movement(double joint_angle);
00080
00081 short unsigned int Torso_Lateral_Flexion_Extension_Movement(double joint_angle);
00082
00083 short unsigned int Ankle_Flexion_Movement(short int id, double joint_angle);
00084
00085 short unsigned int Ankle_Inversion_Eversion_Movement(short int id, double joint_angle);
00086
00087 short unsigned int Knee_Movement(short int id, double joint_angle);
00088
00089 short unsigned int Hip_Abduction_Hiperabduction_Movement(short int id, double joint_angle);
00090
00091 short unsigned int Hip_Flexion_Movement(short int id, double joint_angle);
00092
00093 double ConvertServoValueByID(int id, short unsigned int servo_value);
00094
00095 double Hip_Flexion_ServoValue_Conversion(short int id, short unsigned int servo_value);
00096
00097 double Hip_Abduction_Hiperabduction_ServoValue_Conversion(short int id, short unsigned int servo_value);
00098
00099 double Knee_Flexion_ServoValue_Conversion(short int id, short unsigned int servo_value);
00100
00101 double Ankle_Flexion_ServoValue_Conversion(short int id, short unsigned int servo_value);
00102
00103 double Ankle_Inversion_Eversion_ServoValue_Conversion(short int id, short unsigned int servo_value);
00104
00105 double Torso_Flexion_Extension_ServoValue_Conversion(short unsigned int servo_value);
00106
00107 double Torso_Rotation_ServoValue_Conversion(short unsigned int servo_value);
00108
00109 double Torso_Lateral_Flexion_Extension_ServoValue_Conversion(short unsigned int servo_value);
00110
00111
00112
00113 struct RoboState
00114 {
00115
00116 short unsigned int op_mode;
00117
00118 double speed_g_static;
00119
00120 double speed_now[13];
00121
00122 double speed_wanted[13];
00123
00124
00125 double joint_now[13];
00126
00127
00128 double joint_wanted[13];
00129
00130 } RoboState;
00131
00132 private:
00133
00134
00135 hitec_5980SG* hitec;
00136
00137
00138 void SetParameters(void);
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00152 struct{
00154 double arm_length;
00155
00157 double forearm_length;
00158
00160 double shin_length;
00161
00163 double thigh_length;
00164
00166 double foot_length;
00167
00169 double foot_width;
00170
00172 double ankle_height;
00173 } robot_dimensions;
00174
00175
00176
00177
00181 struct{
00182
00183
00184
00186 double head_min_tilt;
00187
00189 double head_max_tilt;
00190
00191
00192
00193
00194
00196 double shoulder_min_flexion;
00197
00199 double shoulder_max_flexion;
00200
00201
00202
00203
00205 double shoulder_min_abduction;
00206
00208 double shoulder_max_abduction;
00209
00210
00211
00212
00214 double elbow_min_flexion;
00215
00217 double elbow_max_flexion;
00218
00219
00220
00221
00222
00224 double torso_min_rotation;
00225
00227 double torso_max_rotation;
00228
00229
00230
00231
00233 double torso_min_flexion;
00234
00236 double torso_max_flexion;
00237
00238
00239
00240
00242 double torso_min_lateral_flexion;
00243
00245 double torso_max_lateral_flexion;
00246
00247
00248
00249
00251 double ankle_min_inversion;
00252
00254 double ankle_max_inversion;
00255
00256
00257
00258
00260 double ankle_min_flexion;
00261
00263 double ankle_max_flexion;
00264
00265
00266
00267
00269 double knee_min_flexion;
00270
00272 double knee_max_flexion;
00273
00274
00275
00276
00278 double hip_min_abduction;
00279
00281 double hip_max_abduction;
00282
00283
00284
00285
00287 double hip_min_flexion;
00288
00290 double hip_max_flexion;
00291 } robot_joint_limits;
00292
00296 struct{
00298 double head_servo_offset;
00299
00301 double shoulder_flexion_servo_offset_left;
00302
00304 double shoulder_flexion_servo_offset_right;
00305
00307 double shoulder_abduction_servo_offset_left;
00308
00310 double shoulder_abduction_servo_offset_right;
00311
00313 double elbow_flexion_servo_offset_left;
00314
00316 double elbow_flexion_servo_offset_right;
00317
00319 double torso_rotation_servo_offset;
00320
00322 double torso_flexion_servo_offset;
00323
00325 double torso_lateral_flexion_servo_offset;
00326
00328 double knee_flexion_b_value_left;
00329
00331 double knee_flexion_b_value_right;
00332
00334 double hip_flexion_b_value_left;
00335
00337 double hip_flexion_b_value_right;
00338 } robot_servo_conversion;
00339
00343 struct {
00345 double head_joint_offset;
00346
00348 double shoulder_flexion_joint_offset_left;
00349
00351 double shoulder_flexion_joint_offset_right;
00352
00354 double shoulder_abduction_joint_offset_left;
00355
00357 double shoulder_abduction_joint_offset_right;
00358
00360 double elbow_flexion_joint_offset_left;
00361
00363 double elbow_flexion_joint_offset_right;
00364
00366 double torso_rotation_joint_offset;
00367
00369 double torso_flexion_joint_offset;
00370
00372 double torso_lateral_flexion_joint_offset;
00373
00375 double knee_flexion_joint_offset_left;
00376
00378 double knee_flexion_joint_offset_right;
00379
00381 double hip_flexion_joint_offset_left;
00382
00384 double hip_flexion_joint_offset_right;
00385
00387 double hip_abduction_joint_offset_left;
00388
00390 double hip_abduction_joint_offset_right;
00391
00393 double feet_flexion_joint_offset_left;
00394
00396 double feet_flexion_joint_offset_right;
00397
00399 double feet_inversion_joint_offset_left;
00400
00402 double feet_inversion_joint_offset_right;
00403
00404 } joint_offset;
00405
00406
00410 struct{
00412 double foot_mass;
00413
00415 double shin_mass;
00416
00418 double thigh_mass;
00419
00420 } robot_element_mass;
00421
00425 struct{
00427 Eigen::Vector3d foot_CoM;
00428
00430 Eigen::Vector3d shin_CoM;
00431
00433 Eigen::Vector3d thigh_CoM;
00434
00435 } robot_relative_COM;
00436
00437
00438 };
00439
00440 #endif