Skip to content

Commit 82b8b82

Browse files
authored
Smartcar library version 6.0.0 (#18)
After the Smartcar got upgraded with an ESP32 at its core, several compatibility changes were necessary to the library. Specifically, ESP32 does not natively support the Servo library and has no analogWrite method. External libraries were chosen to fill this gap and other several compatibility enhancements were made to ensure that the differences between the AVR microcontrollers and ESP32 are transparent to the user. Additionally, the Odometer constructors were updated to eliminate any sequential coupling and enforce a more RAII way of doing things. Finally, several other smaller improvements and refinements are introduced.
2 parents 90e5a52 + ca3f07f commit 82b8b82

File tree

64 files changed

+62524
-999
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+62524
-999
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@ static-analysis-report/
1616
arduino*.xz
1717
coverage-reports
1818
coverage.info
19+
20+
# Ignore vscode configuration
21+
.vscode

.travis.yml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
1-
# Set language to `none` because if set to `cpp` CXX and C environment variables
2-
# are overriden with those of older versions
3-
language: none
4-
5-
env:
6-
global:
7-
- CXX=g++-5
1+
language: cpp
2+
dist: bionic
83

94
addons:
105
apt:
6+
update: true
117
sources:
12-
- ubuntu-toolchain-r-test
8+
- sourceline: "ppa:ubuntu-toolchain-r/test"
139
packages:
14-
- g++-5
10+
- g++
1511
- lcov
1612
- doxygen
1713
- doxygen-doc
1814
- doxygen-latex
1915
- doxygen-gui
2016
- graphviz
2117
- cppcheck
18+
- clang-tidy-8
2219

2320
notifications:
2421
email: false
@@ -35,17 +32,22 @@ cache:
3532
before_install:
3633
# Set up the environment for building with the Arduino IDE
3734
- source <(curl -SLs https://raw.githubusercontent.com/adafruit/travis-ci-arduino/master/install.sh)
35+
install:
36+
- arduino --install-library "ESP32 AnalogWrite"
37+
- arduino --install-library "ServoESP32"
3838

3939
script:
4040
# Build and run unit tests
4141
- bash test/build_and_run_ut.sh
4242
# Run static code analysis over the source code
4343
- cppcheck --std=c++11 --enable=performance,portability,information --quiet --error-exitcode=1 src/
44+
- bash run_clang-tidy.sh
4445
# Ensure examples are buildable for various boards
4546
- build_platform uno
4647
- build_platform mega2560
4748
- build_platform leonardo
4849
- build_platform esp8266
50+
- build_platform esp32
4951

5052
after_success:
5153
- bash run_coverage.sh

README.md

Lines changed: 74 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,66 @@ A versatile and easy to use vehicle platform for hobby-grade projects
55
* [Description](#description)
66
* [Hardware](#hardware)
77
* [Software](#software)
8-
* [Materials needed](#materials-needed-default-setup)
8+
* [Reference platforms](#reference-platforms)
99
* [Supported sensors](#supported-sensors)
1010
* [How to get started](#how-to-get-started)
1111
* [Dependencies](#dependencies)
1212
* [Extensions](#extensions)
1313
* [Project documentation](#project-documentation)
1414
* [License](#license)
1515

16-
### Description
16+
## Description
1717
This repository, includes everything necessary to set up a Smartcar platform.
1818
The Smartcar, is a vehicular educational platform, which enables the user to develop
1919
various robotic applications in an affordable, pedagogic and easy way. It is intended
2020
for persons with basic programming knowledge and little to no experience of electronics,
2121
mechanics or robotics. More experienced users, should also find this approach convenient,
2222
due to its open source nature, high level API and object oriented design.
2323

24-
### Hardware
25-
The platform, hardware wise is conceptually focused around the Smartcar shield. The Smartcar
26-
shield is an open hardware PCB, that is effortlessly stacked on top of an Arduino. It includes
27-
an L293D H-bridge chip, that drives the motors, screw terminals to connect the motors
24+
## Hardware
25+
Despite the software being hardware-agnostic, historically, development has been based on specific
26+
hardware. Initially, the **Smartcar shield** was used on top of an Arduino, using cheap car kits.
27+
This setup will be referred to as `shield` or `v1`.
28+
29+
Since the winter of 2019, a new platform was developed from scratch, using the WiFi and Bluetooth
30+
enabled ESP32 as the vehicle's "brain". This setup will be referred to as `platform` or `v2` and
31+
will be considered the default one from now on. It offers greater robustness and many more
32+
possibilities, as it offers out-of-the-box connectivity.
33+
34+
### Platform
35+
36+
![smartcar platform](https://i.imgur.com/cFrq2Wj.jpg)
37+
38+
The Smartcar platform is a complete hardware solution for your hobby-grade, connected vehicle project.
39+
It is comprised of the chassis, made out of printed circuit boards, stacked on each other and an
40+
ESP32 development board that drives the motors, controls the sensors and communicates with the
41+
world via WiFi and Bluetooth.
42+
43+
There are 4 motors with directional odometers which enable not only to determine how much the
44+
wheels have moved but also the direction they spin. It is equipped with a GY-50 gyroscope module
45+
(based on the L3G4200D sensor) to provide heading information and sockets to optionally connect
46+
4 `VL45L0X` LIDAR sensors to provide distance measurements. It is powered up by 8 AA batteries
47+
and you can find the boards' source files in [extras/eagle/smartcar_platform](/extras/eagle/smartcar_shield).
48+
49+
### Shield
50+
51+
![smartcar_shield](https://i.imgur.com/7g5ts49.png)
52+
53+
The Smartcar shield is an open hardware PCB, that is effortlessly stacked on top of an Arduino. It
54+
includes an L293D H-bridge chip, that drives the motors, screw terminals to connect the motors
2855
and a battery to them and a GY-50 gyroscope module (based on the L3G4200D sensor).
2956
In [extras/eagle/smartcar_shield](/extras/eagle/smartcar_shield) you can find the
3057
design files for the board, in a modifiable form, using free software. There are
3158
also the options, to order it as-is, from either USA or China based manufacturers.
59+
3260
The Smartcar shield, facilitates efficient cable management, helps to preserve space
3361
and is as small as possible, in order to keep the manufacturing price low. Additionally,
3462
the components necessary to assemble it, are widely available over the Internet. Furthermore,
3563
you can find 2D CAD drawings of the Smartcar chassis in various formats, at
3664
[/extras/cad/2D](extras/cad/2D) which you can freely use in order to fabricate your own,
3765
e.g. with a milling machine or a laser cutter.
3866

39-
### Software
67+
## Software
4068
The software, is the Smartcar shield Arduino library. It sports a high level API, meant to
4169
enable its users to perform tasks easily with relatively few lines of code. It intends to
4270
hide implementation details or low level hardware operations. The library, handles
@@ -58,7 +86,34 @@ If the Smartcar shield library is installed through the Library Manager of Ardui
5886
recommended, the user will receive a notification in their IDE, when new versions are released
5987
making updates particularly easy, without the need to use GitHub or git.
6088

61-
### Materials needed (default setup)
89+
## Reference platforms
90+
91+
### Smartcar platform (default setup)
92+
93+
* 1 x [Modules board](https://www.pcbway.com/project/shareproject/Smartcar___Module_board.html)
94+
* 1 x [Motor board](https://www.pcbway.com/project/shareproject/Smartcar___Motors_board.html)
95+
* 4 x [Brushed motors](https://www.aliexpress.com/item/32872592243.html?spm=a2g0s.9042311.0.0.40d44c4dvsYt5w)
96+
* 2 x [TTL level shifters](https://www.aliexpress.com/item/32472491036.html?spm=a2g0s.9042311.0.0.40d44c4dvsYt5w)
97+
* 1 x DOIT ESP32 devkit v1 (30 GPIO pins)
98+
* 1 x [TB6612FNG dual motor driver (Sparkfun)](https://www.sparkfun.com/products/14451)
99+
* 4 x M6 (30mm) screws
100+
* 4 x M6 nuts
101+
* 16 x M3 (10mm) screws
102+
* 16 x M3 nuts
103+
* 2 x [HSP 02052 Front Bumper](https://www.aliexpress.com/item/32753903115.html)
104+
* 10 x 6pin 2.54 pitch female pin headers
105+
* 2 x 15pin 2.54 pitch female pin headers
106+
* 1 x GY-50 gyroscope
107+
* 4 x [8pin 2.54 pitch long male pin headers](https://www.aliexpress.com/item/32911455899.html) (30mm long)
108+
* 4 x 8pin 2.54 pitch female pin headers
109+
* 3 x 10KOhm resistors
110+
* 8 x [AA battery holders](https://www.electrokit.com/produkt/batterihallare-1xaa-pcb/)
111+
* 1 x [DD40AJSA adjustable buck converter](https://www.aliexpress.com/item/32816584868.html)
112+
* 4 x [VL45L0x ToF distance sensors](https://www.aliexpress.com/item/32828144370.html) (optional)
113+
* 4 x 4pin 2.54 angled headers to mount the sensors vertically
114+
115+
### Smartcar shield
116+
62117
* Smartcar chassis
63118
* [Smartcar shield PCB](extras/eagle/smartcar_shield)
64119
* L293D H-bridge
@@ -91,25 +146,25 @@ making updates particularly easy, without the need to use GitHub or git.
91146
* Directional (4+ pins)
92147
* Non-directional (3-pins)
93148

94-
### How to get started
149+
## How to get started
95150
* Assemble the vehicle
96151
* [Install the library](https://www.ardu-badge.com/Smartcar%20shield)
97-
* [Connect the motors appropriately](examples/Car/shieldMotorsTest/shieldMotorsTest.ino) (if using the default setup)
152+
* [Connect the motors appropriately](examples/Car/shieldMotorsTest/shieldMotorsTest.ino) (if using the shield)
98153
* [Getting started with the Smartcar Platform](https://www.hackster.io/platisd/getting-started-with-the-smartcar-platform-1648ad)
99154

100-
### Dependencies
101-
- [Wire library](http://arduino.cc/en/reference/Wire) (included with the Arduino IDE)
102-
- [Servo library](https://www.arduino.cc/en/reference/servo) (included with the Arduino IDE)
155+
## Dependencies
156+
All dependencies should be downloaded automatically by the Arduino IDE's library manager.
103157

104-
### Extensions
105-
You can utilize the object oriented design of this library in order to easily extend it.
106-
Have a look at the [Library Architecture](../../wiki/Library-architecture).
158+
- [Wire library](http://arduino.cc/en/reference/Wire)
159+
- [Servo library](https://www.arduino.cc/en/reference/servo)
160+
- [ServoESP32](https://github.com/RoboticsBrno/ServoESP32)
161+
- [ESP32 AnalogWrite](https://github.com/ERROPiX/ESP32_AnalogWrite)
107162

108-
### Project documentation
163+
## Project documentation
109164
* [API Documentation](https://platisd.github.io/smartcar_shield/)
110165
* [The Smartcar platform](http://plat.is/smartcar)
111-
* [Wiki](../../wiki)
166+
* [Wiki](https://github.com/platisd/smartcar_shield/wiki)
112167
* [Turning software engineers into Makers](https://platis.solutions/blog/2016/06/17/turning-software-engineers-into-makers/)
113168

114-
### License
169+
## License
115170
MIT
Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,30 @@
11
#include <Smartcar.h>
22

3-
const unsigned short LEFT_ODOMETER_PIN = 2;
4-
const unsigned short RIGHT_ODOMETER_PIN = 3;
5-
6-
BrushedMotor leftMotor(8, 10, 9);
7-
BrushedMotor rightMotor(12, 13, 11);
3+
BrushedMotor leftMotor(smartcarlib::pins::v2::leftMotorPins);
4+
BrushedMotor rightMotor(smartcarlib::pins::v2::rightMotorPins);
85
DifferentialControl control(leftMotor, rightMotor);
96

10-
DirectionlessOdometer leftOdometer(100);
11-
DirectionlessOdometer rightOdometer(100);
7+
const auto pulsesPerMeter = 600;
128

13-
DistanceCar car(control, leftOdometer, rightOdometer);
9+
DirectionlessOdometer leftOdometer(
10+
smartcarlib::pins::v2::leftOdometerPin, []() { leftOdometer.update(); }, pulsesPerMeter);
11+
DirectionlessOdometer rightOdometer(
12+
smartcarlib::pins::v2::rightOdometerPin, []() { rightOdometer.update(); }, pulsesPerMeter);
1413

15-
void setup() {
16-
// Initialize the odometers (they won't work otherwise)
17-
leftOdometer.attach(LEFT_ODOMETER_PIN, []() {
18-
leftOdometer.update();
19-
});
20-
rightOdometer.attach(RIGHT_ODOMETER_PIN, []() {
21-
rightOdometer.update();
22-
});
14+
DistanceCar car(control, leftOdometer, rightOdometer);
2315

24-
car.enableCruiseControl();
25-
car.setSpeed(1.5); // Maintain a speed of 1.5 m/sec
16+
void setup()
17+
{
18+
car.enableCruiseControl();
19+
car.setSpeed(1.5); // Maintain a speed of 1.5 m/sec
2620
}
2721

28-
void loop() {
29-
car.update(); // Maintain the speed
30-
// Stop after moving 1 meter
31-
if (car.getDistance() >= 100) {
32-
car.setSpeed(0);
33-
}
22+
void loop()
23+
{
24+
car.update(); // Maintain the speed
25+
// Stop after moving 1 meter
26+
if (car.getDistance() >= 100)
27+
{
28+
car.setSpeed(0);
29+
}
3430
}
Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,37 @@
11
#include <Smartcar.h>
22

3-
BrushedMotor leftMotor(8, 10, 9);
4-
BrushedMotor rightMotor(12, 13, 11);
3+
BrushedMotor leftMotor(smartcarlib::pins::v2::leftMotorPins);
4+
BrushedMotor rightMotor(smartcarlib::pins::v2::rightMotorPins);
55
DifferentialControl control(leftMotor, rightMotor);
66

77
SimpleCar car(control);
88

9-
void setup() {
10-
Serial.begin(9600);
11-
Serial.setTimeout(200);
9+
void setup()
10+
{
11+
Serial.begin(9600);
12+
Serial.setTimeout(200);
1213
}
1314

14-
void loop() {
15-
handleInput();
15+
void loop()
16+
{
17+
handleInput();
1618
}
1719

18-
void handleInput() { //handle serial input if there is any
19-
if (Serial.available()) {
20-
String input = Serial.readStringUntil('\n');
21-
if (input.startsWith("m")) {
22-
int throttle = input.substring(1).toInt();
23-
car.setSpeed(throttle);
24-
}else if (input.startsWith("t")){
25-
int deg = input.substring(1).toInt();
26-
car.setAngle(deg);
20+
void handleInput()
21+
{
22+
// handle serial input if there is any
23+
if (Serial.available())
24+
{
25+
String input = Serial.readStringUntil('\n');
26+
if (input.startsWith("m"))
27+
{
28+
int throttle = input.substring(1).toInt();
29+
car.setSpeed(throttle);
30+
}
31+
else if (input.startsWith("t"))
32+
{
33+
int deg = input.substring(1).toInt();
34+
car.setAngle(deg);
35+
}
2736
}
28-
}
2937
}
Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
11
#include <Smartcar.h>
22

3-
const int GYROSCOPE_OFFSET = 37;
3+
const int GYROSCOPE_OFFSET = 37;
44
const unsigned long PRINT_INTERVAL = 100;
5-
unsigned long previousPrintout = 0;
5+
unsigned long previousPrintout = 0;
66

7-
BrushedMotor leftMotor(8, 10, 9);
8-
BrushedMotor rightMotor(12, 13, 11);
7+
BrushedMotor leftMotor(smartcarlib::pins::v2::leftMotorPins);
8+
BrushedMotor rightMotor(smartcarlib::pins::v2::rightMotorPins);
99
DifferentialControl control(leftMotor, rightMotor);
1010

1111
GY50 gyroscope(GYROSCOPE_OFFSET);
1212

1313
HeadingCar car(control, gyroscope);
1414

15-
void setup() {
16-
Serial.begin(9600);
15+
void setup()
16+
{
17+
Serial.begin(9600);
1718
}
1819

19-
void loop() {
20-
// Update the heading readings
21-
car.update();
22-
unsigned long currentTime = millis();
23-
if (currentTime >= previousPrintout + PRINT_INTERVAL) {
24-
previousPrintout = currentTime;
25-
Serial.println(car.getHeading());
26-
}
20+
void loop()
21+
{
22+
// Update the heading readings
23+
car.update();
24+
unsigned long currentTime = millis();
25+
if (currentTime >= previousPrintout + PRINT_INTERVAL)
26+
{
27+
previousPrintout = currentTime;
28+
Serial.println(car.getHeading());
29+
}
2730
}

0 commit comments

Comments
 (0)