@@ -105,12 +105,12 @@ void startStopAutomomousDrive(bool aDoStart, uint8_t aDriveMode) {
105
105
#if defined(USE_ENCODER_MOTOR_CONTROL) && defined(ENABLE_PATH_INFO_PAGE)
106
106
if (sStepMode != MODE_SINGLE_STEP) {
107
107
// add last driven distance to path
108
- insertToPath (RobotCarPWMMotorControl .rightCarMotor .LastRideEncoderCount , sLastDegreesTurned , true );
108
+ insertToPath (RobotCar .rightCarMotor .LastRideEncoderCount , sLastDegreesTurned , true );
109
109
}
110
110
#endif
111
111
DistanceServoWriteAndDelay (90 );
112
112
sDriveMode = MODE_MANUAL_DRIVE;
113
- RobotCarPWMMotorControl .stop (STOP_MODE_RELEASE);
113
+ RobotCar .stop (STOP_MODE_RELEASE);
114
114
TouchButtonDistanceFeedbackMode.removeButton (COLOR16_WHITE);
115
115
}
116
116
@@ -141,7 +141,7 @@ int postProcessAndCollisionDetection() {
141
141
*/
142
142
void driveCollisonAvoidingOneStep () {
143
143
144
- bool tCarIsStopped = RobotCarPWMMotorControl .isStopped ();
144
+ bool tCarIsStopped = RobotCar .isStopped ();
145
145
/*
146
146
* Check step conditions if step should happen
147
147
*/
@@ -158,10 +158,10 @@ void driveCollisonAvoidingOneStep() {
158
158
*/
159
159
if (sNextRotationDegree == MINIMUM_DISTANCE_TOO_SMALL) {
160
160
// go backwards and do a new scan
161
- RobotCarPWMMotorControl .goDistanceMillimeter (100 , DIRECTION_BACKWARD, &loopGUI);
161
+ RobotCar .goDistanceMillimeter (100 , DIRECTION_BACKWARD, &loopGUI);
162
162
} else {
163
163
// rotate and go
164
- RobotCarPWMMotorControl .rotate (sNextRotationDegree , sTurnMode , false , &loopGUI); // do not use slow speed
164
+ RobotCar .rotate (sNextRotationDegree , sTurnMode , false , &loopGUI); // do not use slow speed
165
165
// wait to really stop after turning
166
166
delay (100 );
167
167
sLastDegreesTurned = sNextRotationDegree ;
@@ -173,21 +173,21 @@ void driveCollisonAvoidingOneStep() {
173
173
*/
174
174
if (sStepMode == MODE_SINGLE_STEP) {
175
175
// Go fixed distance
176
- RobotCarPWMMotorControl .goDistanceMillimeter (sCentimetersDrivenPerScan * 10 , DIRECTION_FORWARD, &loopGUI);
176
+ RobotCar .goDistanceMillimeter (sCentimetersDrivenPerScan * 10 , DIRECTION_FORWARD, &loopGUI);
177
177
} else
178
178
/*
179
179
* Continuous mode, start car or let it run (do nothing)
180
180
*/
181
181
if (tCarIsStopped) {
182
- RobotCarPWMMotorControl .startRampUpAndWaitForDriveSpeedPWM (DIRECTION_FORWARD, &loopGUI);
182
+ RobotCar .startRampUpAndWaitForDriveSpeedPWM (DIRECTION_FORWARD, &loopGUI);
183
183
}
184
184
}
185
185
186
186
/*
187
187
* Here car is moving
188
188
*/
189
189
#if defined(USE_ENCODER_MOTOR_CONTROL)
190
- uint16_t tStepStartDistanceCount = RobotCarPWMMotorControl .rightCarMotor .EncoderCount ; // get count before distance scanning
190
+ uint16_t tStepStartDistanceCount = RobotCar .rightCarMotor .EncoderCount ; // get count before distance scanning
191
191
#endif
192
192
bool tCurrentPageIsAutomaticControl = (sCurrentPage == PAGE_AUTOMATIC_CONTROL);
193
193
@@ -207,13 +207,13 @@ void driveCollisonAvoidingOneStep() {
207
207
* compute distance driven for one US scan
208
208
* First check if car is stopped
209
209
*/
210
- if (!RobotCarPWMMotorControl .isStopped () && sStepMode != MODE_SINGLE_STEP) {
210
+ if (!RobotCar .isStopped () && sStepMode != MODE_SINGLE_STEP) {
211
211
/*
212
212
* No stop here => distance is valid
213
213
* One encoder count is 11 mm so just take the count as centimeter here :-)
214
214
*/
215
215
#if defined(USE_ENCODER_MOTOR_CONTROL)
216
- sCentimetersDrivenPerScan = RobotCarPWMMotorControl .rightCarMotor .EncoderCount - tStepStartDistanceCount;
216
+ sCentimetersDrivenPerScan = RobotCar .rightCarMotor .EncoderCount - tStepStartDistanceCount;
217
217
#endif
218
218
if (tCurrentPageIsAutomaticControl) {
219
219
char tStringBuffer[6 ];
@@ -230,7 +230,7 @@ void driveCollisonAvoidingOneStep() {
230
230
/*
231
231
* Stop if rotation requested or single step
232
232
*/
233
- RobotCarPWMMotorControl .stopAndWaitForIt ();
233
+ RobotCar .stopAndWaitForIt ();
234
234
#if defined(USE_ENCODER_MOTOR_CONTROL)
235
235
#if defined(ENABLE_PATH_INFO_PAGE)
236
236
@@ -241,17 +241,17 @@ void driveCollisonAvoidingOneStep() {
241
241
insertToPath (CENTIMETER_PER_RIDE * 2 , sLastDegreesTurned , true );
242
242
} else {
243
243
// add last driven distance to path
244
- insertToPath (RobotCarPWMMotorControl .rightCarMotor .LastRideEncoderCount , sLastDegreesTurned , true );
244
+ insertToPath (RobotCar .rightCarMotor .LastRideEncoderCount , sLastDegreesTurned , true );
245
245
}
246
246
#endif
247
247
} else {
248
248
/*
249
249
* No stop, just continue => overwrite last path element with current riding distance and try to synchronize motors
250
250
*/
251
251
#if defined(ENABLE_PATH_INFO_PAGE)
252
- insertToPath (RobotCarPWMMotorControl .rightCarMotor .EncoderCount , sLastDegreesTurned , false );
252
+ insertToPath (RobotCar .rightCarMotor .EncoderCount , sLastDegreesTurned , false );
253
253
#endif
254
- // RobotCarPWMMotorControl .rightCarMotor.synchronizeMotor(&RobotCarPWMMotorControl .leftCarMotor, 100);
254
+ // RobotCar .rightCarMotor.synchronizeMotor(&RobotCar .leftCarMotor, 100);
255
255
#endif
256
256
}
257
257
@@ -347,7 +347,7 @@ void driveFollowerModeOneStep() {
347
347
*/
348
348
if (sDoStep ) { // Check if we shall do this step
349
349
DistanceServoWriteAndDelay (90 , false ); // reset distance servo direction
350
- RobotCarPWMMotorControl .rotate (sNextRotationDegree , TURN_FORWARD, false , &loopGUI); // do not use slow speed
350
+ RobotCar .rotate (sNextRotationDegree , TURN_FORWARD, false , &loopGUI); // do not use slow speed
351
351
sNextRotationDegree = 0 ;
352
352
}
353
353
@@ -363,7 +363,7 @@ void driveFollowerModeOneStep() {
363
363
/*
364
364
* No target found -> stop car, clear display and start scanning in the next step
365
365
*/
366
- RobotCarPWMMotorControl .stop (STOP_MODE_RELEASE);
366
+ RobotCar .stop (STOP_MODE_RELEASE);
367
367
clearPrintedForwardDistancesInfos (false ); // clear area for next scan results
368
368
sNextRotationDegree = NO_TARGET_FOUND; // scan at next step
369
369
} else {
@@ -372,29 +372,37 @@ void driveFollowerModeOneStep() {
372
372
* Target found -> keep distance
373
373
*/
374
374
int tSpeedPWM = 0 ;
375
+ uint8_t tDirection = DIRECTION_STOP;
375
376
if (tCentimeter > FOLLOWER_DISTANCE_MAXIMUM_CENTIMETER) {
376
377
/*
377
378
* Target too far, but below scan threshold -> drive FORWARD with speed proportional to the gap
379
+ * We start with DEFAULT_START_SPEED_PWM, which is adjusted to avoid undervoltage which prevents moving
378
380
*/
379
- tSpeedPWM = RobotCarPWMMotorControl. rightCarMotor . DriveSpeedPWMFor2Volt / 2
381
+ tSpeedPWM = PWMDcMotor::getVoltageAdjustedSpeedPWM (DEFAULT_START_SPEED_PWM, sVINVoltage )
380
382
+ (tCentimeter - FOLLOWER_DISTANCE_MAXIMUM_CENTIMETER) * 2 ;
383
+ tDirection = DIRECTION_FORWARD;
381
384
382
385
} else if (tCentimeter < FOLLOWER_DISTANCE_MINIMUM_CENTIMETER) {
383
386
/*
384
387
* Target too close -> drive BACKWARD with speed proportional to the gap
388
+ * We start with DEFAULT_START_SPEED_PWM, which is adjusted to avoid undervoltage which prevents moving
385
389
*/
386
- tSpeedPWM = -(RobotCarPWMMotorControl. rightCarMotor . DriveSpeedPWMFor2Volt / 2
387
- + (FOLLOWER_DISTANCE_MINIMUM_CENTIMETER - tCentimeter) * 4 ) ;
388
-
390
+ tSpeedPWM = PWMDcMotor::getVoltageAdjustedSpeedPWM (DEFAULT_START_SPEED_PWM, sVINVoltage )
391
+ + (FOLLOWER_DISTANCE_MINIMUM_CENTIMETER - tCentimeter) * 4 ;
392
+ tDirection = DIRECTION_BACKWARD;
389
393
}
394
+
390
395
if (tSpeedPWM != 0 ) {
391
- RobotCarPWMMotorControl.setSpeedPWMAndDirection (tSpeedPWM);
396
+ if (tSpeedPWM > MAX_SPEED_PWM) {
397
+ tSpeedPWM = MAX_SPEED_PWM;
398
+ }
399
+ RobotCar.setSpeedPWMAndDirection (tSpeedPWM, tDirection);
392
400
} else {
393
401
/*
394
402
* Target is in the right distance -> stop
395
403
*/
396
- if (!RobotCarPWMMotorControl .isStopped ()) {
397
- RobotCarPWMMotorControl .stop (STOP_MODE_RELEASE);
404
+ if (!RobotCar .isStopped ()) {
405
+ RobotCar .stop (STOP_MODE_RELEASE);
398
406
}
399
407
}
400
408
}
@@ -406,8 +414,8 @@ void driveFollowerModeOneStep() {
406
414
*/
407
415
sDoStep = false ;
408
416
delayAndLoopGUI (500 );
409
- if (!RobotCarPWMMotorControl .isStopped ()) {
410
- RobotCarPWMMotorControl .stop (STOP_MODE_RELEASE);
417
+ if (!RobotCar .isStopped ()) {
418
+ RobotCar .stop (STOP_MODE_RELEASE);
411
419
}
412
420
}
413
421
delayAndLoopGUI (100 ); // the IR sensor takes 39 ms for one measurement
0 commit comments