This repository has been archived by the owner on Mar 21, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ejemplo.cpp
231 lines (181 loc) · 10.6 KB
/
ejemplo.cpp
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
#include "apstring.h"
#include "kRobot.h"
#include <iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<unistd.h>
#define SOCKET_PORT 8000
/**************************************************************************************
* bool moveBackward();
* Purpose: Makes robot move backwards indefinitely at speeds in private fields
* Preconditions: Serial communications open.
* Postconditions: Robot moves backwards indefinitely. Returns true if
* completed sucessfully, false otherwise.
**************************************************************************************
r.setWheelSpeed(leftSpeed, rightSpeed);
r.moveBackward();
/**************************************************************************************
* bool moveBackwardDistance(int distance);
* Purpose: Makes robot move backward n millimeters.
* Range is 0 < distance <= 670000 mm.
* Preconditions: Serial communications open; distance in millimeters.
* Postconditions: Robot moves backwards n millimeters. Returns true if
* completed sucessfully, false otherwise.
**************************************************************************************
r.moveBackwardDistance(leftSpeed);
/**************************************************************************************
* bool stop();
* Purpose: Stops the movement of the robot.
* Preconditions: Serial communications open; robot in motion.
* Postconditions: Robot stops. Returns true if completed sucessfully, false otherwise.
**************************************************************************************
r.stop();
/**************************************************************************************
* bool turnLeft(int degree);
* Purpose: Makes robot turn left degrees passed as parameter.
* Preconditions: 0<=degrees<=360; Serial communications open.
* Postconditions: Robot turns right n degrees. Returns true if
* completed sucessfully, false otherwise.
**************************************************************************************
r.turnLeft(leftSpeed);
wait(0.2);
/**************************************************************************************
* bool turnRight(int degree);
* Purpose: Makes robot turn right degrees passed as parameter.
* Preconditions: 0<=degrees<=360; Serial communications open.
* Postconditions: Robot turns right n degrees. Returns true if
* completed sucessfully, false otherwise.
**************************************************************************************
r.turnRight(leftSpeed);
wait(0.2);
/**************************************************************************************
* int getLeftWheelCounter();
* Purpose: Reads left wheel counter.
* Preconditions: Serial communications open.
* Postconditions: Returns counter (+ forward, - reverse)
**************************************************************************************
r.getLeftWheelCounter();
/**************************************************************************************
* int getRightWheelCounter();
* Purpose: Reads right wheel counter.
* Preconditions: Serial communications open.
* Postconditions: Returns counter (+ forward, - reverse)
**************************************************************************************
r.getRightWheelCounter();
/**************************************************************************************
* int getLeftWheelSpeed();
* Purpose: Reads the speed and direction (+/-) of left wheel/motor in mm/sec.
* Preconditions: Serial communications open.
* Postconditions: Returns speed and direction of left wheel
**************************************************************************************
r.getLeftWheelSpeed();
/**************************************************************************************
* int getRightWheelSpeed();
* Purpose: Reads the speed and direction (+/-) of right wheel/motor in mm/sec.
* Preconditions: Serial communications open.
* Postconditions: Returns speed and direction of right wheel
**************************************************************************************
r.getRightWheelSpeed();
/**************************************************************************************
* bool setWheelSpeed(int leftSpeed, int rightSpeed);
* Purpose: Sets the speed and direction (+/-) of wheel/motor in mm/sec.
* Range is 0 < speed <= 1000 mm/sec.
* Preconditions: Serial communications open.
* Postconditions: Private fields are updated. Returns true if
* completed sucessfully, false otherwise.
**************************************************************************************
r.setWheelSpeed(leftSpeed,rightSpeed));
/**************************************************************************************
* int getLeftWheelAcceleration();
* Purpose: Reads the acceleration of left wheel/motor in mm/sec^2.
* Preconditions: Serial communications open.
* Postconditions: Returns acceleration of left wheel
**************************************************************************************
r.getLeftWheelAcceleration();
/**************************************************************************************
* int getRightWheelAcceleration();
* Purpose: Reads the acceleration of right wheel/motor in mm/sec^2.
* Preconditions: Serial communications open.
* Postconditions: Returns acceleration of right wheel
**************************************************************************************
r.getRightWheelAcceleration();
/**************************************************************************************
* bool setWheelAcceleration(int leftAcc, int rightAcc);
* Purpose: Sets the acceleration and direction (+/-) of wheel/motor in mm/sec^2.
* Range is 0 < acceleration <= 396875 mm/sec^2.
* Preconditions: Serial communications open.
* Postconditions: Private fields are updated. Returns true if
* completed sucessfully, false otherwise.
**************************************************************************************
r.setWheelAcceleration(leftSpeed,rightSpeed);
/**************************************************************************************
* bool readLightSensors();
* Purpose: Reads the values of each of eight light sensors.
* Preconditions: Serial communication open.
* Postconditions: Stores values of light sensors in an array, indexed
* 0..7, as labeled on Khepera diagram. Returns true if
* completed sucessfully, false otherwise.
**************************************************************************************
r.readLightSensors();
/**************************************************************************************
* bool writeLightSensors();
* Purpose: Displays the values of each of eight light sensors.
* Preconditions: Sensors updated; serial communication open.
* Postconditions: Values of light sensors displayed, indexed
* 0..7 as labeled on Khepera diagram. Returns true if
* completed sucessfully, false otherwise.
**************************************************************************************
r.writeLightSensors();
/**************************************************************************************
* int getLightSensor(int s);
* Purpose: Displays the value of requested sensor as numbered
* on Khepera diagram.
* Preconditions: 0<=s<8; Sensors updated; serial communication open.
* Postconditions: Value returned, 0<=val<1024, larger magnitidue is less light
**************************************************************************************
r.getLightSensor(leftSpeed);
/**************************************************************************************
* bool readProxSensors();
* Purpose: Reads the values of each of eight proximity sensors.
* Preconditions: Serial communication open.
* Postconditions: Stores values of proximity sensors in an array, indexed
* 0..7 as labeled on Khepera diagram. Returns true if
* completed sucessfully, false otherwise.
**************************************************************************************
r.readProxSensors();
/**************************************************************************************
* bool writeProxSensors();
* Purpose: Displays the values of the proximity sensors to the screen.
* Preconditions: Array contains values.
* Postconditions: Values of proximity sensors displayed, indexed
* 0..7 as labeled on Khepera diagram. Returns true if
* completed sucessfully, false otherwise.
**************************************************************************************
r.writeProxSensors();
/**************************************************************************************
* int getProxSensor(int s);
* Purpose: Displays the value of requested sensor as numbered
* on Khepera diagram.
* Preconditions: 0<=s<8; Sensors updated; serial communication open.
* Postconditions: Value returned, 0<=val<1024, larger magnitidue is closer.
**************************************************************************************
r.getProxSensor(leftSpeed);*/
int main()
{
//set serial port for linux
kRobot r("/dev/ttyUSB0",true);
r.reset();
//r.setWheelSpeed(10,10);
//r.moveForward();
/**************************************************************************************
* bool moveForwardDistance(int distance);
* Purpose: Makes robot move forward n millimeters.
* Range is 0 < distance <= 670000 mm.
* Preconditions: Serial communications open; distance in millimeters.
* Postconditions: Robot moves forward n millimeters. Returns true if
* completed sucessfully, false otherwise.
**************************************************************************************/
r.moveForwardDistance(10000);
return 0;
}//main