Skip to content

Commit 6e9313d

Browse files
committed
Quality assurance
1 parent c421e02 commit 6e9313d

38 files changed

+309
-344
lines changed

.github/workflows/TestCompile.yml

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,13 @@ jobs:
4343
-DDISTANCE_SERVO_IS_MOUNTED_HEAD_DOWN
4444
-DUSE_ADAFRUIT_MOTOR_SHIELD
4545

46-
- arduino-boards-fqbn: arduino:avr:uno|BreadboardFull # Nano board with TB6612 breakout board
46+
- arduino-boards-fqbn: arduino:avr:uno|TimeOfFlight # UNO board with ToF distance sensor
4747
build-properties:
4848
RobotCarBlueDisplay:
49-
-DTBB6612_4WD_4AA_FULL_CONFIGURATION
49+
-DMOTOR_SHIELD_2WD_FULL_CONFIGURATION
5050
-DBLUETOOTH_BAUD_RATE=BAUD_115200
51-
-mcall-prologues # reduces size by 870 bytes
51+
-DUS_SENSOR_SUPPORTS_1_PIN_MODE
52+
-mcall-prologues
5253

5354
- arduino-boards-fqbn: arduino:avr:uno|BreadboardFull # Nano board with TB6612 breakout board
5455
build-properties:
@@ -66,14 +67,6 @@ jobs:
6667
-DUS_SENSOR_SUPPORTS_1_PIN_MODE
6768
-mcall-prologues # reduces size by 870 bytes
6869

69-
- arduino-boards-fqbn: arduino:avr:uno|TimeOfFlight # UNO board with ToF distance sensor
70-
build-properties:
71-
RobotCarBlueDisplay:
72-
-DMOTOR_SHIELD_2WD_ENCODER_TOF_CONFIGURATION
73-
-DBLUETOOTH_BAUD_RATE=BAUD_115200
74-
-DUS_SENSOR_SUPPORTS_1_PIN_MODE
75-
-DDISTANCE_SERVO_IS_MOUNTED_HEAD_DOWN
76-
-mcall-prologues
7770

