-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocalizationRobot.py
More file actions
91 lines (64 loc) · 1.59 KB
/
Copy pathlocalizationRobot.py
File metadata and controls
91 lines (64 loc) · 1.59 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
#!/usr/bin/python #this is server file
from socket import * #import socket module
import RPi.GPIO as GPIO
import time
import math
import numpy as np
GPIO.setmode(GPIO.BCM)
GPIO.setup(23, GPIO.OUT)
pwmLeft = GPIO.PWM(23, 100)
GPIO.setup(24, GPIO.OUT)
pwmRight = GPIO.PWM(24, 100)
DEFAULT_SPEED = 15.0
#Defines
noMove = 15 #in percentage for servo PWM
timeInterval = 0.1 #in time second
#fwd
def goFwd():
print "going straight"
pwmLeft.ChangeDutyCycle(17)
pwmRight.ChangeDutyCycle(13)
#right
def goRight():
print "going right"
pwmLeft.ChangeDutyCycle(17)
pwmRight.ChangeDutyCycle(noMove)
#right
def goLeft():
print "going left"
pwmLeft.ChangeDutyCycle(noMove)
pwmRight.ChangeDutyCycle(13)
#stall
def goStop():
print "stop"
pwmLeft.ChangeDutyCycle(noMove)
pwmRight.ChangeDutyCycle(noMove)
print "starting"
#initialize servo to be center
pwmLeft.start(DEFAULT_SPEED)
pwmRight.start(DEFAULT_SPEED)
#set up server
HOST = "192.168.137.129"
PORT = 8888
s = socket(AF_INET, SOCK_STREAM)
#s.bind((HOST,PORT))
#s.listen(1)
#conn, addr = s.accept()
#print "connected by: ", addr
#count = 0
s.connect((HOST, PORT))
print "socket connected to server"
#s.sendall('Hello server')
while True:
#receive command
#data = conn.recv(1)
#data = ord(data)
data = s.recv(1)
data = ord(data)
print data
if (data < 5):
if (data == 2 ): goLeft()
elif (data == 0 ): goRight()
elif (data == 1) : goFwd()
elif (data == 3) : goStop()
GPIO.cleanup()