Skip to content

Commit 6e792ef

Browse files
committed
Update examples for new API
1 parent e9f270f commit 6e792ef

File tree

22 files changed

+181
-105
lines changed

22 files changed

+181
-105
lines changed

examples/Car/DistanceCar/DistanceCar.ino

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
#include <Smartcar.h>
22

3-
BrushedMotor leftMotor(smartcarlib::pins::v2::leftMotorPins);
4-
BrushedMotor rightMotor(smartcarlib::pins::v2::rightMotorPins);
3+
ArduinoRuntime arduino;
4+
BrushedMotor leftMotor(arduino, smartcarlib::pins::v2::leftMotorPins);
5+
BrushedMotor rightMotor(arduino, smartcarlib::pins::v2::rightMotorPins);
56
DifferentialControl control(leftMotor, rightMotor);
67

78
const auto pulsesPerMeter = 600;
89

910
DirectionlessOdometer leftOdometer(
10-
smartcarlib::pins::v2::leftOdometerPin, []() { leftOdometer.update(); }, pulsesPerMeter);
11+
arduino,
12+
smartcarlib::pins::v2::leftOdometerPin,
13+
[]() { leftOdometer.update(); },
14+
pulsesPerMeter);
1115
DirectionlessOdometer rightOdometer(
12-
smartcarlib::pins::v2::rightOdometerPin, []() { rightOdometer.update(); }, pulsesPerMeter);
16+
arduino,
17+
smartcarlib::pins::v2::rightOdometerPin,
18+
[]() { rightOdometer.update(); },
19+
pulsesPerMeter);
1320

14-
DistanceCar car(control, leftOdometer, rightOdometer);
21+
DistanceCar car(arduino, control, leftOdometer, rightOdometer);
1522

1623
void setup()
1724
{

examples/Car/FullSerialControl/FullSerialControl.ino

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#include <Smartcar.h>
22

3-
BrushedMotor leftMotor(smartcarlib::pins::v2::leftMotorPins);
4-
BrushedMotor rightMotor(smartcarlib::pins::v2::rightMotorPins);
3+
ArduinoRuntime arduino;
4+
BrushedMotor leftMotor(arduino, smartcarlib::pins::v2::leftMotorPins);
5+
BrushedMotor rightMotor(arduino, smartcarlib::pins::v2::rightMotorPins);
56
DifferentialControl control(leftMotor, rightMotor);
67

78
SimpleCar car(control);

examples/Car/HeadingCar/HeadingCar.ino

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ const int GYROSCOPE_OFFSET = 37;
44
const unsigned long PRINT_INTERVAL = 100;
55
unsigned long previousPrintout = 0;
66

7-
BrushedMotor leftMotor(smartcarlib::pins::v2::leftMotorPins);
8-
BrushedMotor rightMotor(smartcarlib::pins::v2::rightMotorPins);
7+
ArduinoRuntime arduino;
8+
BrushedMotor leftMotor(arduino, smartcarlib::pins::v2::leftMotorPins);
9+
BrushedMotor rightMotor(arduino, smartcarlib::pins::v2::rightMotorPins);
910
DifferentialControl control(leftMotor, rightMotor);
1011

11-
GY50 gyroscope(GYROSCOPE_OFFSET);
12+
GY50 gyroscope(arduino, GYROSCOPE_OFFSET);
1213

1314
HeadingCar car(control, gyroscope);
1415

examples/Car/PidControllerMonitor/PidControllerMonitor.ino

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,25 @@ const unsigned long PRINTOUT_INTERVAL = 100;
99
unsigned long previousPrintOut = 0;
1010
float carSpeed = 0.5;
1111

12-
BrushedMotor leftMotor(smartcarlib::pins::v2::leftMotorPins);
13-
BrushedMotor rightMotor(smartcarlib::pins::v2::rightMotorPins);
12+
ArduinoRuntime arduino;
13+
BrushedMotor leftMotor(arduino, smartcarlib::pins::v2::leftMotorPins);
14+
BrushedMotor rightMotor(arduino, smartcarlib::pins::v2::rightMotorPins);
1415
DifferentialControl control(leftMotor, rightMotor);
1516

1617
const auto pulsesPerMeter = 600;
1718

1819
DirectionlessOdometer leftOdometer(
19-
smartcarlib::pins::v2::leftOdometerPin, []() { leftOdometer.update(); }, pulsesPerMeter);
20+
arduino,
21+
smartcarlib::pins::v2::leftOdometerPin,
22+
[]() { leftOdometer.update(); },
23+
pulsesPerMeter);
2024
DirectionlessOdometer rightOdometer(
21-
smartcarlib::pins::v2::rightOdometerPin, []() { rightOdometer.update(); }, pulsesPerMeter);
25+
arduino,
26+
smartcarlib::pins::v2::rightOdometerPin,
27+
[]() { rightOdometer.update(); },
28+
pulsesPerMeter);
2229

