今回はmycobot-piを頂いたこともあり、さっそく遊んでみることにしました。
実際はROSをやりたいんですが、まだ不安なうえによくわからないのでとりあえずpythonで確認します。
確認したpython program
確認したサンプルプログラムは2つです。
- ロボット先端にあるAtomのLチカ
- ロボットダンス
参考にしたリンクを下記に示す。
ロボット先端にあるAtomのLチカ
from pymycobot.mycobot import MyCobot
from pymycobot import PI_PORT, PI_BAUD
mc = MyCobot(PI_PORT, PI_BAUD)
mc.set_color(255, 0, 0)
ロボットダンス
from pymycobot.mycobot import MyCobot
from pymycobot import PI_PORT, PI_BAUD # When using the Raspberry Pi version of myCobot, you can refer to these two variables for MyCobot initialization
import time
if __name__ == '__main__':
# Initialize a MyCobot object
mc = MyCobot(PI_PORT, PI_BAUD)
# Set the start time
start = time.time()
# Let the robot arm move to the specified position
mc.send_angles([-1.49, 115, -153.45, 30, -33.42, 137.9], 80)
# Check whether it move to the specified positon
while not mc.is_in_position([-1.49, 115, -153.45, 30, -33.42, 137.9], 0):
# Restore the movement of the robot arm
mc.resume()
# Let the robot arm move 0.5s
time.sleep(0.5)
# Pause the movement of the robot arm
mc.pause()
# Check if the movement timed out
if time.time() - start > 3:
break
# Set start time
start = time.time()
# Let the movement last 30 seconds
while time.time() - start < 30:
# Let the robot arm reach this position quickly
mc.send_angles([-1.49, 115, -153.45, 30, -33.42, 137.9], 80)
# Set the color of the light to[0,0,50]
mc.set_color(0, 0, 50)
time.sleep(0.7)
# Let the robot arm reach this position quickly
mc.send_angles([-1.49, 55, -153.45, 80, 33.42, 137.9], 80)
# Set the color of the light to[0,50,0]
mc.set_color(0, 50, 0)
time.sleep(0.7)
# mc.release_all_servos()
この二つのプログラムを利用して確認しました。上記プログラムはリンクのものをそのまま貼っていますが、多少プログラムの数値を変更して実際の動作は確認しています。
それぞれtwitterに示しています。
mycobot-piの先端にあるLEDの点灯できた。言語が中国語になってるから直さないと pic.twitter.com/9qMoWVfisl
— 充実したデスマ (@kwaz6) 2021年6月18日
とりあえず踊れるようになった pic.twitter.com/qjFUpqUdUY
— 充実したデスマ (@kwaz6) 2021年6月18日
まとめ
今回はpythonのサンプルプログラムを利用してmycobot-piを動かしてみました。
今後はROSであったり、pythonの制御プログラムの理解等、さらに遊んでいきたいと思います。