Skip to content

Commit d51a5cc

Browse files
Sylwester DawidaSylwester Dawida
Sylwester Dawida
authored and
Sylwester Dawida
committed
final code
1 parent 9f015b2 commit d51a5cc

10 files changed

+100
-112
lines changed

python/.idea/workspace.xml

+24-34
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

python/C_code/arduinoTestCode/arduinoTestCode.ino

+46-55
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const char robotError = 5;
2323
const char RobotReady = 6;
2424
const char accessDenyed = 7;
2525

26-
const char* secourityCode = "QV9";
26+
const char* secourityCode = "QV9JKMNASKJNWKJSNKWJ";
2727
//comunication data
2828
char messageId = 1;
2929
int gotBytes = 0;
@@ -139,15 +139,19 @@ void loop()
139139
if (message)
140140
checkData();
141141
if (state == commandExecution) {
142-
checkIfExecuted();
142+
if (arlo.available()) {
143+
char ch = arlo.read();
144+
setFrame(mobileRobot, command, commandId, messageId++, commandExecuted);
145+
Serial.write(frame, 6);
146+
}
143147
}
144148
}
145149
}
146150

147151
bool checkNewConnection() {
148152
int i = 0;
149153
newConnection = false;
150-
unsigned long time = millis() + 5000;
154+
unsigned long time = millis() + 1000;
151155
while ( millis() < time) {
152156
while (Serial.available()) {
153157
formatBuff[i] = Serial.read();
@@ -185,10 +189,6 @@ void readData() {
185189

186190
}
187191

188-
void drive_speed(int , int) {
189-
190-
}
191-
192192
void checkData() {
193193
// check command
194194
deviceId = frame[0];
@@ -197,15 +197,12 @@ void checkData() {
197197
messageIdExternal = frame[3];
198198
additionalInfo = frame[4];
199199
message = false;
200-
show();
201-
delay(500);
202200
setExecutionParameters();
203201

204202
}
205203

206204
void stop() {
207-
Serial.println("stop");
208-
drive_speed(0, 0);
205+
drive_speed(0, 0, 0);
209206
state = waiting;
210207
}
211208

@@ -214,7 +211,38 @@ void setExecutionParameters() {
214211
Serial.println("default");
215212
return;
216213
}
217-
if (command >= speedUp) { //controll setting commands executed instant
214+
if(command < speedUp){ //executable commands
215+
bool error = false;
216+
if (command == forward) {
217+
leftEnd = step;
218+
rightEnd = step;
219+
drive_speed(speed, speed, step);
220+
} else if (command == backward) {
221+
leftEnd = step;
222+
rightEnd = step;
223+
drive_speed(-speed, -speed, step);
224+
} else if (command == turnLeft) {
225+
leftEnd = turn;
226+
rightEnd = turn;
227+
drive_speed(-speed, speed, turn);
228+
} else if (command == turnRight) {
229+
leftEnd = turn;
230+
rightEnd = turn;
231+
drive_speed(speed, -speed, turn);
232+
} else if (command == turnAround) {
233+
leftEnd = halfTurn;
234+
rightEnd = halfTurn;
235+
drive_speed(speed, -speed, halfTurn);
236+
} else {
237+
error = true;
238+
}
239+
setFrame(mobileRobot, command, commandId, messageId++, error ? commandError : commandAccepted);
240+
Serial.write( frame, 6);
241+
//show();
242+
state = commandExecution;
243+
executionCommand = command;
244+
executionCommandId = commandId;
245+
} else { //controll setting commands executed instant
218246
int signR, signL;
219247
bool error = false;
220248
if (command == speedUp) {
@@ -248,53 +276,16 @@ void setExecutionParameters() {
248276
}
249277
setFrame(mobileRobot, command, commandId, messageId++, error ? commandError : commandExecuted);
250278
Serial.write(frame, 6);
251-
} else { //executable commands
252-
bool error = false;
253-
if (command == forward) {
254-
leftEnd = step;
255-
rightEnd = step;
256-
drive_speed(speed, speed, step);
257-
} else if (command == backward) {
258-
leftEnd = step;
259-
rightEnd = step;
260-
drive_speed(-speed, -speed, step);
261-
} else if (command == turnLeft) {
262-
leftEnd = turn;
263-
rightEnd = turn;
264-
drive_speed(-speed, speed, turn);
265-
} else if (command == turnRight) {
266-
leftEnd = turn;
267-
rightEnd = turn;
268-
drive_speed(speed, -speed, turn);
269-
} else if (command == turnAround) {
270-
leftEnd = halfTurn;
271-
rightEnd = halfTurn;
272-
drive_speed(speed, -speed, halfTurn);
273-
} else {
274-
error = true;
275-
}
276-
setFrame(mobileRobot, command, commandId, messageId++, error ? commandError : commandAccepted);
277-
Serial.write( frame, 6);
278-
//show();
279-
state = commandExecution;
280-
executionCommand = command;
281-
executionCommandId = commandId;
282-
}
283-
}
284-
285-
void checkIfExecuted() {
286-
if (arlo.available()) {
287-
char ch = arlo.read();
288-
if(ch == 'r')
289-
stop();
290-
setFrame(mobileRobot, command, commandId, messageId++, commandExecuted);
291-
Serial.write(frame, 6);
292-
//show();
293-
}
279+
}
294280
}
295281

296282
void drive_speed(int left, int right, int endD){
297283
char sec = 184;
284+
if(!left){
285+
char l = 1;
286+
arlo.write(l);
287+
return;
288+
}
298289
arlo.write(sec);
299290
char cleft = 127 + left;
300291
arlo.write(cleft);

python/C_code/arlo2.0.binary

0 Bytes
Binary file not shown.

python/C_code/arlo2.0.c

+8-4
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,19 @@ void getData() {
4646
//dprint(xbee, "You typed: %d %d %d\n", speedR, speedL, end);
4747
myWait();
4848
c = fdserial_rxChar(xbee);
49-
end = 20 * (int)c;
49+
end = 2 * (int)c;
5050
if(!end){
5151
emergency = 1;
5252
continue;
5353
}
5454
//dprint(xbee, "You typed: %d %d %d\n", speedR, speedL, end);
5555
ready = 1;
56-
while(ready)
57-
;
56+
while(ready){
57+
if(fdserial_rxReady(xbee) == 1){
58+
c = fdserial_rxChar(xbee);
59+
emergency = 1;
60+
}
61+
}
5862
commandEnded = 0;
5963
dprint(xbee, "r");
6064
}
@@ -83,7 +87,7 @@ int main()
8387
drive_speed(speedL, speedR);
8488
ticksR = 0;
8589
print("before3\n"); // 20/127 of full power to motors
86-
while(abs(ticksR) < end || emergency)
90+
while(abs(ticksR) < end && !emergency)
8791
drive_getTicks(&ticksL, &ticksR);
8892
drive_speed(0,0);
8993
emergency = 0;

python/C_code/arlo2.0.elf

0 Bytes
Binary file not shown.

python/C_code/cmm/arlo2.0.binary

32 Bytes
Binary file not shown.

python/C_code/cmm/arlo2.0.elf

27 Bytes
Binary file not shown.
Binary file not shown.

python/mainApplication.py

+17-12
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,20 @@ def setupUi(self, RobotController):
2929
RobotController.resize(1400, 700)
3030

3131
RobotController.emergency.connect(self.emergencyStop)
32+
RobotController.network.connect(self.capture)
3233

3334
self.centralwidget = QtWidgets.QWidget(RobotController)
3435
self.centralwidget.setObjectName("centralwidget")
3536

37+
self.pushButton_5 = QtWidgets.QPushButton(self.centralwidget)
38+
self.pushButton_5.setGeometry(QtCore.QRect(900, 48, 80, 60))
39+
font = QtGui.QFont()
40+
font.setFamily("Arial")
41+
font.setPointSize(15)
42+
self.pushButton_5.setFont(font)
43+
self.pushButton_5.setAcceptDrops(False)
44+
self.pushButton_5.setObjectName("pushButton_5")
45+
3646
self.pushButton_4 = QtWidgets.QPushButton(self.centralwidget)
3747
self.pushButton_4.setGeometry(QtCore.QRect(1200, 48, 80, 60))
3848
font = QtGui.QFont()
@@ -69,15 +79,6 @@ def setupUi(self, RobotController):
6979
self.pushButton_2.setAcceptDrops(False)
7080
self.pushButton_2.setObjectName("pushButton_2")
7181

72-
self.pushButton_5 = QtWidgets.QPushButton(self.centralwidget)
73-
self.pushButton_5.setGeometry(QtCore.QRect(900, 48, 80, 60))
74-
font = QtGui.QFont()
75-
font.setFamily("Arial")
76-
font.setPointSize(15)
77-
self.pushButton_5.setFont(font)
78-
self.pushButton_5.setAcceptDrops(False)
79-
self.pushButton_5.setObjectName("pushButton_5")
80-
8182
self.textBrowser = QtWidgets.QTextBrowser(self.centralwidget)
8283
self.textBrowser.setGeometry(QtCore.QRect(50, 230, 500, 280))
8384
font = QtGui.QFont()
@@ -254,17 +255,18 @@ def send(self, recognized=None):
254255
if self.comboBox.currentIndex() == 0:
255256
pass
256257
else:
257-
self.print(self.comboBox.currentData())
258258
command = self.commands.commands(int(self.comboBox.currentData()))
259259
self.comboBox.setCurrentIndex(0)
260260
if command == self.commands.commands.default:
261261
pass
262262
elif command == self.commands.commands.stopCommand:
263263
self.emergencyStop()
264+
self.print("Emergency stop")
264265
elif command.value < self.commands.commands.speedUp.value and self.commands.watchDog: # acvive command not settings
265266
self.print("Cannot send command, one is already in execution: {}".format(
266267
self.commands.watchDog[0].command.name))
267268
else:
269+
self.print(command.name)
268270
self.commands.executeCommand(command)
269271
except Exception as e:
270272
self.print(e)
@@ -297,10 +299,10 @@ def getRecognitionResult(self, image, output):
297299

298300
def computeGesture(self, output):
299301
index = argmax(output).item() + 1 # label
300-
if (not self.gesturesCapturing) or (not self.netowkrProcess) or index != self.lastCompute:
302+
if (not self.gesturesCapturing) or index == 1 or (not self.netowkrProcess) or index != self.lastCompute:
301303
self.time = time()
302304
self.frames = 0
303-
elif time() - self.time > 1 and self.frames > 15:
305+
elif time() - self.time > 2 and self.frames > 15:
304306
command = self.commands.commands(index)
305307
self.print("Recognized: {}".format(command.name))
306308
self.send(command)
@@ -311,6 +313,7 @@ def computeGesture(self, output):
311313

312314
class MyWindow(QtWidgets.QMainWindow):
313315
emergency = pyqtSignal()
316+
network = pyqtSignal()
314317

315318
def __init__(self, parent=None):
316319
QtWidgets.QMainWindow.__init__(self, parent=parent)
@@ -319,6 +322,8 @@ def keyPressEvent(self, event):
319322
if type(event) == QtGui.QKeyEvent:
320323
if event.key() == QtCore.Qt.Key_Shift:
321324
self.emergency.emit()
325+
elif event.key() == QtCore.Qt.Key_Control:
326+
self.network.emit()
322327

323328

324329
if __name__ == '__main__':

0 commit comments

Comments
 (0)