Skip to content

Commit c421e02

Browse files
committed
Renamed instance from RobotCarPWMMotorControl to RobotCar
1 parent a0634f1 commit c421e02

19 files changed

+617
-445
lines changed

src/AutonomousDrive.hpp

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,12 @@ void startStopAutomomousDrive(bool aDoStart, uint8_t aDriveMode) {
105105
#if defined(USE_ENCODER_MOTOR_CONTROL) && defined(ENABLE_PATH_INFO_PAGE)
106106
if (sStepMode != MODE_SINGLE_STEP) {
107107
// add last driven distance to path
108-
insertToPath(RobotCarPWMMotorControl.rightCarMotor.LastRideEncoderCount, sLastDegreesTurned, true);
108+
insertToPath(RobotCar.rightCarMotor.LastRideEncoderCount, sLastDegreesTurned, true);
109109
}
110110
#endif
111111
DistanceServoWriteAndDelay(90);
112112
sDriveMode = MODE_MANUAL_DRIVE;
113-
RobotCarPWMMotorControl.stop(STOP_MODE_RELEASE);
113+
RobotCar.stop(STOP_MODE_RELEASE);
114114
TouchButtonDistanceFeedbackMode.removeButton(COLOR16_WHITE);
115115
}
116116

@@ -141,7 +141,7 @@ int postProcessAndCollisionDetection() {
141141
*/
142142
void driveCollisonAvoidingOneStep() {
143143

144-
bool tCarIsStopped = RobotCarPWMMotorControl.isStopped();
144+
bool tCarIsStopped = RobotCar.isStopped();
145145
/*
146146
* Check step conditions if step should happen
147147
*/
@@ -158,10 +158,10 @@ void driveCollisonAvoidingOneStep() {
158158
*/
159159
if (sNextRotationDegree == MINIMUM_DISTANCE_TOO_SMALL) {
160160
// go backwards and do a new scan
161-
RobotCarPWMMotorControl.goDistanceMillimeter(100, DIRECTION_BACKWARD, &loopGUI);
161+
RobotCar.goDistanceMillimeter(100, DIRECTION_BACKWARD, &loopGUI);
162162
} else {
163163
// 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
165165
// wait to really stop after turning
166166
delay(100);
167167
sLastDegreesTurned = sNextRotationDegree;
@@ -173,21 +173,21 @@ void driveCollisonAvoidingOneStep() {
173173
*/
174174
if (sStepMode == MODE_SINGLE_STEP) {
175175
// Go fixed distance
176-
RobotCarPWMMotorControl.goDistanceMillimeter(sCentimetersDrivenPerScan * 10, DIRECTION_FORWARD, &loopGUI);
176+
RobotCar.goDistanceMillimeter(sCentimetersDrivenPerScan * 10, DIRECTION_FORWARD, &loopGUI);
177177
} else
178178
/*
179179
* Continuous mode, start car or let it run (do nothing)
180180
*/
181181
if (tCarIsStopped) {
182-
RobotCarPWMMotorControl.startRampUpAndWaitForDriveSpeedPWM(DIRECTION_FORWARD, &loopGUI);
182+
RobotCar.startRampUpAndWaitForDriveSpeedPWM(DIRECTION_FORWARD, &loopGUI);
183183
}
184184
}
185185

186186
/*
187187
* Here car is moving
188188
*/
189189
#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
191191
#endif
192192
bool tCurrentPageIsAutomaticControl = (sCurrentPage == PAGE_AUTOMATIC_CONTROL);
193193

@@ -207,13 +207,13 @@ void driveCollisonAvoidingOneStep() {
207207
* compute distance driven for one US scan
208208
* First check if car is stopped
209209
*/
210-
if (!RobotCarPWMMotorControl.isStopped() && sStepMode != MODE_SINGLE_STEP) {
210+
if (!RobotCar.isStopped() && sStepMode != MODE_SINGLE_STEP) {
211211
/*
212212
* No stop here => distance is valid
213213
* One encoder count is 11 mm so just take the count as centimeter here :-)
214214
*/
215215
#if defined(USE_ENCODER_MOTOR_CONTROL)
216-
sCentimetersDrivenPerScan = RobotCarPWMMotorControl.rightCarMotor.EncoderCount - tStepStartDistanceCount;
216+
sCentimetersDrivenPerScan = RobotCar.rightCarMotor.EncoderCount - tStepStartDistanceCount;
217217
#endif
218218
if (tCurrentPageIsAutomaticControl) {
219219
char tStringBuffer[6];
@@ -230,7 +230,7 @@ void driveCollisonAvoidingOneStep() {
230230
/*
231231
* Stop if rotation requested or single step
232232
*/
233-
RobotCarPWMMotorControl.stopAndWaitForIt();
233+
RobotCar.stopAndWaitForIt();
234234
#if defined(USE_ENCODER_MOTOR_CONTROL)
235235
#if defined(ENABLE_PATH_INFO_PAGE)
236236

@@ -241,17 +241,17 @@ void driveCollisonAvoidingOneStep() {
241241
insertToPath(CENTIMETER_PER_RIDE * 2, sLastDegreesTurned, true);
242242
} else {
243243
// add last driven distance to path
244-
insertToPath(RobotCarPWMMotorControl.rightCarMotor.LastRideEncoderCount, sLastDegreesTurned, true);
244+
insertToPath(RobotCar.rightCarMotor.LastRideEncoderCount, sLastDegreesTurned, true);
245245
}
246246
#endif
247247
} else {
248248
/*
249249
* No stop, just continue => overwrite last path element with current riding distance and try to synchronize motors
250250
*/
251251
#if defined(ENABLE_PATH_INFO_PAGE)
252-
insertToPath(RobotCarPWMMotorControl.rightCarMotor.EncoderCount, sLastDegreesTurned, false);
252+
insertToPath(RobotCar.rightCarMotor.EncoderCount, sLastDegreesTurned, false);
253253
#endif
254-
// RobotCarPWMMotorControl.rightCarMotor.synchronizeMotor(&RobotCarPWMMotorControl.leftCarMotor, 100);
254+
// RobotCar.rightCarMotor.synchronizeMotor(&RobotCar.leftCarMotor, 100);
255255
#endif
256256
}
257257

@@ -347,7 +347,7 @@ void driveFollowerModeOneStep() {
347347
*/
348348
if (sDoStep) { // Check if we shall do this step
349349
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
351351
sNextRotationDegree = 0;
352352
}
353353

@@ -363,7 +363,7 @@ void driveFollowerModeOneStep() {
363363
/*
364364
* No target found -> stop car, clear display and start scanning in the next step
365365
*/
366-
RobotCarPWMMotorControl.stop(STOP_MODE_RELEASE);
366+
RobotCar.stop(STOP_MODE_RELEASE);
367367
clearPrintedForwardDistancesInfos(false); // clear area for next scan results
368368
sNextRotationDegree = NO_TARGET_FOUND; // scan at next step
369369
} else {
@@ -372,29 +372,37 @@ void driveFollowerModeOneStep() {
372372
* Target found -> keep distance
373373
*/
374374
int tSpeedPWM = 0;
375+
uint8_t tDirection = DIRECTION_STOP;
375376
if (tCentimeter > FOLLOWER_DISTANCE_MAXIMUM_CENTIMETER) {
376377
/*
377378
* 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
378380
*/
379-
tSpeedPWM = RobotCarPWMMotorControl.rightCarMotor.DriveSpeedPWMFor2Volt / 2
381+
tSpeedPWM = PWMDcMotor::getVoltageAdjustedSpeedPWM(DEFAULT_START_SPEED_PWM, sVINVoltage)
380382
+ (tCentimeter - FOLLOWER_DISTANCE_MAXIMUM_CENTIMETER) * 2;
383+
tDirection = DIRECTION_FORWARD;
381384

382385
} else if (tCentimeter < FOLLOWER_DISTANCE_MINIMUM_CENTIMETER) {
383386
/*
384387
* 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
385389
*/
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;
389393
}
394+
390395
if (tSpeedPWM != 0) {
391-
RobotCarPWMMotorControl.setSpeedPWMAndDirection(tSpeedPWM);
396+
if (tSpeedPWM > MAX_SPEED_PWM) {
397+
tSpeedPWM = MAX_SPEED_PWM;
398+
}
399+
RobotCar.setSpeedPWMAndDirection(tSpeedPWM, tDirection);
392400
} else {
393401
/*
394402
* Target is in the right distance -> stop
395403
*/
396-
if (!RobotCarPWMMotorControl.isStopped()) {
397-
RobotCarPWMMotorControl.stop(STOP_MODE_RELEASE);
404+
if (!RobotCar.isStopped()) {
405+
RobotCar.stop(STOP_MODE_RELEASE);
398406
}
399407
}
400408
}
@@ -406,8 +414,8 @@ void driveFollowerModeOneStep() {
406414
*/
407415
sDoStep = false;
408416
delayAndLoopGUI(500);
409-
if (!RobotCarPWMMotorControl.isStopped()) {
410-
RobotCarPWMMotorControl.stop(STOP_MODE_RELEASE);
417+
if (!RobotCar.isStopped()) {
418+
RobotCar.stop(STOP_MODE_RELEASE);
411419
}
412420
}
413421
delayAndLoopGUI(100); // the IR sensor takes 39 ms for one measurement

src/AutonomousDrivePage.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Contains all the GUI elements for autonomous driving.
55
* Cont ->Step / Step -> SStep, SStep->Cont: Switches mode from "continuous drive" to "drive until next turn" to "drive CENTIMETER_PER_RIDE_PRO"
6-
* Start Simple: Start simple driving algorithm (using the 2 "simple" functions in RobotCarPWMMotorControl.cpp)
6+
* Start Simple: Start simple driving algorithm (using the 2 "simple" functions in RobotCar.cpp)
77
* Start Pro: Start elaborated driving algorithm
88
*
99
* Requires BlueDisplay library.
@@ -99,7 +99,7 @@ void setStepModeButtonCaption() {
9999
*/
100100
void setStepMode(uint8_t aStepMode) {
101101
if (aStepMode == MODE_SINGLE_STEP) {
102-
RobotCarPWMMotorControl.stopAndWaitForIt();
102+
RobotCar.stopAndWaitForIt();
103103
} else if (aStepMode > MODE_SINGLE_STEP) {
104104
aStepMode = MODE_CONTINUOUS;
105105
sDoStep = true;
@@ -282,7 +282,7 @@ void startAutonomousDrivePage(void) {
282282

283283
drawAutonomousDrivePage();
284284
if(!isCalibrated) {
285-
calibrateDriveSpeedPWM();
285+
calibrateAndPrint();
286286
}
287287
}
288288

src/BTSensorDrivePage.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,14 @@ void doSensorChange(uint8_t aSensorType, struct SensorCallback *aSensorCallbackI
170170
tDirection |= DIRECTION_TURN;
171171
}
172172
tSpeedPWMValue = max(tSpeedPWMValue, tLeftRightValue);
173-
RobotCarPWMMotorControl.setSpeedPWMAndDirection(speedOverflowAndDeadBandHandling(tSpeedPWMValue), tDirection);
173+
RobotCar.setSpeedPWMAndDirection(speedOverflowAndDeadBandHandling(tSpeedPWMValue), tDirection);
174174
#else
175175
if(tSpeedPWMValue < 0){
176176
tLeftRightValue = -tLeftRightValue;
177177
}
178-
RobotCarPWMMotorControl.rightCarMotor.setSpeedPWMAndDirection(
178+
RobotCar.rightCarMotor.setSpeedPWMAndDirection(
179179
speedOverflowAndDeadBandHandling(tSpeedPWMValue + tLeftRightValue));
180-
RobotCarPWMMotorControl.leftCarMotor.setSpeedPWMAndDirection(
180+
RobotCar.leftCarMotor.setSpeedPWMAndDirection(
181181
speedOverflowAndDeadBandHandling(tSpeedPWMValue - tLeftRightValue));
182182
#endif
183183
}

src/CarPWMMotorControl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ class CarPWMMotorControl {
209209
};
210210

211211
#if !defined(CAR_HAS_4_MECANUM_WHEELS)
212-
extern CarPWMMotorControl RobotCarPWMMotorControl;
212+
extern CarPWMMotorControl RobotCar;
213213
#endif
214214

215215
#endif // _CAR_PWM_MOTOR_CONTROL_H

0 commit comments

Comments
 (0)