-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClassBot.h
More file actions
229 lines (174 loc) · 4.15 KB
/
ClassBot.h
File metadata and controls
229 lines (174 loc) · 4.15 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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
//
// ClassBot.h
//
//
// dependencies:
// AccelStepper
// MultiStepper
//
#ifndef ClassBot_h
#define ClassBot_h
#include <Arduino.h>
#include <avr/pgmspace.h>
#include <AccelStepper.h>
#include <MultiStepper.h>
#include <Servo.h>
#include <math.h>
static const double TWOPI = 6.2831853071795865;
static const double RAD2DEG = 57.2957795130823209;
// Choose one of the fonts from the fonts directory to use
// for drawing text, only one fits in memory at a time. I
// havn't tested all of these but they should work if they
// fit in memory.
#ifdef FONT_ASTROLOGY
#include "fonts/astrology.h"
#endif
#ifdef FONT_CURSIVE
#include "fonts/cursive.h"
#endif
#ifdef FONT_CYRILC_1
#include "fonts/cyrilc_1.h"
#endif
#ifdef FONT_CYRILLIC
#include "fonts/cyrillic.h"
#endif
#ifdef FONT_FUTURAL
#include "fonts/futural.h"
#endif
#ifdef FONT_FUTURAM
#include "fonts/futuram.h"
#endif
#ifdef FONT_GOTHGBT
#include "fonts/gothgbt.h"
#endif
#ifdef FONT_GOTHGRT
#include "fonts/gothgrt.h"
#endif
#ifdef FONT_GOTHICENG
#include "fonts/gothiceng.h"
#endif
#ifdef FONT_GOTHICGER
#include "fonts/gothicger.h"
#endif
#ifdef FONT_GOTHICITA
#include "fonts/gothicita.h"
#endif
#ifdef FONT_GOTHITT
#include "fonts/gothitt.h"
#endif
#ifdef FONT_GREEKC
#include "fonts/greekc.h"
#endif
#ifdef FONT_GREEK
#include "fonts/greek.h"
#endif
#ifdef FONT_GREEKS
#include "fonts/greeks.h"
#endif
#ifdef FONT_JAPANESE
#include "fonts/japanese.h"
#endif
#ifdef FONT_MARKERS
#include "fonts/markers.h"
#endif
#ifdef FONT_MATHLOW
#include "fonts/mathlow.h"
#endif
#ifdef FONT_MATHUPP
#include "fonts/mathupp.h"
#endif
#ifdef FONT_METEOROLOGY
#include "fonts/meteorology.h"
#endif
#ifdef FONT_MUSIC
#include "fonts/music.h"
#endif
#ifdef FONT_ROWMAND
#include "fonts/rowmand.h"
#endif
#ifdef FONT_ROWMANS
#include "fonts/rowmans.h"
#endif
#ifdef FONT_ROWMANT
#include "fonts/rowmant.h"
#endif
#ifdef FONT_SCRIPTC
#include "fonts/scriptc.h"
#endif
#ifdef FONT_SCRIPTS
#include "fonts/scripts.h"
#endif
#ifdef FONT_SYMBOLIC
#include "fonts/symbolic.h"
#endif
#ifdef FONT_TIMESG
#include "fonts/timesg.h"
#endif
#ifdef FONT_TIMESIB
#include "fonts/timesib.h"
#endif
#ifdef FONT_TIMESI
#include "fonts/timesi.h"
#endif
#ifdef FONT_TIMESRB
#include "fonts/timesrb.h"
#endif
#ifdef FONT_TIMESR
#include "fonts/timesr.h"
#endif
// if no font was selected default to rowmans
#ifndef FONT_INCLUDED
#include "fonts/rowmans.h"
#endif
#define MAX_SPEED 1000
#define LEFT 0
#define RIGHT 1
// set for your bot's pen servo
#define PEN_UP_ANGLE 150
#define PEN_DOWN_ANGLE 150 - 90
static int stepsPerRev = 4076; // stepper steps per revloution
static const int backlashComp = 20; // compensation for gear lash
static float wheelDiameter = 65; // mm (increase = spiral out)
static int wheelBase = 112; // mm (increase = spiral in)
static float wheelBPI = wheelBase * PI;
static float stepsDist = stepsPerRev / (wheelDiameter *PI);
class ClassBot
{
public:
ClassBot(int l1 = 9, int l2 = 7, int l3 = 8, int l4 = 6, int r1 = 2, int r2 = 4, int r3 = 3, int r4 = 5, int servoPin = A0);
void penDown();
void penUp();
void moveForward(float distance);
void moveBackward(float distance);
void turnLeft(float degrees);
void turnRight(float degrees);
void turnTo(float heading);
void moveTo(long x, long y, boolean penUp=true, float scale = 1);
void drawChar(char ch, float scale = 1);
void writeText(char *str, float scale = 1);
void done();
void setX(long x);
void setY(long y);
void setH(float degrees);
boolean getPen();
long getX();
long getY();
float getH();
private:
long botX = 0; // at origin
long botY = 0;
float botH = 0; // facing north
boolean penIsUp;
AccelStepper *leftMotor;
AccelStepper *rightMotor;
MultiStepper motors;
long steps[2] = { 0, 0 };
int lastPos[2] = { -1, -1 };
Servo penServo;
void setStep(int which, float dist);
double bearing(double a1, double a2, double b1, double b2);
};
#endif
//
// EOF
//