-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroboclaw_readcurrent.py
executable file
·47 lines (40 loc) · 1.22 KB
/
roboclaw_readcurrent.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
'''
# brief : This script is code to measurement moter current.
# @author : koji kawabata
# @date : 2019/11/15
'''
import sys,signal,time
import roboclaw_driver.roboclaw_driver as rc
def handler(signal,frame):
rc.SpeedM1M2(address, 0, 0)
sys.exit(0)
def displayCurrent():
crc, l_currentA, r_currentA = rc.ReadCurrents(address)
elapsed_time = time.time() - start
l_currentA /= 100.0
r_currentA /= 100.0
if crc == 1:
# print("M1 moter current "+'{:.3}'.format(l_current)+"[A]")
# print("M2 moter current "+'{:.3}'.format(r_current)+"[A]")
print("elapsed_time:{0}".format(elapsed_time)+"[sec] "+
"M1 moter current "+'{:.3}'.format(l_currentA)+"[A]")
print("elapsed_time:{0}".format(elapsed_time)+"[sec] "+
"M2 moter current "+'{:.3}'.format(r_currentA)+"[A]")
else:
print("Failed")
rc.Open('/dev/ttyACM0',115200)
signal.signal(signal.SIGINT,handler)
address = 0x80
try:
# loop until ctl + c
m1_qpps = m2_qpps = 200
rc.SpeedM1M2(address, m1_qpps, m2_qpps)
time.sleep(0.5)
start = time.time()
while True:
displayCurrent()
time.sleep(0.01)
except Exception as e:
print(e)
finally:
rc.SpeedM1M2(address, 0, 0)