23-
DistanceCar car(control, leftOdometer, rightOdometer);
30+
DistanceCar car(arduino, control, leftOdometer, rightOdometer);
2431

2532
void setup()
2633
{

examples/Car/SimpleCar/SimpleCar.ino

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#include <Smartcar.h>
22

3-
BrushedMotor leftMotor(smartcarlib::pins::v2::leftMotorPins);
4-
BrushedMotor rightMotor(smartcarlib::pins::v2::rightMotorPins);
3+
ArduinoRuntime arduino;
4+
BrushedMotor leftMotor(arduino, smartcarlib::pins::v2::leftMotorPins);
5+
BrushedMotor rightMotor(arduino, smartcarlib::pins::v2::rightMotorPins);
56
DifferentialControl control(leftMotor, rightMotor);
67

78
SimpleCar car(control);

examples/Car/SmartCar/SmartCar.ino

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,27 @@
33
const unsigned long PRINT_INTERVAL = 100;
44
unsigned long previousPrintout = 0;
55

6-
BrushedMotor leftMotor(smartcarlib::pins::v2::leftMotorPins);
7-
BrushedMotor rightMotor(smartcarlib::pins::v2::rightMotorPins);
6+
ArduinoRuntime arduino;
7+
BrushedMotor leftMotor(arduino, smartcarlib::pins::v2::leftMotorPins);
8+
BrushedMotor rightMotor(arduino, smartcarlib::pins::v2::rightMotorPins);
89
DifferentialControl control(leftMotor, rightMotor);
910

10-
GY50 gyroscope(37);
11+
GY50 gyroscope(arduino, 37);
1112

1213
const auto pulsesPerMeter = 600;
1314

1415
DirectionlessOdometer leftOdometer(
15-
smartcarlib::pins::v2::leftOdometerPin, []() { leftOdometer.update(); }, pulsesPerMeter);
16+
arduino,
17+
smartcarlib::pins::v2::leftOdometerPin,
18+
[]() { leftOdometer.update(); },
19+
pulsesPerMeter);
1620
DirectionlessOdometer rightOdometer(
17-
smartcarlib::pins::v2::rightOdometerPin, []() { rightOdometer.update(); }, pulsesPerMeter);
21+
arduino,
22+
smartcarlib::pins::v2::rightOdometerPin,
23+
[]() { rightOdometer.update(); },
24+
pulsesPerMeter);
1825

19-
SmartCar car(control, gyroscope, leftOdometer, rightOdometer);
26+
SmartCar car(arduino, control, gyroscope, leftOdometer, rightOdometer);
2027

2128
void setup()
2229
{

examples/Car/automatedMovements/automatedMovements.ino

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,27 @@ const float carSpeed = 1.0;
44
const long distanceToTravel = 40;
55
const int degreesToTurn = 90;
66

7-
BrushedMotor leftMotor(smartcarlib::pins::v2::leftMotorPins);
8-
BrushedMotor rightMotor(smartcarlib::pins::v2::rightMotorPins);
7+
ArduinoRuntime arduino;
8+
BrushedMotor leftMotor(arduino, smartcarlib::pins::v2::leftMotorPins);
9+
BrushedMotor rightMotor(arduino, smartcarlib::pins::v2::rightMotorPins);
910
DifferentialControl control(leftMotor, rightMotor);
1011

11-
GY50 gyroscope(37);
12+
GY50 gyroscope(arduino, 37);
1213

1314
const auto pulsesPerMeter = 600;
1415

1516
DirectionlessOdometer leftOdometer(
16-
smartcarlib::pins::v2::leftOdometerPin, []() { leftOdometer.update(); }, pulsesPerMeter);
17+
arduino,
18+
smartcarlib::pins::v2::leftOdometerPin,
19+
[]() { leftOdometer.update(); },
20+
pulsesPerMeter);
1721
DirectionlessOdometer rightOdometer(
18-
smartcarlib::pins::v2::rightOdometerPin, []() { rightOdometer.update(); }, pulsesPerMeter);
22+
arduino,
23+
smartcarlib::pins::v2::rightOdometerPin,
24+
[]() { rightOdometer.update(); },
25+
pulsesPerMeter);
1926

