forked from robotstreamer/robotstreamer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sexbot_interface.py
153 lines (128 loc) · 3.69 KB
/
sexbot_interface.py
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
import os
import robot_util
import time
import atexit
import serial
import sys
import pigpio
commandArgs = None
#straight speeds 200#300#450
#turn speeds 500#700#450
straightDelay=0.6
stopDelay=0.05
turnDelay=0.5
ser=None
movementSystemActive=None
dildoActive=None
dildoDutyCycle1=10 #percentage
dildoDutyCycle2=20 #percentage
dildoDutyCycle3=30 #percentage
dildoFreq=25 #Hertz
dildoDelay=3 #seconds
pipwm=None #object representing the pwm pin
def getSerial():
ser = serial.Serial(port='/dev/ttyUSB0', baudrate=9600)
return ser
def goForward(ser, speed):
speedBytes=bytes(str(speed), encoding='ascii')+b'\r\n'
ser.write(b'M1: '+speedBytes)
ser.write(b'M2: '+speedBytes)
def goBackward(ser, speed):
speedBytes=bytes(str(speed), encoding='ascii')+b'\r\n'
ser.write(b'M1: -'+speedBytes)
ser.write(b'M2: -'+speedBytes)
def turnRight(ser, speed):
speedBytes=bytes(str(speed), encoding='ascii')+b'\r\n'
ser.write(b'M1: -'+speedBytes)
ser.write(b'M2: '+speedBytes)
def turnLeft(ser, speed):
speedBytes=bytes(str(speed), encoding='ascii')+b'\r\n'
ser.write(b'M1: '+speedBytes)
ser.write(b'M2: -'+speedBytes)
def stopMotors(ser):
ser.write(b'M1: 0\r\n')
ser.write(b'M2: 0\r\n')
def exitTasks():
global ser
global pipwm
pipwm.hardware_PWM(18,0,0)
stopMotors(ser)
ser.close()
def init(cArgs):
global ser
global movementSystemActive
global pipwm
global dildoActive
global commandArgs
ser=getSerial()
movementSystemActive=False
dildoActive=False
pipwm=pigpio.pi()
atexit.register(exitTasks)
pipwm.hardware_PWM(18,0,0)
commandArgs = cArgs
def handleCommand(command, keyPosition, price=0):
global turnDelay
global straightDelay
global ser
global movementSystemActive
global pipwm
global dildoActive
print("\n\n")
if keyPosition != "down":
return
robot_util.handleSoundCommand(command, keyPosition, price)
if command == 'F':
if movementSystemActive:
print("skip")
else:
print("onforward")
movementSystemActive=True
goForward(ser, commandArgs.straight_speed)
time.sleep(straightDelay)
stopMotors(ser)
# time.sleep(stopDelay)
movementSystemActive=False
if command == 'B':
if movementSystemActive:
print("skip")
else:
print("onback")
movementSystemActive=True
goBackward(ser, commandArgs.straight_speed)
time.sleep(straightDelay)
stopMotors(ser)
# time.sleep(stopDelay)
movementSystemActive=False
if command == 'L':
if movementSystemActive:
print("skip")
else:
print("onleft")
movementSystemActive=True
turnLeft(ser, commandArgs.turn_speed)
time.sleep(turnDelay)
stopMotors(ser)
# time.sleep(stopDelay)
movementSystemActive=False
if command == 'R':
if movementSystemActive:
print("skip")
else:
print("onright")
movementSystemActive=True
turnRight(ser, commandArgs.turn_speed)
time.sleep(turnDelay)
stopMotors(ser)
# time.sleep(stopDelay)
movementSystemActive=False
if command[0:6] == 'THRUST':
if dildoActive:
print('skip')
else:
dildoActive=True
dildoDutyCycle=int(command[6:])
pipwm.hardware_PWM(18, dildoFreq, dildoDutyCycle*10000)
time.sleep(dildoDelay)
pipwm.hardware_PWM(18, dildoFreq, 0)
dildoActive=False