|
15 | 15 | "import numpy as np\n",
|
16 | 16 | "from scipy.interpolate import interp1d\n",
|
17 | 17 | "\n",
|
18 |
| - "# 1. Connect your Luos network (here using an USB module for example)\n", |
| 18 | + "# 1. Connect your Luos network (here using an USB container for example)\n", |
19 | 19 | "r = Device('/dev/cu.usbserial-DN05NM1N')\n",
|
20 |
| - "print(r.modules)\n", |
| 20 | + "print(r.containers)\n", |
21 | 21 | "\n",
|
22 |
| - "# 2. Select the module of your network you need to configure\n", |
23 |
| - "module = r.controlled_moto\n", |
| 22 | + "# 2. Select the container of your network you need to configure\n", |
| 23 | + "container = r.controlled_moto\n", |
24 | 24 | "\n",
|
25 |
| - "# 3. Setup module basic settings\n", |
26 |
| - "module.encoder_res = 3\n", |
27 |
| - "module.reduction = 210.59\n", |
| 25 | + "# 3. Setup container basic settings\n", |
| 26 | + "container.encoder_res = 3\n", |
| 27 | + "container.reduction = 210.59\n", |
28 | 28 | "\n",
|
29 |
| - "SAMPLERATE = 1.0/module.sampling_freq\n", |
| 29 | + "SAMPLERATE = 1.0/container.sampling_freq\n", |
30 | 30 | "\n",
|
31 | 31 | "def run_speed_test(velocity_target):\n",
|
32 |
| - " module.rot_position = False\n", |
33 |
| - " module.rot_speed = True\n", |
34 |
| - " module.current = True\n", |
35 |
| - " module.rot_position_mode = False\n", |
36 |
| - " module.rot_speed_mode = True\n", |
37 |
| - " module.target_rot_speed = 0.0\n", |
38 |
| - " module.compliant = False\n", |
| 32 | + " container.rot_position = False\n", |
| 33 | + " container.rot_speed = True\n", |
| 34 | + " container.current = True\n", |
| 35 | + " container.rot_position_mode = False\n", |
| 36 | + " container.rot_speed_mode = True\n", |
| 37 | + " container.target_rot_speed = 0.0\n", |
| 38 | + " container.compliant = False\n", |
39 | 39 | " target = []\n",
|
40 | 40 | " real = []\n",
|
41 | 41 | " current = []\n",
|
42 | 42 | " test_time_vector = []\n",
|
43 | 43 | " test_start_time = time.time()\n",
|
44 |
| - " target.append(module.target_rot_speed)\n", |
45 |
| - " real.append(module.rot_speed)\n", |
46 |
| - " current.append(module.current)\n", |
| 44 | + " target.append(container.target_rot_speed)\n", |
| 45 | + " real.append(container.rot_speed)\n", |
| 46 | + " current.append(container.current)\n", |
47 | 47 | " test_time = time.time()\n",
|
48 | 48 | " test_time_vector.append(0.0)\n",
|
49 | 49 | " while (test_time < test_start_time + 0.5):\n",
|
50 | 50 | " time.sleep(SAMPLERATE)\n",
|
51 |
| - " target.append(module.target_rot_speed)\n", |
52 |
| - " real.append(module.rot_speed)\n", |
53 |
| - " current.append(module.current)\n", |
| 51 | + " target.append(container.target_rot_speed)\n", |
| 52 | + " real.append(container.rot_speed)\n", |
| 53 | + " current.append(container.current)\n", |
54 | 54 | " test_time_vector.append(test_time - test_start_time)\n",
|
55 | 55 | " test_time = time.time()\n",
|
56 |
| - " module.target_rot_speed = velocity_target\n", |
| 56 | + " container.target_rot_speed = velocity_target\n", |
57 | 57 | " while (test_time < test_start_time + 2.5):\n",
|
58 | 58 | " time.sleep(SAMPLERATE)\n",
|
59 |
| - " target.append(module.target_rot_speed)\n", |
60 |
| - " real.append(module.rot_speed)\n", |
61 |
| - " current.append(module.current)\n", |
| 59 | + " target.append(container.target_rot_speed)\n", |
| 60 | + " real.append(container.rot_speed)\n", |
| 61 | + " current.append(container.current)\n", |
62 | 62 | " test_time_vector.append(test_time - test_start_time)\n",
|
63 | 63 | " test_time = time.time()\n",
|
64 |
| - " module.compliant = True\n", |
| 64 | + " container.compliant = True\n", |
65 | 65 | " plot_test(test_time_vector, target, real, current)\n",
|
66 | 66 | "\n",
|
67 | 67 | "def run_pos_test(pos_target):\n",
|
68 |
| - " module.rot_speed = False\n", |
69 |
| - " module.rot_position = True\n", |
70 |
| - " module.current = True\n", |
71 |
| - " module.rot_speed_mode = False\n", |
72 |
| - " module.rot_position_mode = True\n", |
73 |
| - " module.target_rot_position = 0.0\n", |
74 |
| - " module.compliant = False\n", |
| 68 | + " container.rot_speed = False\n", |
| 69 | + " container.rot_position = True\n", |
| 70 | + " container.current = True\n", |
| 71 | + " container.rot_speed_mode = False\n", |
| 72 | + " container.rot_position_mode = True\n", |
| 73 | + " container.target_rot_position = 0.0\n", |
| 74 | + " container.compliant = False\n", |
75 | 75 | " target = []\n",
|
76 | 76 | " real = []\n",
|
77 | 77 | " current = []\n",
|
78 | 78 | " test_time_vector = []\n",
|
79 | 79 | " test_start_time = time.time()\n",
|
80 |
| - " target.append(module.target_rot_position)\n", |
81 |
| - " real.append(module.rot_position)\n", |
82 |
| - " current.append(module.current)\n", |
| 80 | + " target.append(container.target_rot_position)\n", |
| 81 | + " real.append(container.rot_position)\n", |
| 82 | + " current.append(container.current)\n", |
83 | 83 | " test_time = time.time()\n",
|
84 | 84 | " test_time_vector.append(0.0)\n",
|
85 | 85 | " while (test_time < test_start_time + 1):\n",
|
86 | 86 | " time.sleep(SAMPLERATE)\n",
|
87 |
| - " target.append(module.target_rot_position)\n", |
88 |
| - " real.append(module.rot_position)\n", |
89 |
| - " current.append(module.current)\n", |
| 87 | + " target.append(container.target_rot_position)\n", |
| 88 | + " real.append(container.rot_position)\n", |
| 89 | + " current.append(container.current)\n", |
90 | 90 | " test_time_vector.append(test_time - test_start_time)\n",
|
91 | 91 | " test_time = time.time()\n",
|
92 |
| - " module.target_rot_position = pos_target\n", |
| 92 | + " container.target_rot_position = pos_target\n", |
93 | 93 | " while (test_time < test_start_time + 2.5):\n",
|
94 | 94 | " time.sleep(SAMPLERATE)\n",
|
95 |
| - " target.append(module.target_rot_position)\n", |
96 |
| - " real.append(module.rot_position)\n", |
97 |
| - " current.append(module.current)\n", |
| 95 | + " target.append(container.target_rot_position)\n", |
| 96 | + " real.append(container.rot_position)\n", |
| 97 | + " current.append(container.current)\n", |
98 | 98 | " test_time_vector.append(test_time - test_start_time)\n",
|
99 | 99 | " test_time = time.time()\n",
|
100 | 100 | " \n",
|
101 | 101 | " # create a smooth trajectory\n",
|
102 | 102 | " moveduration = 2\n",
|
103 | 103 | " keypoints = np.array([90, 4, -10, -33, -87, -87, 10, -80, 0])\n",
|
104 | 104 | " x = np.linspace(0, 1, keypoints.shape[-1], endpoint=True)\n",
|
105 |
| - " traj = interp1d(x, keypoints, 'cubic')(np.linspace(0, 1, int(moveduration*module.sampling_freq)))\n", |
| 105 | + " traj = interp1d(x, keypoints, 'cubic')(np.linspace(0, 1, int(moveduration*container.sampling_freq)))\n", |
106 | 106 | " #send traj to motor\n",
|
107 |
| - " module.target_rot_position = traj\n", |
| 107 | + " container.target_rot_position = traj\n", |
108 | 108 | " # wait a bit for the motor to start\n",
|
109 | 109 | " time.sleep(0.03)\n",
|
110 | 110 | " traj_start_time = time.time()\n",
|
111 | 111 | " for i, sample in enumerate(traj):\n",
|
112 | 112 | " target.append(sample)\n",
|
113 |
| - " real.append(module.rot_position)\n", |
114 |
| - " current.append(module.current)\n", |
| 113 | + " real.append(container.rot_position)\n", |
| 114 | + " current.append(container.current)\n", |
115 | 115 | " test_time_vector.append(test_time - test_start_time)\n",
|
116 |
| - " #time.sleep(1.0/module.sampling_freq)\n", |
| 116 | + " #time.sleep(1.0/container.sampling_freq)\n", |
117 | 117 | " while(time.time() < traj_start_time + SAMPLERATE*(i+1)):\n",
|
118 | 118 | " time.sleep(0.004)\n",
|
119 | 119 | " test_time = time.time()\n",
|
|
122 | 122 | " while (test_time < traj_start_time + 0.5):\n",
|
123 | 123 | " time.sleep(SAMPLERATE)\n",
|
124 | 124 | " target.append(traj[len(traj)-1])\n",
|
125 |
| - " real.append(module.rot_position)\n", |
126 |
| - " current.append(module.current)\n", |
| 125 | + " real.append(container.rot_position)\n", |
| 126 | + " current.append(container.current)\n", |
127 | 127 | " test_time_vector.append(test_time - test_start_time)\n",
|
128 | 128 | " test_time = time.time()\n",
|
129 |
| - " module.compliant = True\n", |
| 129 | + " container.compliant = True\n", |
130 | 130 | " plot_test(test_time_vector, target, real, current)\n",
|
131 | 131 | "\n",
|
132 | 132 | "def plot_test(test_time_vector, target, real, current):\n",
|
|
149 | 149 | " \n",
|
150 | 150 | "#motor wiring test\n",
|
151 | 151 | "def wiring_test():\n",
|
152 |
| - " module.setToZero()\n", |
153 |
| - " module.power_mode = True\n", |
154 |
| - " module.compliant = False\n", |
155 |
| - " module.power_ratio = 100.0\n", |
| 152 | + " container.setToZero()\n", |
| 153 | + " container.power_mode = True\n", |
| 154 | + " container.compliant = False\n", |
| 155 | + " container.power_ratio = 100.0\n", |
156 | 156 | " time.sleep(0.5)\n",
|
157 |
| - " module.power_ratio = 0\n", |
158 |
| - " module.compliant = True\n", |
159 |
| - " if (module.rot_position > 1):\n", |
| 157 | + " container.power_ratio = 0\n", |
| 158 | + " container.compliant = True\n", |
| 159 | + " if (container.rot_position > 1):\n", |
160 | 160 | " print(\"Connection OK\")\n",
|
161 |
| - " module.encoder_res = 3\n", |
162 |
| - " module.reduction = 150.0\n", |
163 |
| - " module.positionPid = [4.0,0.02,100] # position PID [P, I, D]\n", |
164 |
| - " module.setToZero()\n", |
| 161 | + " container.encoder_res = 3\n", |
| 162 | + " container.reduction = 150.0\n", |
| 163 | + " container.positionPid = [4.0,0.02,100] # position PID [P, I, D]\n", |
| 164 | + " container.setToZero()\n", |
165 | 165 | " time.sleep(0.1)\n",
|
166 |
| - " module.rot_position_mode = True\n", |
167 |
| - " module.compliant = False\n", |
168 |
| - " module.target_rot_position = 90\n", |
| 166 | + " container.rot_position_mode = True\n", |
| 167 | + " container.compliant = False\n", |
| 168 | + " container.target_rot_position = 90\n", |
169 | 169 | " time.sleep(1)\n",
|
170 |
| - " module.compliant = True\n", |
171 |
| - " if (module.rot_position > 80) :\n", |
| 170 | + " container.compliant = True\n", |
| 171 | + " if (container.rot_position > 80) :\n", |
172 | 172 | " print (\"Sensor direction OK\")\n",
|
173 | 173 | " print (\"Motor OK\")\n",
|
174 | 174 | " else : \n",
|
|
194 | 194 | "outputs": [],
|
195 | 195 | "source": [
|
196 | 196 | "# Speed settings\n",
|
197 |
| - "module.speedPid = [0.1,0.1,1.0] # speed PID [P, I, D]\n", |
| 197 | + "container.speedPid = [0.1,0.1,1.0] # speed PID [P, I, D]\n", |
198 | 198 | "run_speed_test(200.0)"
|
199 | 199 | ]
|
200 | 200 | },
|
|
207 | 207 | "outputs": [],
|
208 | 208 | "source": [
|
209 | 209 | "# position settings\n",
|
210 |
| - "module.positionPid = [3.0, 0.02, 90] # position PID [P, I, D]\n", |
| 210 | + "container.positionPid = [3.0, 0.02, 90] # position PID [P, I, D]\n", |
211 | 211 | "run_pos_test(90.0)"
|
212 | 212 | ]
|
213 | 213 | }
|
|
0 commit comments