-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathxv11_motor_controller.py
67 lines (56 loc) · 1.69 KB
/
xv11_motor_controller.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
#!/usr/bin/env python
"""Basic PWM Software controller for Neato LDS
Requirements: bare Neato LDS(no logic board)
patched/modified CWRU xv_11_laser_driver package
that implements/exposes an rpm topic
Make Controller board
"""
import sys,os,serial,socket
import getopt
import rospy
from std_msgs.msg import UInt16
import mcontroller
import pdb
class motorctlr (object):
results=0
haslaser=0
rpmport=0
pulseduty=0
minrpm=295
maxrpm=310
rpmcltr=''
def __init__(self,addr):
#set up internal variables and just return a "stub" object
#we expect laserport to be a handle to an already open serial.Serial object
self.results=0
self.haslaser=0
self.pulseduty=768
self.minrpm=295
self.maxrpm=320
self.bootstep=20
self.rpmcheck=0
self.rpmsamples=[]
try:
self.rpmctlr=mcontroller.AppBoard(addr)
self.rpmctlr.set_pwm(0,self.pulseduty,'duty')
except:
sys.exit("Failed to set PWM on Controller")
def rpmctl(self,currpms,step,samples):
rpmval=0
if(len(self.rpmsamples) < samples):
self.rpmsamples.append(currpms)
else:
mean_rpms=(sum(self.rpmsamples))/samples
self.rpmsamples=[]
if mean_rpms < self.minrpm :
self.pulseduty += step
if mean_rpms > self.maxrpm :
self.pulseduty -= step
if mean_rpms < self.maxrpm:
self.pulseduty +=1
try:
self.rpmctlr.set_pwm(0,self.pulseduty,'duty')
print ("current RPM %d pulseduty= %d" ) % (mean_rpms,self.pulseduty)
except:
print "Failed to set PWM on Controller"
exit()