servohumanoid.h
Go to the documentation of this file.
00001 /**************************************************************************************************
00002  Software License Agreement (BSD License)
00003 
00004  Copyright (c) 2011-2013, LAR toolkit developers - University of Aveiro - http://lars.mec.ua.pt
00005  All rights reserved.
00006 
00007  Redistribution and use in source and binary forms, with or without modification, are permitted
00008  provided that the following conditions are met:
00009 
00010   *Redistributions of source code must retain the above copyright notice, this list of
00011    conditions and the following disclaimer.
00012   *Redistributions in binary form must reproduce the above copyright notice, this list of
00013    conditions and the following disclaimer in the documentation and/or other materials provided
00014    with the distribution.
00015   *Neither the name of the University of Aveiro nor the names of its contributors may be used to
00016    endorse or promote products derived from this software without specific prior written permission.
00017  
00018  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
00019  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
00020  FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
00021  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00022  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
00024  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00025  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 ***************************************************************************************************/
00027 
00034 #ifndef SERVOHUMANOID_H
00035 #define SERVOHUMANOID_H
00036 
00037 #define PI 3.141592653589793238462643383279502884197
00038 
00039 //Defines for left or right side limbs
00040 #define LEFT     1
00041 #define RIGHT   -1
00042 
00043 // Define for dimension extraction
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 // #define PFLN {printf("Passing through File [%s] @ Line [%d].\n", __FILE__, __LINE__);}
00053 
00054 //includes
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         //void Inv_Kin_3DOF_Detached_Leg(double X, double Y, double Z, double *req_angle);
00112         
00113         struct RoboState
00114         {
00115             // general speed configurations
00116             short unsigned int op_mode;
00117             
00118             double speed_g_static;
00119             //double speed_now[13];
00120             double speed_wanted[13];
00121             
00122             // Actual positions
00123             double joint_now[13];
00124         
00125             // wanted positions
00126             double joint_wanted[13];
00127             
00128         } RoboState;
00129         
00130     private:
00131 
00132         // servomotor Class
00133         hitec_5980SG* hitec;
00134         
00135         // Func to set parameters
00136         void SetParameters(void);
00137         
00138         /*~~~~~~~~~~~~~~~~~~~~~~~~~ 
00139         || miscellaneous variables ||
00140           ~~~~~~~~~~~~~~~~~~~~~~~~~*/
00141         //definition of PI as a double for calculations
00142         //double PI;
00143         
00144         /*~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
00145         ||      robot dimensions     ||
00146           ~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
00150         struct{
00152         double arm_length;
00153         
00155         double forearm_length;
00156         
00158         double shin_length;
00159         
00161         double thigh_length;
00162         
00164         double foot_length;
00165         
00167         double foot_width;
00168         
00170         double ankle_height;
00171         } robot_dimensions;
00172         
00173         //   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
00174         // || robot joint limitation variables ||
00175         //   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00179         struct{
00180         // <<<< HEAD >>>>   
00181         // Motion range [0...10] vertical to tilted
00182         
00184         double head_min_tilt;
00185         
00187         double head_max_tilt;
00188         
00189         /* <<<< ARMS >>>>*/
00190         /* Shoulder flexion
00191         Motion range [-40...140] back to front
00192         */
00194         double shoulder_min_flexion;
00195         
00197         double shoulder_max_flexion;
00198         
00199         /* Shoulder abduction
00200         Motion range [0...180] back to front
00201         */
00203         double shoulder_min_abduction;
00204         
00206         double shoulder_max_abduction;
00207         
00208         /* Elbow flexion
00209         Motion range [0...120] streched to flected
00210         */
00212         double elbow_min_flexion;
00213         
00215         double elbow_max_flexion;
00216         
00217         /* <<<< TORSO >>>>*/
00218         /* Torso rotation
00219         Motion range [-90...90] left to right
00220         */    
00222         double torso_min_rotation;
00223         
00225         double torso_max_rotation;
00226         
00227         /* Torso flexion
00228         Motion range [-15...90] left to right
00229         */    
00231         double torso_min_flexion;
00232         
00234         double torso_max_flexion;
00235         
00236         /* Torso lateral flexion
00237         Motion range [-90...90] left to right
00238         */
00240         double torso_min_lateral_flexion;
00241         
00243         double torso_max_lateral_flexion;
00244         
00245         /* Ankle inversion
00246         Motion range [-30...45] inside to outside
00247         */
00249         double ankle_min_inversion;
00250         
00252         double ankle_max_inversion;
00253         
00254         /* Ankle flexion
00255         Motion range [-40...20] inside to outside
00256         */
00258         double ankle_min_flexion;
00259         
00261         double ankle_max_flexion;
00262         
00263         /* Knee flexion
00264         Motion range [0...130] inside to outside
00265         */
00267         double knee_min_flexion;
00268         
00270         double knee_max_flexion;
00271         
00272         /* Hip abduction
00273         Motion range [-40...45] inside to outside
00274         */
00276         double hip_min_abduction;
00277         
00279         double hip_max_abduction;
00280         
00281         /* hip flexion
00282         Motion range [-30...120] inside to outside
00283         */
00285         double hip_min_flexion;
00286         
00288         double hip_max_flexion;
00289         } robot_joint_limits;
00290         
00294         struct{
00296           double head_servo_offset;
00297     
00299           double shoulder_flexion_servo_offset_left;
00300     
00302           double shoulder_flexion_servo_offset_right;
00303     
00305           double shoulder_abduction_servo_offset_left;
00306     
00308           double shoulder_abduction_servo_offset_right;
00309     
00311           double elbow_flexion_servo_offset_left;
00312     
00314           double elbow_flexion_servo_offset_right;
00315     
00317           double torso_rotation_servo_offset;
00318     
00320           double torso_flexion_servo_offset;
00321     
00323           double torso_lateral_flexion_servo_offset;
00324     
00326           double knee_flexion_b_value_left;
00327     
00329           double knee_flexion_b_value_right;
00330     
00332           double hip_flexion_b_value_left;
00333     
00335           double hip_flexion_b_value_right;
00336         } robot_servo_conversion;
00337 
00341         struct {
00343           double head_joint_offset;
00344     
00346           double shoulder_flexion_joint_offset_left;
00347     
00349           double shoulder_flexion_joint_offset_right;
00350     
00352           double shoulder_abduction_joint_offset_left;
00353     
00355           double shoulder_abduction_joint_offset_right;
00356     
00358           double elbow_flexion_joint_offset_left;
00359     
00361           double elbow_flexion_joint_offset_right;
00362     
00364           double torso_rotation_joint_offset;
00365     
00367           double torso_flexion_joint_offset;
00368     
00370           double torso_lateral_flexion_joint_offset;
00371     
00373           double knee_flexion_joint_offset_left;
00374     
00376           double knee_flexion_joint_offset_right;
00377     
00379           double hip_flexion_joint_offset_left;
00380     
00382           double hip_flexion_joint_offset_right;
00383 
00385           double hip_abduction_joint_offset_left;
00386     
00388           double hip_abduction_joint_offset_right;
00389 
00391           double feet_flexion_joint_offset_left;
00392     
00394           double feet_flexion_joint_offset_right;
00395 
00397           double feet_inversion_joint_offset_left;
00398     
00400           double feet_inversion_joint_offset_right;
00401             
00402         } joint_offset;
00403 
00404         
00408         struct{
00410           double foot_mass;
00411           
00413           double shin_mass;
00414           
00416           double thigh_mass;
00417           
00418         } robot_element_mass;
00419         
00423         struct{
00425           Eigen::Vector3d foot_CoM;
00426           
00428           Eigen::Vector3d shin_CoM;
00429           
00431           Eigen::Vector3d thigh_CoM;
00432           
00433         } robot_relative_COM;
00434         
00435     
00436 };
00437 
00438 #endif /* SERVOHUMANOID_H */ 


humanoid_control
Author(s): Emilio Estrelinha, César Sousa
autogenerated on Thu Nov 20 2014 11:35:26