Skip to content

Commit f0222ce

Browse files
committed
added travel
1 parent ee503d1 commit f0222ce

File tree

2 files changed

+13
-32
lines changed

2 files changed

+13
-32
lines changed

src/definitions/robot_definitions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
#define MOTOR_LIMIT 70.0 // Mechanical RPM limit speed of used motors
2727
#define MOTOR_CPR 6.0 // Resolution of the encoder
28-
#define MOTOR_GEAR_RATIO 150.0 // Gear ratio of the motor
28+
#define MOTOR_GEAR_RATIO 150.0 // Gear ratio of the motor, maybe 150.58?
2929

3030
const float MOTOR_RATIO = MOTOR_CPR*MOTOR_GEAR_RATIO;
3131

src/motor_control/motor_control.h

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class MotorControl{
5555

5656
float controller_period;
5757
float conversion_factor;
58+
float conversion_factor_travel;
5859
float measure;
5960
float last_measure;
6061

@@ -104,7 +105,8 @@ class MotorControl{
104105
id_memory=0;
105106
mean=0.0;
106107

107-
conversion_factor = 60.0*(1/MOTOR_RATIO)/(controller_period);
108+
conversion_factor_travel = (1.0/MOTOR_RATIO);
109+
conversion_factor = 60.0*(1.0/MOTOR_RATIO)/(controller_period);
108110
vel_pid = new PidController(kp,ki,kd,controller_period,CONTROL_LIMIT);
109111
}
110112

@@ -115,16 +117,6 @@ class MotorControl{
115117
vel_pid->reset();
116118
clearMemory();
117119
}
118-
/*
119-
bool setRPM(const float ref){
120-
if ((ref<MOTOR_LIMIT)&&(ref>-MOTOR_LIMIT)){
121-
reference = ref;
122-
vel_pid->setReference(reference);
123-
return true;
124-
}
125-
return false;
126-
}
127-
*/
128120

129121
float checkLimits(float value){
130122
if (value>CONTROL_LIMIT){
@@ -163,14 +155,6 @@ class MotorControl{
163155
}
164156

165157

166-
void test(){
167-
motor->setSpeed(2000);
168-
delay(1000);
169-
motor->setSpeed(-2000);
170-
delay(1000);
171-
}
172-
173-
174158
/*
175159
void update(){
176160
measure = encoder->getCount();
@@ -240,6 +224,7 @@ class MotorControl{
240224

241225
measure = encoder->getCount();
242226
encoder->reset();
227+
travel += measure*conversion_factor_travel;
243228
measure = measure*conversion_factor;
244229

245230
/* experimental
@@ -248,7 +233,6 @@ class MotorControl{
248233
}
249234
end */
250235

251-
252236
addMemory(measure);
253237

254238
/*
@@ -257,23 +241,13 @@ class MotorControl{
257241
motor->setSpeed(0);
258242
clearMemory();
259243
}
260-
261244
*/
262245

263-
264246
measure = meanMemory();
265247

266-
/*
267-
measure = encoder->getCount();
268-
encoder->reset();
269-
measure = measure*conversion_factor;
270-
*/
271-
272-
273248
//vel_pid->update(measure);
274249
//motor->setSpeed(vel_pid->getControlOutput());
275250

276-
277251
if (control_mode==CONTROL_MODE_LINEAR){
278252
if (step_index<iterations){
279253
step_index++;
@@ -289,7 +263,6 @@ class MotorControl{
289263
vel_pid->setReference(reference);
290264
}
291265

292-
293266
vel_pid->update(measure);
294267
motor->setSpeed(vel_pid->getControlOutput());
295268
}
@@ -326,6 +299,14 @@ class MotorControl{
326299
vel_pid->reset();
327300
}
328301

302+
void resetTravel(){
303+
travel=0;
304+
}
305+
306+
float getTravel(){
307+
return travel;
308+
}
309+
329310

330311
};
331312

0 commit comments

Comments
 (0)