7871
steps:
7972
- name: Checkout

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Compile options for the used **PWMMotorControl library** like `USE_ENCODER_MOTOR
6161
| `CAR_HAS_US_DISTANCE_SENSOR` | disabled | A HC-SR04 ultrasonic distance sensor is mounted (default for most China smart cars). |
6262
| `US_SENSOR_SUPPORTS_1_PIN_MODE` | disabled | Use modified HC-SR04 modules or HY-SRF05 ones.</br>Modify HC-SR04 by connecting 10kOhm between echo and trigger and then use only trigger pin. |
6363
| `CAR_HAS_IR_DISTANCE_SENSOR` | disabled | Use Sharp GP2Y0A21YK / 1080 IR distance sensor. |
64-
| `CAR_CAR_HAS_TOF_DISTANCE_SENSOR` | disabled | Use VL53L1X TimeOfFlight distance sensor. |
64+
| `CAR_HAS_TOF_DISTANCE_SENSOR` | disabled | Use VL53L1X TimeOfFlight distance sensor. |
6565
| `CAR_HAS_DISTANCE_SERVO` | disabled | Distance sensor is mounted on a pan servo (default for most China smart cars). |
6666
| `DISTANCE_SERVO_IS_MOUNTED_HEAD_DOWN` | disabled | Distance.h | The distance servo is mounted head down to detect even small obstacles. The Servo direction is reverse then. |
6767
| `CAR_HAS_PAN_SERVO` | disabled | Enables the pan slider for the `PanServo` at the `PIN_PAN_SERVO` pin. |

src/ADCUtils.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,3 @@ float getTemperature(void);
143143
#endif // defined(ADATE)
144144
#endif // defined(__AVR__)
145145
#endif // _ADC_UTILS_H
146-
#pragma once

src/AutonomousDrive.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
#ifndef _AUTONOMOUS_DRIVE_H
2020
#define _AUTONOMOUS_DRIVE_H
2121

22-
#include <stdint.h>
23-
2422
/*
2523
* Different autonomous driving modes
2624
*/
@@ -61,4 +59,3 @@ void driveFollowerModeOneStep();
6159

6260
#endif // _AUTONOMOUS_DRIVE_H
6361
#endif // defined(ENABLE_AUTONOMOUS_DRIVE)
64-
#pragma once

src/AutonomousDrive.hpp

Lines changed: 32 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,19 @@
2626

2727
#ifndef _ROBOT_CAR_AUTOMOMOUS_DRIVE_HPP
2828
#define _ROBOT_CAR_AUTOMOMOUS_DRIVE_HPP
29-
#include <Arduino.h>
3029

3130
#include "AutonomousDrive.h"
3231

33-
#include "RobotCarPinDefinitionsAndMore.h"
34-
#include "RobotCarBlueDisplay.h"
35-
#include "RobotCarGui.h"
36-
#include "Distance.h"
37-
3832
uint8_t sDriveMode = MODE_MANUAL_DRIVE; // one of MODE_MANUAL_DRIVE, MODE_COLLISION_AVOIDING_BUILTIN, MODE_COLLISION_AVOIDING_USER or MODE_FOLLOWER
3933

4034
uint8_t sStepMode = MODE_CONTINUOUS; // one of MODE_CONTINUOUS, MODE_STEP_TO_NEXT_TURN or MODE_SINGLE_STEP
4135
bool sDoStep = false; // if true => do one step
4236

4337
turn_direction_t sTurnMode = TURN_IN_PLACE;
4438
int sNextRotationDegree = 0; // Storage for turning decision especially for single step mode
39+
#if defined(ENABLE_PATH_INFO_PAGE)
4540
int sLastDegreesTurned = 0; // Storage of last turning for insertToPath()
41+
#endif
4642

4743
/*
4844
* Used for adaptive collision detection
@@ -93,7 +89,7 @@ void startStopAutomomousDrive(bool aDoStart, uint8_t aDriveMode) {
9389
// Show distance sliders
9490
SliderUSDistance.drawSlider();
9591
TouchButtonDistanceFeedbackMode.drawButton();
96-
# if defined(CAR_HAS_IR_DISTANCE_SENSOR) || defined(CAR_CAR_HAS_TOF_DISTANCE_SENSOR)
92+
# if defined(CAR_HAS_IR_DISTANCE_SENSOR) || defined(CAR_HAS_TOF_DISTANCE_SENSOR)
9793
SliderIROrTofDistance.drawSlider();
9894
# endif
9995
}
@@ -102,7 +98,7 @@ void startStopAutomomousDrive(bool aDoStart, uint8_t aDriveMode) {
10298
/*
10399
* Stop autonomous driving.
104100
*/
105-
#if defined(USE_ENCODER_MOTOR_CONTROL) && defined(ENABLE_PATH_INFO_PAGE)
101+
#if defined(ENABLE_PATH_INFO_PAGE)
106102
if (sStepMode != MODE_SINGLE_STEP) {
107103
// add last driven distance to path
108104
insertToPath(RobotCar.rightCarMotor.LastRideEncoderCount, sLastDegreesTurned, true);
@@ -114,9 +110,8 @@ void startStopAutomomousDrive(bool aDoStart, uint8_t aDriveMode) {
114110
TouchButtonDistanceFeedbackMode.removeButton(COLOR16_WHITE);
115111
}
116112

117-
// manage on off buttons
113+
// manage 3 on off buttons
118114
handleAutomomousDriveRadioButtons();
119-
TouchButtonRobotCarStartStop.setValue(aDoStart, false);
120115
}
121116

122117
/*
@@ -152,45 +147,48 @@ void driveCollisonAvoidingOneStep() {
152147
bool tMovementJustStarted = sDoStep || tCarIsStopped; // tMovementJustStarted is needed for speeding up US scanning by skipping first scan angle if not just started.
153148
sDoStep = false; // Now it can be set again by GUI
154149

155-
if (sNextRotationDegree != 0) {
150+
/*
151+
* Check sNextRotationDegree
152+
*/
153+
if (sNextRotationDegree == MINIMUM_DISTANCE_TOO_SMALL) {
156154
/*
157-
* rotate car / go backward accordingly to sNextRotationDegree
155+
* Go backwards and do a new scan
158156
*/
159-
if (sNextRotationDegree == MINIMUM_DISTANCE_TOO_SMALL) {
160-
// go backwards and do a new scan
161-
RobotCar.goDistanceMillimeter(100, DIRECTION_BACKWARD, &loopGUI);
162-
} else {
163-
// rotate and go
164-
RobotCar.rotate(sNextRotationDegree, sTurnMode, false, &loopGUI); // do not use slow speed
165-
// wait to really stop after turning
166-
delay(100);
167-
sLastDegreesTurned = sNextRotationDegree;
168-
}
169-
}
170-
if (sNextRotationDegree != MINIMUM_DISTANCE_TOO_SMALL) {
157+
RobotCar.goDistanceMillimeter(100, DIRECTION_BACKWARD, &loopGUI);
158+
} else if (sNextRotationDegree != 0) {
159+
/*
160+
* Rotate and stop
161+
*/
162+
RobotCar.rotate(sNextRotationDegree, sTurnMode, false, &loopGUI); // do not use slow speed
163+
// wait to really stop after turning
164+
delay(100);
165+
#if defined(ENABLE_PATH_INFO_PAGE)
166+
sLastDegreesTurned = sNextRotationDegree;
167+
#endif
168+
} else {
171169
/*
172-
* No rotation or standard rotation here. Go fixed distance or keep moving
170+
* No rotation or go back here. Go fixed distance or keep moving
173171
*/
174172
if (sStepMode == MODE_SINGLE_STEP) {
175173
// Go fixed distance
176174
RobotCar.goDistanceMillimeter(sCentimetersDrivenPerScan * 10, DIRECTION_FORWARD, &loopGUI);
177-
} else
178-
/*
179-
* Continuous mode, start car or let it run (do nothing)
180-
*/
181-
if (tCarIsStopped) {
175+
} else if (tCarIsStopped) {
176+
/*
177+
* Continuous mode, start car or let it run (do nothing)
178+
*/
182179
RobotCar.startRampUpAndWaitForDriveSpeedPWM(DIRECTION_FORWARD, &loopGUI);
183180
}
181+
#if defined(ENABLE_PATH_INFO_PAGE)
182+
sLastDegreesTurned = 0; // rotation was 0 here
183+
#endif
184184
}
185185

186186
/*
187-
* Here car is moving
187+
* Here car is moving or did a rotation or go back
188188
*/
189189
#if defined(USE_ENCODER_MOTOR_CONTROL)
190190
uint16_t tStepStartDistanceCount = RobotCar.rightCarMotor.EncoderCount; // get count before distance scanning
191191
#endif
192-
bool tCurrentPageIsAutomaticControl = (sCurrentPage == PAGE_AUTOMATIC_CONTROL);
193-
194192
/*
195193
* The magic happens HERE
196194
* This runs as fast as possible and mainly determine the duration of one step
@@ -215,7 +213,7 @@ void driveCollisonAvoidingOneStep() {
215213
#if defined(USE_ENCODER_MOTOR_CONTROL)
216214
sCentimetersDrivenPerScan = RobotCar.rightCarMotor.EncoderCount - tStepStartDistanceCount;
217215
#endif
218-
if (tCurrentPageIsAutomaticControl) {
216+
if (sCurrentPage == PAGE_AUTOMATIC_CONTROL) {
219217
char tStringBuffer[6];
220218
sprintf_P(tStringBuffer, PSTR("%2d%s"), sCentimetersDrivenPerScan, "cm");
221219
BlueDisplay1.drawText(0, BUTTON_HEIGHT_4_LINE_4 - TEXT_SIZE_11_DECEND, tStringBuffer, TEXT_SIZE_11,
@@ -231,9 +229,7 @@ void driveCollisonAvoidingOneStep() {
231229
* Stop if rotation requested or single step
232230
*/
233231
RobotCar.stopAndWaitForIt();
234-
#if defined(USE_ENCODER_MOTOR_CONTROL)
235232
#if defined(ENABLE_PATH_INFO_PAGE)
236-
237233
/*
238234
* Insert / update last ride in path
239235
*/
@@ -243,15 +239,11 @@ void driveCollisonAvoidingOneStep() {
243239
// add last driven distance to path
244240
insertToPath(RobotCar.rightCarMotor.LastRideEncoderCount, sLastDegreesTurned, true);
245241
}
246-
#endif
247242
} else {
248243
/*
249244
* No stop, just continue => overwrite last path element with current riding distance and try to synchronize motors
250245
*/
251-
#if defined(ENABLE_PATH_INFO_PAGE)
252246
insertToPath(RobotCar.rightCarMotor.EncoderCount, sLastDegreesTurned, false);
253-
#endif
254-
// RobotCar.rightCarMotor.synchronizeMotor(&RobotCar.leftCarMotor, 100);
255247
#endif
256248
}
257249

src/AutonomousDrivePage.hpp

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,6 @@
2626

2727
#ifndef _ROBOT_CAR_AUTOMOMOUS_DRIVE_PAGE_HPP
2828
#define _ROBOT_CAR_AUTOMOMOUS_DRIVE_PAGE_HPP
29-
#include <Arduino.h>
30-
31-
#include "RobotCarPinDefinitionsAndMore.h"
32-
#include "RobotCarBlueDisplay.h"
33-
#include "RobotCarGui.h"
34-
#include "Distance.h"
3529

3630
BDButton TouchButtonStepMode;
3731
const char sStepModeButtonStringContinuousStepToTurn[] PROGMEM = "Continuous\n->\nStep to turn";
@@ -54,7 +48,7 @@ BDButton TouchButtonScanSpeed;
5448
BDButton TouchButtonPathInfoPage;
5549
#endif
5650

57-
#if defined(CAR_HAS_IR_DISTANCE_SENSOR) || defined(CAR_CAR_HAS_TOF_DISTANCE_SENSOR)
51+
#if defined(CAR_HAS_IR_DISTANCE_SENSOR) || defined(CAR_HAS_TOF_DISTANCE_SENSOR)
5852
BDButton TouchButtonScanMode;
5953
const char sDistanceSourceModeButtonStringMinMax[] PROGMEM = "Min->Max";
6054
const char sDistanceSourceModeButtonStringMaxUS[] PROGMEM = "Max->US";
@@ -126,14 +120,12 @@ void doStep(BDButton *aTheTouchedButton, int16_t aValue) {
126120
/*
127121
* Start if not yet done
128122
*/
129-
if (sDriveMode == MODE_FOLLOWER) {
130-
sDoStep = true;
131-
} else if (sDriveMode != MODE_MANUAL_DRIVE) {
123+
if (sDriveMode == MODE_MANUAL_DRIVE) {
132124
startStopAutomomousDrive(true, MODE_COLLISION_AVOIDING_BUILTIN);
133125
}
134126
}
135127

136-
#if defined(CAR_HAS_IR_DISTANCE_SENSOR) || defined(CAR_CAR_HAS_TOF_DISTANCE_SENSOR)
128+
#if defined(CAR_HAS_IR_DISTANCE_SENSOR) || defined(CAR_HAS_TOF_DISTANCE_SENSOR)
137129
void setScanModeButtonCaption() {
138130
TouchButtonScanMode.setCaptionFromStringArrayPGM(sDistanceSourceModeButtonCaptionStringArray, sDistanceSourceMode);
139131
}
@@ -147,7 +139,7 @@ void doDistanceSourceMode(BDButton *aTheTouchedButton, int16_t aValue) {
147139
TouchButtonScanMode.drawButton();
148140
}
149141

150-
#endif // defined(CAR_HAS_IR_DISTANCE_SENSOR) || defined(CAR_CAR_HAS_TOF_DISTANCE_SENSOR)
142+
#endif // defined(CAR_HAS_IR_DISTANCE_SENSOR) || defined(CAR_HAS_TOF_DISTANCE_SENSOR)
151143

152144
void doChangeScanSpeed(BDButton *aTheTouchedButton, int16_t aValue) {
153145
sDoSlowScan = aValue;
@@ -220,7 +212,7 @@ void initAutonomousDrivePage(void) {
220212
BUTTON_WIDTH_3, TEXT_SIZE_22_HEIGHT, COLOR16_RED, reinterpret_cast<const __FlashStringHelper*>(sDistanceFeedbackModeNoTone), TEXT_SIZE_14,
221213
FLAG_BUTTON_DO_BEEP_ON_TOUCH, DISTANCE_FEEDBACK_NO_TONE, &doNextDistanceFeedbackMode);
222214

223-
#if defined(CAR_HAS_IR_DISTANCE_SENSOR) || defined(CAR_CAR_HAS_TOF_DISTANCE_SENSOR)
215+
#if defined(CAR_HAS_IR_DISTANCE_SENSOR) || defined(CAR_HAS_TOF_DISTANCE_SENSOR)
224216
TouchButtonScanMode.init(BUTTON_WIDTH_3_POS_3, BUTTON_HEIGHT_4_LINE_4 - (TEXT_SIZE_22_HEIGHT + BUTTON_DEFAULT_SPACING_QUARTER),
225217
BUTTON_WIDTH_3, TEXT_SIZE_22_HEIGHT, COLOR16_RED,
226218
reinterpret_cast<const __FlashStringHelper*>(sDistanceSourceModeButtonStringMinMax),
@@ -259,7 +251,7 @@ void drawAutonomousDrivePage(void) {
259251
// small buttons
260252
TouchButtonStartStopUserAutonomousDrive.drawButton();
261253
// TouchButtonDistanceFeedbackMode.drawButton();
262-
#if defined(CAR_HAS_IR_DISTANCE_SENSOR) || defined(CAR_CAR_HAS_TOF_DISTANCE_SENSOR)
254+
#if defined(CAR_HAS_IR_DISTANCE_SENSOR) || defined(CAR_HAS_TOF_DISTANCE_SENSOR)
263255
TouchButtonScanMode.drawButton();
264256
#endif
265257

@@ -275,11 +267,24 @@ void startAutonomousDrivePage(void) {
275267

276268
// restore last step and scan mode
277269
setStepModeButtonCaption();
278-
#if defined(CAR_HAS_IR_DISTANCE_SENSOR) || defined(CAR_CAR_HAS_TOF_DISTANCE_SENSOR)
270+
#if defined(CAR_HAS_IR_DISTANCE_SENSOR) || defined(CAR_HAS_TOF_DISTANCE_SENSOR)
279271
setScanModeButtonCaption();
280272
#endif
281273
setDistanceFeedbackModeButtonCaption();
282274

275+
#if defined(ENABLE_PATH_INFO_PAGE)
276+
#define SLIDER_SHIFTED_Y_POS BUTTON_HEIGHT_6
277+
#else
278+
#define SLIDER_SHIFTED_Y_POS SLIDER_TOP_MARGIN
279+
#endif
280+
#if defined(US_DISTANCE_SLIDER_IS_SMALL)
281+
SliderUSDistance.setPosition(POS_X_DISTANCE_POSITION_SLIDER - ((BUTTON_WIDTH_10 / 2) - 2) - TEXT_SIZE_11_WIDTH, SLIDER_SHIFTED_Y_POS);
282+
#else
283+
SliderUSDistance.setPosition(POS_X_DISTANCE_POSITION_SLIDER - BUTTON_WIDTH_10, SLIDER_SHIFTED_Y_POS);
284+
#endif
285+
#if defined(CAR_HAS_IR_DISTANCE_SENSOR) || defined(CAR_HAS_TOF_DISTANCE_SENSOR)
286+
SliderIROrTofDistance.setPosition(POS_X_DISTANCE_POSITION_SLIDER - (TEXT_SIZE_11_WIDTH + BUTTON_WIDTH_10), SLIDER_SHIFTED_Y_POS);
287+
#endif
283288
drawAutonomousDrivePage();
284289
if(!isCalibrated) {
285290
calibrateAndPrint();
@@ -292,7 +297,15 @@ void loopAutonomousDrivePage(void) {
292297
}
293298

294299
void stopAutonomousDrivePage(void) {
295-
startStopRobotCar(false);
300+
#if defined(US_DISTANCE_SLIDER_IS_SMALL)
301+
SliderUSDistance.setPosition(POS_X_US_DISTANCE_SLIDER - ((BUTTON_WIDTH_10 / 2) - 2), SLIDER_TOP_MARGIN + BUTTON_HEIGHT_8);
302+
#else
303+
SliderUSDistance.setPosition(POS_X_US_DISTANCE_SLIDER - BUTTON_WIDTH_10, SLIDER_TOP_MARGIN + BUTTON_HEIGHT_8);
304+
#endif
305+
#if defined(CAR_HAS_IR_DISTANCE_SENSOR) || defined(CAR_HAS_TOF_DISTANCE_SENSOR)
306+
SliderIROrTofDistance.setPosition(POS_X_THIRD_SLIDER - ((BUTTON_WIDTH_10 / 2) - 2), SLIDER_TOP_MARGIN + BUTTON_HEIGHT_8);
307+
#endif
308+
296309
}
297310

298311
/*
@@ -330,6 +343,7 @@ void drawCollisionDecision(int aDegreeToTurn, uint8_t aLengthOfVector, bool aDoC
330343
BlueDisplay1.drawVectorDegrees(US_DISTANCE_MAP_ORIGIN_X, US_DISTANCE_MAP_ORIGIN_Y, aLengthOfVector, tDegreeToDisplay + 90,
331344
tColor);
332345
if (!aDoClearVector) {
346+
//Print result
333347
sprintf_P(sStringBuffer, PSTR("wall%4d\xB0 rotation: %3d\xB0 wall%4d\xB0"), sForwardDistancesInfo.WallLeftAngleDegrees,
334348
aDegreeToTurn, sForwardDistancesInfo.WallRightAngleDegrees); // \xB0 is degree character
335349
BlueDisplay1.drawText(BUTTON_WIDTH_3_5_POS_2, US_DISTANCE_MAP_ORIGIN_Y + TEXT_SIZE_11, sStringBuffer, TEXT_SIZE_11,

src/BTSensorDrivePage.hpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@
2020
*/
2121
#ifndef _ROBOT_CAR_BT_SENSOR_DRIVE_PAGE_HPP
2222
#define _ROBOT_CAR_BT_SENSOR_DRIVE_PAGE_HPP
23-
#include <Arduino.h>
24-
25-
#include "RobotCarPinDefinitionsAndMore.h"
26-
#include "RobotCarBlueDisplay.h"
27-
28-
#include "RobotCarGui.h"
2923

3024
// 4 Sliders for accelerometer
3125
BDSlider SliderForward; // Y negative

0 commit comments

Comments
 (0)