Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Patte.h
00001 /** 00002 * Patte.h 00003 * 00004 * Created on: Mar 03, 2015 00005 * Author: salco 00006 */ 00007 #ifndef PATTE_H_ 00008 #define PATTE_H_ 00009 00010 #define NBR_SERVO 32 00011 #define DEFAULTPOSITION 150 00012 #define DEFAULTMAX 225 00013 #define DEFAULTMIN 75 00014 00015 //#include <string> 00016 #include <stdio.h> 00017 //#include "debug.h" 00018 00019 struct servo_t { 00020 char iD; //use for ssc-32 00021 // all value down is a pulse value between 750-2250 // 00022 unsigned char basePose; 00023 unsigned char max; 00024 unsigned char min; 00025 // mabey change curr for a integer to get more precision and less space // 00026 unsigned char curr; 00027 }; 00028 00029 class Patte 00030 { 00031 // number related to the SSC-32 // 00032 /*char m_numServo_Coxa; 00033 char m_numServo_Femur; 00034 char m_numServo_Tibia; 00035 char m_numServo_Tars;*/ 00036 char m_id; 00037 servo_t m_Coxa; 00038 servo_t m_Femur; 00039 servo_t m_Tibia; 00040 servo_t m_Tars; 00041 char buffer [50]; 00042 bool valuesChange; 00043 bool valuesCoxaChange; 00044 bool valuesFemurChange; 00045 bool valuesTibiaChange; 00046 bool valuesTarsChange; 00047 00048 public: 00049 Patte(char patteId,char coxaId,char femurId,char tibiaId,char tarsId) { 00050 m_id = patteId; 00051 valuesChange = false; 00052 00053 m_Coxa.iD = coxaId; 00054 m_Coxa.max = DEFAULTMAX; 00055 m_Coxa.min = DEFAULTMIN; 00056 m_Coxa.curr= DEFAULTPOSITION; 00057 valuesCoxaChange = false; 00058 00059 m_Femur.iD = femurId; 00060 m_Femur.max = DEFAULTMAX; 00061 m_Femur.min = DEFAULTMIN; 00062 m_Femur.curr= DEFAULTPOSITION; 00063 valuesFemurChange = false; 00064 00065 m_Tibia.iD = tibiaId; 00066 m_Tibia.max = DEFAULTMAX; 00067 m_Tibia.min = DEFAULTMIN; 00068 m_Tibia.curr= DEFAULTPOSITION; 00069 valuesTibiaChange = false; 00070 00071 m_Tars.iD = tarsId; 00072 m_Tars.max = DEFAULTMAX; 00073 m_Tars.min = DEFAULTMIN; 00074 m_Tars.curr= DEFAULTPOSITION; 00075 valuesTarsChange = false; 00076 } 00077 virtual ~Patte() {} 00078 char id(void) { 00079 return m_id; 00080 } 00081 const char* toString(void) { 00082 char buffer1[50]= {""}; 00083 char buffer2[50]= {""}; 00084 char buffer3[50]= {""}; 00085 char buffer4[50]= {""}; 00086 for(int i=0;i<50;i++)buffer[i]=0; 00087 00088 if(valuesCoxaChange) 00089 sprintf (buffer1,"#%d P%d0 ",m_Coxa.iD,m_Coxa.curr); 00090 if(valuesFemurChange) 00091 sprintf (buffer2,"#%d P%d0 ",m_Femur.iD,m_Femur.curr); 00092 if(valuesTibiaChange) 00093 sprintf (buffer3,"#%d P%d0 ",m_Tibia.iD,m_Tibia.curr); 00094 if(valuesTarsChange) 00095 sprintf (buffer4,"#%d P%d0",m_Tars.iD,m_Tars.curr); 00096 //sprintf (buffer,"#%d P%d0 #%d P%d0 #%d P%d0 #%d P%d0",m_Coxa.iD,m_Coxa.curr,m_Femur.iD,m_Femur.curr,m_Tibia.iD,m_Tibia.curr,m_Tars.iD,m_Tars.curr); 00097 sprintf (buffer,"%s%s%s%s",buffer1,buffer2,buffer3,buffer4); 00098 //debug(1,"\n\n\rintern string %s",buffer); 00099 00100 return buffer; 00101 } 00102 bool haveChange() { 00103 bool result = valuesChange|valuesCoxaChange|valuesFemurChange|valuesTibiaChange|valuesTarsChange; 00104 if(valuesChange)valuesChange=false; 00105 return result; 00106 } 00107 //setting Coxa // 00108 void set_Id_Coxa(char id) { 00109 m_Coxa.iD = id; 00110 valuesChange =true; 00111 } 00112 void set_PulseMax_Coxa(unsigned char value) { 00113 m_Coxa.max = value; 00114 valuesChange =true; 00115 } 00116 void set_PulseMin_Coxa(unsigned char value) { 00117 m_Coxa.min = value; 00118 valuesChange =true; 00119 } 00120 void set_DefaultPulse_Coxa(unsigned char value) { 00121 m_Coxa.basePose = value; 00122 valuesChange =true; 00123 } 00124 char get_Id_Coxa(void) { 00125 return m_Coxa.iD; 00126 } 00127 unsigned char get_PulseMax_Coxa(void) { 00128 return m_Coxa.max; 00129 } 00130 unsigned char get_PulseMin_Coxa(void) { 00131 return m_Coxa.min; 00132 } 00133 unsigned char get_DefaultPulse_Coxa(void) { 00134 return m_Coxa.basePose; 00135 } 00136 unsigned char get_CurrentPulse_Coxa(void) { 00137 return m_Coxa.curr; 00138 } 00139 //setting Femur // 00140 void set_Id_Femur(char id) { 00141 m_Femur.iD = id; 00142 valuesChange =true; 00143 } 00144 void set_PulseMax_Femur(unsigned char value) { 00145 m_Femur.max = value; 00146 valuesChange =true; 00147 } 00148 void set_PulseMin_Femur(unsigned char value) { 00149 m_Femur.min = value; 00150 valuesChange =true; 00151 } 00152 void set_DefaultPulse_Femur(unsigned char value) { 00153 m_Femur.basePose = value; 00154 valuesChange =true; 00155 } 00156 char get_Id_Femur(void) { 00157 return m_Femur.iD; 00158 } 00159 unsigned char get_PulseMax_Femur(void) { 00160 return m_Femur.max; 00161 } 00162 unsigned char get_PulseMin_Femur(void) { 00163 return m_Femur.min; 00164 } 00165 unsigned char get_DefaultPulse_Femur(void) { 00166 return m_Femur.basePose; 00167 } 00168 unsigned char get_CurrentPulse_Femur(void) { 00169 return m_Femur.curr; 00170 } 00171 //setting Tibia // 00172 void set_Id_Tibia(char id) { 00173 m_Tibia.iD = id; 00174 valuesChange =true; 00175 } 00176 void set_PulseMax_Tibia(unsigned char value) { 00177 m_Tibia.max = value; 00178 valuesChange =true; 00179 } 00180 void set_PulseMin_Tibia(unsigned char value) { 00181 m_Tibia.min = value; 00182 valuesChange =true; 00183 } 00184 void set_DefaultPulse_Tibia(unsigned char value) { 00185 m_Tibia.basePose = value; 00186 valuesChange =true; 00187 } 00188 char get_Id_Tibia(void) { 00189 return m_Tibia.iD; 00190 } 00191 unsigned char get_PulseMax_Tibia(void) { 00192 return m_Tibia.max; 00193 } 00194 unsigned char get_PulseMin_Tibia(void) { 00195 return m_Tibia.min; 00196 } 00197 unsigned char get_DefaultPulse_Tibia(void) { 00198 return m_Tibia.basePose; 00199 } 00200 unsigned char get_CurrentPulse_Tibia(void) { 00201 return m_Tibia.curr; 00202 } 00203 //setting Tars // 00204 void set_Id_Tars(char id) { 00205 m_Tars.iD = id; 00206 valuesChange =true; 00207 } 00208 void set_PulseMax_Tars(unsigned char value) { 00209 m_Tars.max = value; 00210 valuesChange =true; 00211 } 00212 void set_PulseMin_Tars(unsigned char value) { 00213 m_Tars.min = value; 00214 valuesChange =true; 00215 } 00216 void set_DefaultPulse_Tars(unsigned char value) { 00217 m_Tars.basePose = value; 00218 valuesChange =true; 00219 } 00220 char get_Id_Tars(void) { 00221 return m_Tars.iD; 00222 } 00223 unsigned char get_PulseMax_Tars(void) { 00224 return m_Tars.max; 00225 } 00226 unsigned char get_PulseMin_Tars(void) { 00227 return m_Tars.min; 00228 } 00229 unsigned char get_DefaultPulse_Tars(void) { 00230 return m_Tars.basePose; 00231 } 00232 unsigned char get_CurrentPulse_Tars(void) { 00233 return m_Tars.curr; 00234 } 00235 //setting All-in-one // 00236 void set_Id(char coxaId,char femurId,char tibiaId,char tarsId) { 00237 m_Coxa.iD = coxaId; 00238 m_Femur.iD= femurId; 00239 m_Tibia.iD= tibiaId; 00240 m_Tars.iD = tarsId; 00241 valuesChange =true; 00242 } 00243 void set_PulseMax(unsigned char coxaValue,unsigned char femurValue, 00244 unsigned char tibiaValue,unsigned char tarsValue) { 00245 m_Coxa.max = coxaValue; 00246 m_Femur.max= femurValue; 00247 m_Tibia.max= tibiaValue; 00248 m_Tars.max = tarsValue; 00249 valuesChange =true; 00250 } 00251 void set_PulseMin(unsigned char coxaValue,unsigned char femurValue, 00252 unsigned char tibiaValue,unsigned char tarsValue) { 00253 m_Coxa.min = coxaValue; 00254 m_Femur.min= femurValue; 00255 m_Tibia.min= tibiaValue; 00256 m_Tars.min = tarsValue; 00257 valuesChange =true; 00258 } 00259 void set_DefaultPulse(unsigned char coxaValue,unsigned char femurValue, 00260 unsigned char tibiaValue,unsigned char tarsValue) { 00261 m_Coxa.basePose = coxaValue; 00262 m_Femur.basePose= femurValue; 00263 m_Tibia.basePose= tibiaValue; 00264 m_Tars.basePose = tarsValue; 00265 valuesChange =true; 00266 } 00267 ////////// 00268 // Move // 00269 ////////// 00270 void move_Coxa(unsigned char value) { 00271 if((value >= m_Coxa.min)&&(value <= m_Coxa.max )&& (value != 255) ) { 00272 m_Coxa.curr = value; 00273 valuesCoxaChange =true; 00274 } 00275 else 00276 valuesCoxaChange =false; 00277 } 00278 void move_Femur(unsigned char value) { 00279 if((value >= m_Femur.min)&&(value <= m_Femur.max )&& (value != 255)) { 00280 m_Femur.curr = value; 00281 valuesFemurChange =true; 00282 } 00283 else 00284 valuesFemurChange =false; 00285 } 00286 void move_Tibia(unsigned char value) { 00287 if((value >= m_Tibia.min)&&(value <= m_Tibia.max )&& (value != 255)) { 00288 m_Tibia.curr = value; 00289 valuesTibiaChange =true; 00290 } 00291 else 00292 valuesTibiaChange =false; 00293 } 00294 void move_Tars(unsigned char value) { 00295 if((value >= m_Tars.min)&&(value <= m_Tars.max )&& (value != 255)) { 00296 m_Tars.curr = value; 00297 valuesTarsChange =true; 00298 } 00299 else 00300 valuesTarsChange =false; 00301 } 00302 void move(unsigned char coxaValue,unsigned char femurValue, 00303 unsigned char tibiaValue,unsigned char tarsValue) {//noob proof 00304 this->move_Coxa(coxaValue); 00305 this->move_Femur(femurValue); 00306 this->move_Tibia(tibiaValue); 00307 this->move_Tars(tarsValue); 00308 } 00309 }; 00310 #endif /* PATTE_H_ */
Generated on Tue Jul 12 2022 19:04:22 by
1.7.2