generated from hariharan382/blog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjoy_dir.py
80 lines (61 loc) · 1.94 KB
/
joy_dir.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
#! /usr/binenv python3
from math import sin
from numpy.lib.polynomial import poly1d
from numpy.matrixlib.defmatrix import matrix
import rospy
import numpy as np
import matplotlib.pyplot as plt
from sensor_msgs.msg import Joy
from matplotlib.animation import FuncAnimation
from servo_topic.src.gait_check import rotz
h=4
s=8
def rotz(gamma):
rz = np.array([[cos(gamma), -sin(gamma), 0],
[sin(gamma), cos(gamma), 0],
[0, 0, 1])
return rz
mat = np.matrix([[1, -6, 15, -20, 15, -6, 1],
[-6, 30, -60, 60, -30, 6, 0],
[15, -60, 90, -60, 15, 0, 0],
[-20, 60, -60, 20, 0, 0, 0],
[15, -30, 15, 0, 0, 0, 0],
[-6, 6, 0, 0, 0, 0, 0],
[1, 0, 0, 0, 0, 0, 0]])
def callback(data):
front_back=data.axes[1]
right_left=-data.axes[0]
len=data.axes[2]
global ang=np.arctan2(front_back,right_left) * 180 / np.pi
h=5
if(ang <0):
ang=360+ang
def animate(ang):
r_z=rotz(ang)
p1=np.matrix([[0,s/2,0],
[0,s,0],
[0,s+1,(3*h/4)+1],
[0,s/2,h],
[0,0,(3*h/2)],
[0,0,0],
[0,s/2,0]])
point_matrix=r_z@p1
p = np.matrix([t ** 6, t ** 5, t ** 4, t ** 3, t ** 2, t, 1])
for t in np.arange(0,1,0.5):
x1=p@mat@point_matrix[:,0]
y1=p@mat@point_matrix[:,1]
z1=p@mat@point_matrix[:,2]
plt.plot(x1,y1,z1,label="joystick")
plt.plt.tight_layout()
rospy.loginfo("%f",ang)
ani=FuncAnimation(plt.plt.gcf(),animate,interval=10)
def listener():
rospy.init_node("joy_listener_node",anonymous=True)
rospy.Subscriber("/joy",Joy,callback)
rospy.spin()
def animate(i):
if __name__ == '__main__':
try:
listener()
except rospy.ROSInterruptException:
pass