-
Notifications
You must be signed in to change notification settings - Fork 0
/
gridCar.ino
73 lines (61 loc) · 1.67 KB
/
gridCar.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "src/timer/arduinoTimer.hpp"
#include "src/movement/tracker/arduinoTracker.hpp"
#include "src/movement/motor/arduinoMotor.hpp"
#include "src/movement/position/gridPosition.hpp"
#include "src/movement/position/coordinate.hpp"
#include "src/movement/motion/motionName.hpp"
#include "src/movement/linePilot.hpp"
#include "src/movement/gridGoal.hpp"
#include "src/communication/arduinoTransmitter.hpp"
#include "src/communication/messageIn.hpp"
#include "src/communication/messageOut.hpp"
#include <SPI.h>
#include <RF24.h>
// Arduino instances
ArduinoTracker tracker{A1, A2, A3};
ArduinoTimer timer{};
ArduinoMotor motor{4, 6, 3, 5};
RF24 radio{9, 10};
const unsigned char address[5] = {'C', 'a', 'r', '0', '1'};
ArduinoTransmitter transmitter{ address, radio };
// Internal instances
MessageOut messageOut{ transmitter };
MessageIn messageIn{ transmitter };
GridPosition position;
GridGoal goal{ Coordinate(3, 2) }; // Grid size
LinePilot pilot(goal, position, tracker, timer, motor);
// Arduino functions
void setup() {
setTuningParameters();
setStartState();
setupArduino();
setupCommunication();
}
void loop() {
messageIn.receive();
pilot.move();
}
// Helper functions
void setTuningParameters()
{
motor.setDefaultSpeed( 100 );
pilot.setAlignmentPeriodInTurn( 100 );
}
void setStartState()
{
position.setLocation( Coordinate(0, 0) );
position.setDirection( Direction::positiveY );
goal.set( Coordinate(2, 1) );
pilot.changeMotion( MotionName::cross );
}
void setupArduino()
{
transmitter.setup();
tracker.setup();
motor.setup();
}
void setupCommunication()
{
goal.listenTo( messageIn );
messageOut.listenTo( position );
}