20-
SmartCar car(control, gyroscope, leftOdometer, rightOdometer);
27+
SmartCar car(arduino, control, gyroscope, leftOdometer, rightOdometer);
2128

2229
void setup()
2330
{

examples/Car/manualControl/manualControl.ino

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ const int bSpeed = -70; // 70% of the full speed backward
55
const int lDegrees = -75; // degrees to turn left
66
const int rDegrees = 75; // degrees to turn right
77

8-
BrushedMotor leftMotor(smartcarlib::pins::v2::leftMotorPins);
9-
BrushedMotor rightMotor(smartcarlib::pins::v2::rightMotorPins);
8+
ArduinoRuntime arduino;
9+
BrushedMotor leftMotor(arduino, smartcarlib::pins::v2::leftMotorPins);
10+
BrushedMotor rightMotor(arduino, smartcarlib::pins::v2::rightMotorPins);
1011
DifferentialControl control(leftMotor, rightMotor);
1112

1213
SimpleCar car(control);

examples/Car/manualWithCruiseControl/manualWithCruiseControl.ino

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,25 @@ const float bSpeed = -0.5; // a ground speed (m/sec)y for going backward
55
const int lDegrees = -75; // degrees to turn left
66
const int rDegrees = 75; // degrees to turn right
77

8-
BrushedMotor leftMotor(smartcarlib::pins::v2::leftMotorPins);
9-
BrushedMotor rightMotor(smartcarlib::pins::v2::rightMotorPins);
8+
ArduinoRuntime arduino;
9+
BrushedMotor leftMotor(arduino, smartcarlib::pins::v2::leftMotorPins);
10+
BrushedMotor rightMotor(arduino, smartcarlib::pins::v2::rightMotorPins);
1011
DifferentialControl control(leftMotor, rightMotor);
1112

1213
const auto pulsesPerMeter = 600;
1314

1415
DirectionlessOdometer leftOdometer(
15-
smartcarlib::pins::v2::leftOdometerPin, []() { leftOdometer.update(); }, pulsesPerMeter);
16+
arduino,
17+
smartcarlib::pins::v2::leftOdometerPin,
18+
[]() { leftOdometer.update(); },
19+
pulsesPerMeter);
1620
DirectionlessOdometer rightOdometer(
17-
smartcarlib::pins::v2::rightOdometerPin, []() { rightOdometer.update(); }, pulsesPerMeter);
21+
arduino,
22+
smartcarlib::pins::v2::rightOdometerPin,
23+
[]() { rightOdometer.update(); },
24+
pulsesPerMeter);
1825

19-
DistanceCar car(control, leftOdometer, rightOdometer);
26+
DistanceCar car(arduino, control, leftOdometer, rightOdometer);
2027

2128
void setup()
2229
{

examples/Car/rotateOnSpot/rotateOnSpot.ino

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
const int carSpeed = 80; // 80% of the max speed
44
const int GYROSCOPE_OFFSET = 37;
55

6-
BrushedMotor leftMotor(smartcarlib::pins::v2::leftMotorPins);
7-
BrushedMotor rightMotor(smartcarlib::pins::v2::rightMotorPins);
6+
ArduinoRuntime arduino;
7+
BrushedMotor leftMotor(arduino, smartcarlib::pins::v2::leftMotorPins);
8+
BrushedMotor rightMotor(arduino, smartcarlib::pins::v2::rightMotorPins);
89
DifferentialControl control(leftMotor, rightMotor);
910

10-
GY50 gyroscope(GYROSCOPE_OFFSET);
11+
GY50 gyroscope(arduino, GYROSCOPE_OFFSET);
1112

1213
HeadingCar car(control, gyroscope);
1314

0 commit comments

Comments
 (0)