RoboidControl for Arduino
Loading...
Searching...
No Matches
UltraSonicConfiguration.h
Go to the documentation of this file.
1#include "Roboid.h"
2
3// Hardware
4// ========
5
6#include "UltrasonicSensor.h"
7// PINS NEED CHANGING!!!!
8UltrasonicSensor sensorLeft = UltrasonicSensor(23, // pinTrigger
9 5 // pinEcho
10);
11UltrasonicSensor sensorRight = UltrasonicSensor(18, // pinTrigger
12 19 // pinEcho
13);
14
15#include "DRV8833.h"
16DRV8833 drv8833 = DRV8833(9, // pinAIn1
17 10, // pinAIn2
18 6, // pinBIn1
19 5 // pinBIn2
20);
21
22// Roboid
23// ======
24
25Roboid* RoboidSetup() {
26 Placement configuration[] = {
27 // Sensors
28 Placement(&sensorLeft, -1),
29 Placement(&sensorRight, 1),
30 // Motors
31 Placement(&drv8833.motorA, Vector3::left),
32 Placement(&drv8833.motorB, Vector3::right),
33 };
34
35 Roboid* roboid = new Roboid(configuration, 4);
36 return roboid;
37}
38
39void UpdateRoboid(Roboid* roboid) {
40 // each motor rotates forward with max speed (value: 1),
41 // unless an object is detected nearby.
42 // The left motor is controlled by the sensor on the right
43 // and vice versa
44 bool obstacleLeft = roboid->perception->SwitchOn(-45, 0);
45 bool obstacleRight = roboid->perception->SwitchOn(0, 45);
46
47 float leftMotorSpeed = obstacleRight ? -1.0F : 1.0F;
48 float rightMotorSpeed = obstacleLeft ? -1.0F : 1.0F;
49
50 DifferentialDrive* diffDrive = (DifferentialDrive*)&roboid->propulsion;
51 diffDrive->SetTargetSpeeds(leftMotorSpeed, rightMotorSpeed);
52}
Roboid * RoboidSetup()
Definition UltraSonicConfiguration.h:25
DRV8833 drv8833
Definition UltraSonicConfiguration.h:16
UltrasonicSensor sensorLeft
Definition UltraSonicConfiguration.h:8
void UpdateRoboid(Roboid *roboid)
Definition UltraSonicConfiguration.h:39
UltrasonicSensor sensorRight
Definition UltraSonicConfiguration.h:11
Roboid * roboid
Definition main.cpp:9
static const Vector3 left
A vector3 with values (-1, 0, 0)
Definition Vector3.h:70
static const Vector3 right
A vector with values (1, 0, 0)
Definition Vector3.h:66