-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAndroidRCReferenceCar.h
More file actions
169 lines (157 loc) · 4.71 KB
/
AndroidRCReferenceCar.h
File metadata and controls
169 lines (157 loc) · 4.71 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*
* Copyright (C) 2012 Sven Nobis
*
* This file is part of AndroidRCCar (http://androidrccar.sven.to)
*
* AndroidRCCar is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This source code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this source code; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __AndroidRCReferenceCar_h__
#define __AndroidRCReferenceCar_h__
#define __STDC_LIMIT_MACROS
#include <stdint.h>
#include <AndroidRCCarCommunication.h>
#include <CarFeatures.h>
#include <AFMotor.h>
#include <Servo.h>
#include<Arduino.h>
#include "TwoCellLiPolBattery.h"
/**
* @brief The AndroidRCReferenceCar class providing the implementation
* of the software for the reference hardware.
*/
class AndroidRCReferenceCar : public AndroidRCCarCommunication {
public:
/**
* @brief Default constructor
*/
AndroidRCReferenceCar():
AndroidRCCarCommunication("Reference Car"),
frontLeftMotor(4),
frontRightMotor(3),
backLeftMotor(1),
backRightMotor(2),
panServo(Servo()),
tiltServo(Servo()),
battery(40, A0, A1),
currentSpeed(0),
currentRotation(0)
{
}
/**
* @brief Stops all motors and rotates the camera to initial position.
*/
void resetAll();
protected:
/**
* {@inheritDoc}
*/
virtual bool turnCar(int16_t rotation);
/**
* {@inheritDoc}
*/
virtual int16_t getBatteryState();
/**
* {@inheritDoc}
* (All Features are supported.)
*/
virtual CarFeatures getFeatures();
/**
* {@inheritDoc}
*/
virtual bool adjustSpeed(int16_t speed);
/**
* {@inheritDoc}
*/
virtual bool rotateCam(int16_t pan, int16_t tilt);
/**
* @brief Attach Servo, resetAll() and check battery power
*/
virtual void doSetUp();
/**
* {@inheritDoc}
*/
virtual bool answerBatteryNearEmpty();
private:
/**
* @brief The speed or rotation wheel has changed. Set new motor speed.
*/
void updateMotors();
/**
* @brief Sets the run of the motor.
* @param run
*/
void setMotorRun(int run);
/**
* @brief Maps a received pan value to the correct value for the servo.
* @param receivedPan The received pan to map
* @return The received value mapped to the value for the servo.
*/
int mapServoPanValue(int16_t receivedPan);
/**
* @brief Maps a received tilt value to the correct value for the servo.
* @param receivedPan The received pan to map
* @return The received value mapped to the value for the servo.
*/
int mapServoTiltValue(int16_t receivedTilt);
/**
* @brief Returns the mapped speed for the left motors.
* The value is mapped from the speed combined with the turnCar value.
* @return mapped speed for the left motors
*/
int mapLeftMotorSpeed();
/**
* @brief Returns the mapped speed for the right motors.
* The value is mapped from the speed combined with the turnCar value.
* @return mapped speed for the left motors
*/
int mapRightMotorSpeed();
/**
* @brief The object for reading the battery state
*/
TwoCellLiPolBattery battery;
/**
* @brief Front left motor
*/
AF_DCMotor frontLeftMotor;
/**
* @brief Front right motor
*/
AF_DCMotor frontRightMotor;
/**
* @brief Back left motor
*/
AF_DCMotor backLeftMotor;
/**
* @brief Back right motor
*/
AF_DCMotor backRightMotor;
/**
* @brief Servo for panning the camera
*/
Servo panServo;
/**
* @brief Servo for tilting the camera
*/
Servo tiltServo;
/**
* @brief currentSpeed of the car as the received value (not mapped!)
*/
int16_t currentSpeed;
/**
* @brief currentRotation of the car as the received value (not mapped!)
*/
int16_t currentRotation;
};
#endif