|
1 | 1 | #!/usr/bin/env python3 |
| 2 | +import socket |
2 | 3 | import tkinter |
3 | 4 | from tkinter import ttk |
4 | 5 | import time |
5 | 6 | import threading |
6 | 7 | import os |
| 8 | +import textwrap |
7 | 9 | import serial |
8 | 10 | import serial.tools.list_ports |
9 | 11 |
|
@@ -123,11 +125,11 @@ def run(self): |
123 | 125 | # Connect method |
124 | 126 | # ============================================================ |
125 | 127 | def connect_mycobot(self): |
126 | | - port = self.port_list.get() |
| 128 | + self.prot = port = self.port_list.get() |
127 | 129 | if not port: |
128 | 130 | self.write_log_to_Text("请选择串口") |
129 | 131 | return |
130 | | - baud = self.baud_list.get() |
| 132 | + self.baud = baud = self.baud_list.get() |
131 | 133 | if not baud: |
132 | 134 | self.write_log_to_Text("请选择波特率") |
133 | 135 | return |
@@ -291,101 +293,113 @@ def _aging_test(self): |
291 | 293 | Aging test thread target. |
292 | 294 | By using in `start_aging_test()` and `stop_aging_test()`. |
293 | 295 | """ |
| 296 | + # if socket.gethostname() != "pi": |
| 297 | + # self.write_log_to_Text("老化测试支持 Raspberry OS.") |
| 298 | + # return |
| 299 | + |
| 300 | + aging_test_content_py = textwrap.dedent( |
| 301 | + """\ |
| 302 | + #!/usr/bin/python3 |
| 303 | +
|
| 304 | + from pymycobot.mycobot import MyCobot |
| 305 | + from pymycobot import PI_PORT, PI_BAUD |
| 306 | + import time |
| 307 | +
|
| 308 | +
|
| 309 | + mycobot = MyCobot('%s', %s) |
| 310 | +
|
| 311 | + def aging_test(): |
| 312 | + # fast |
| 313 | + mycobot.wait(5).send_angles([0, 0, 0, 0, 0, 0], 95) |
| 314 | + mycobot.wait(3).send_angles([170, 0, 0, 0, 0, 0], 95) |
| 315 | + mycobot.wait(3).send_angles([-170, 0, 0, 0, 0, 0], 95) |
| 316 | + mycobot.wait(3).send_angles([0, 0, 0, 0, 0, 0], 95) |
| 317 | + mycobot.wait(3).send_angles([0, 90, 0, 0, 0, 0], 95) |
| 318 | + mycobot.wait(3).send_angles([0, -90, 0, 0, 0, 0], 95) |
| 319 | + mycobot.wait(3).send_angles([0, 0, 0, 0, 0, 0], 95) |
| 320 | + mycobot.wait(3).send_angles([0, 0, 140, 0, 0, 0], 95) |
| 321 | + mycobot.wait(3).send_angles([0, 0, -140, 0, 0, 0], 95) |
| 322 | + mycobot.wait(3).send_angles([0, 0, 0, 0, 0, 0], 95) |
| 323 | + mycobot.wait(3).send_angles([0, 0, 0, 130, 0, 0], 95) |
| 324 | + mycobot.wait(3).send_angles([0, 0, 0, -110, 0, 0], 95) |
| 325 | + mycobot.wait(3).send_angles([0, 0, 0, 0, 0, 0], 95) |
| 326 | + mycobot.wait(3).send_angles([0, 0, 0, 0, 165, 0], 95) |
| 327 | + mycobot.wait(3).send_angles([0, 0, 0, 0, -165, 0], 95) |
| 328 | + mycobot.wait(3).send_angles([0, 0, 0, 0, 0, 0], 95) |
| 329 | + mycobot.wait(3).send_angles([0, 0, 0, 0, 0, 180], 95) |
| 330 | + mycobot.wait(3).send_angles([0, 0, 0, 0, 0, -180], 95) |
| 331 | +
|
| 332 | + # middle |
| 333 | + mycobot.wait(3).send_angles([0, 0, 0, 0, 0, 0], 55) |
| 334 | + mycobot.wait(5).send_angles([170, 0, 0, 0, 0, 0], 55) |
| 335 | + mycobot.wait(6.5).send_angles([-170, 0, 0, 0, 0, 0], 55) |
| 336 | + mycobot.wait(5).send_angles([0, 0, 0, 0, 0, 0], 55) |
| 337 | + mycobot.wait(5).send_angles([0, 90, 0, 0, 0, 0], 55) |
| 338 | + mycobot.wait(5).send_angles([0, -90, 0, 0, 0, 0], 55) |
| 339 | + mycobot.wait(5).send_angles([0, 0, 0, 0, 0, 0], 55) |
| 340 | + mycobot.wait(5).send_angles([0, 0, 140, 0, 0, 0], 55) |
| 341 | + mycobot.wait(5).send_angles([0, 0, -140, 0, 0, 0], 55) |
| 342 | + mycobot.wait(5).send_angles([0, 0, 0, 0, 0, 0], 55) |
| 343 | + mycobot.wait(5).send_angles([0, 0, 0, 130, 0, 0], 55) |
| 344 | + mycobot.wait(5).send_angles([0, 0, 0, -110, 0, 0], 55) |
| 345 | + mycobot.wait(5).send_angles([0, 0, 0, 0, 0, 0], 55) |
| 346 | + mycobot.wait(5).send_angles([0, 0, 0, 0, 165, 0], 55) |
| 347 | + mycobot.wait(5).send_angles([0, 0, 0, 0, -165, 0], 55) |
| 348 | + mycobot.wait(5).send_angles([0, 0, 0, 0, 0, 0], 55) |
| 349 | + mycobot.wait(5).send_angles([0, 0, 0, 0, 0, 180], 55) |
| 350 | + mycobot.wait(5).send_angles([0, 0, 0, 0, 0, -180], 55) |
| 351 | +
|
| 352 | + # slow |
| 353 | + mycobot.wait(5).send_angles([0, 0, 0, 0, 0, 0], 15) |
| 354 | + mycobot.wait(7).send_angles([170, 0, 0, 0, 0, 0], 15) |
| 355 | + mycobot.wait(7).send_angles([-170, 0, 0, 0, 0, 0], 15) |
| 356 | + mycobot.wait(11).send_angles([0, 0, 0, 0, 0, 0], 15) |
| 357 | + mycobot.wait(7).send_angles([0, 90, 0, 0, 0, 0], 15) |
| 358 | + mycobot.wait(7).send_angles([0, -90, 0, 0, 0, 0], 15) |
| 359 | + mycobot.wait(0).send_angles([0, 0, 0, 0, 0, 0], 15) |
| 360 | + mycobot.wait(7).send_angles([0, 0, 140, 0, 0, 0], 15) |
| 361 | + mycobot.wait(7).send_angles([0, 0, -140, 0, 0, 0], 15) |
| 362 | + mycobot.wait(11).send_angles([0, 0, 0, 0, 0, 0], 15) |
| 363 | + mycobot.wait(7).send_angles([0, 0, 0, 130, 0, 0], 15) |
| 364 | + mycobot.wait(7).send_angles([0, 0, 0, -110, 0, 0], 15) |
| 365 | + mycobot.wait(11).send_angles([0, 0, 0, 0, 0, 0], 15) |
| 366 | + mycobot.wait(7).send_angles([0, 0, 0, 0, 165, 0], 15) |
| 367 | + mycobot.wait(7).send_angles([0, 0, 0, 0, -165, 0], 15) |
| 368 | + mycobot.wait(11).send_angles([0, 0, 0, 0, 0, 0], 15) |
| 369 | + mycobot.wait(7).send_angles([0, 0, 0, 0, 0, 180], 15) |
| 370 | + mycobot.wait(7).send_angles([0, 0, 0, 0, 0, -180], 15) |
| 371 | +
|
| 372 | +
|
| 373 | + if __name__ == '__main__': |
| 374 | + while True: |
| 375 | + aging_test() |
| 376 | + """ |
| 377 | + % (self.prot, self.baud) |
| 378 | + ) |
294 | 379 |
|
295 | | - aging_test_content_py = """\ |
296 | | -#!/usr/bin/python3 |
297 | | -
|
298 | | -from pymycobot.mycobot import MyCobot |
299 | | -from pymycobot import PI_PORT, PI_BAUD |
300 | | -import time |
301 | | -
|
302 | | -
|
303 | | -mycobot = MyCobot(PI_PORT, PI_BAUD) |
304 | | -
|
305 | | -def aging_test(): |
306 | | - mycobot.send_angles([0, 0, 0, 0, 0, 0], 90) |
307 | | - time.sleep(2.5) |
308 | | -
|
309 | | - mycobot.send_angles([170, 0, 0, 0, 0, 0], 90) |
310 | | - time.sleep(2) |
311 | | -
|
312 | | - mycobot.send_angles([-170, 0, 0, 0, 0, 0], 90) |
313 | | - time.sleep(3.5) |
314 | | -
|
315 | | - mycobot.send_angles([0, 0, 0, 0, 0, 0], 90) |
316 | | - time.sleep(2) |
317 | | -
|
318 | | - mycobot.send_angles([0, 90, 0, 0, 0, 0], 90) |
319 | | - time.sleep(2) |
320 | | -
|
321 | | - mycobot.send_angles([0, -90, 0, 0, 0, 0], 90) |
322 | | - time.sleep(3.5) |
323 | | -
|
324 | | - mycobot.send_angles([0, 0, 0, 0, 0, 0], 90) |
325 | | - time.sleep(2.5) |
326 | | -
|
327 | | - mycobot.send_angles([0, 0, 140, 0, 0, 0], 90) |
328 | | - time.sleep(2) |
329 | | -
|
330 | | - mycobot.send_angles([0, 0, -140, 0, 0, 0], 90) |
331 | | - time.sleep(3.5) |
332 | | -
|
333 | | - mycobot.send_angles([0, 0, 0, 0, 0, 0], 90) |
334 | | - time.sleep(2) |
335 | | -
|
336 | | - mycobot.send_angles([0, 0, 0, 130, 0, 0], 90) |
337 | | - time.sleep(2) |
338 | | -
|
339 | | - mycobot.send_angles([0, 0, 0, -110, 0, 0], 90) |
340 | | - time.sleep(3.5) |
341 | | -
|
342 | | - mycobot.send_angles([0, 0, 0, 0, 0, 0], 90) |
343 | | - time.sleep(2.5) |
344 | | -
|
345 | | - mycobot.send_angles([0, 0, 0, 0, 165, 0], 90) |
346 | | - time.sleep(2) |
347 | | -
|
348 | | - mycobot.send_angles([0, 0, 0, 0, -165, 0], 90) |
349 | | - time.sleep(3.5) |
350 | | -
|
351 | | - mycobot.send_angles([0, 0, 0, 0, 0, 0], 90) |
352 | | - time.sleep(2.5) |
353 | | -
|
354 | | - mycobot.send_angles([0, 0, 0, 0, 0, 180], 90) |
355 | | - time.sleep(2) |
356 | | -
|
357 | | - mycobot.send_angles([0, 0, 0, 0, 0, -180], 90) |
358 | | - time.sleep(3.5) |
359 | | -
|
360 | | -
|
361 | | -if __name__ == '__main__': |
362 | | - #i=10 |
363 | | - while 1: |
364 | | - aging_test() |
365 | | - # i-=1 |
366 | | -
|
367 | | - """ |
368 | | - |
369 | | - aging_test_content_sh = """\ |
370 | | -#!/bin/bash |
371 | | -/usr/bin/python3 /home/pi/Desktop/aging_test.py |
372 | | -
|
373 | | - """ |
374 | | - |
375 | | - aging_test_content_service = """\ |
376 | | -[Unit] |
377 | | -Description=aging-test |
378 | | -
|
379 | | -[Service] |
380 | | -Type=forking |
381 | | -Restart=on-failure |
382 | | -RestartSec=2 |
383 | | -ExecStart=/home/pi/aging_test.sh |
384 | | -
|
385 | | -[Install] |
386 | | -WantedBy=multi-user.target |
| 380 | + aging_test_content_sh = textwrap.dedent( |
| 381 | + """\ |
| 382 | + #!/bin/bash |
| 383 | + /usr/bin/python3 /home/pi/Desktop/aging_test.py |
| 384 | + """ |
| 385 | + ) |
387 | 386 |
|
388 | | - """ |
| 387 | + aging_test_content_service = textwrap.dedent( |
| 388 | + """\ |
| 389 | + [Unit] |
| 390 | + Description=aging-test |
| 391 | +
|
| 392 | + [Service] |
| 393 | + Type=forking |
| 394 | + User=pi |
| 395 | + Restart=on-failure |
| 396 | + RestartSec=2 |
| 397 | + ExecStart=/home/pi/aging_test.sh |
| 398 | +
|
| 399 | + [Install] |
| 400 | + WantedBy=multi-user.target |
| 401 | + """ |
| 402 | + ) |
389 | 403 |
|
390 | 404 | os.system( |
391 | 405 | 'echo "' + aging_test_content_py + '" >> /home/pi/Desktop/aging_test.py' |
|
0 commit comments