注釈

こんにちは!SunFounder Raspberry Pi & Arduino & ESP32 Enthusiasts Communityへようこそ!Raspberry Pi、Arduino、ESP32に関心のある仲間とともに、さらに深く学びましょう。

参加する理由

  • 専門家のサポート: 購入後の問題や技術的な課題を、コミュニティやチームのサポートで解決できます。

  • 学びと共有: ヒントやチュートリアルを交換して、スキルを向上させましょう。

  • 特別なプレビュー: 新製品の発表や先行公開に早期アクセスできます。

  • 特別割引: 新製品に対して限定割引を楽しめます。

  • 祝祭プロモーションとプレゼント: プレゼントや祝祭プロモーションに参加できます。

👉 私たちと一緒に探求し、創造する準備はできましたか?[ここ]をクリックして、今すぐ参加しましょう!

感情的なロボット

この例では、PiCrawlerのいくつかの興味深いカスタムアクションを紹介します。

コードの実行

cd ~/picrawler/examples
sudo python3 emotional_robot.py

コード

注釈

以下のコードは 変更/リセット/コピー/実行/停止 が可能です。ただし、最初にソースコードのパス(例: picrawler\examples )に移動する必要があります。コードを変更した後は、直接実行してその効果を確認できます。

from picrawler import Picrawler
from time import sleep

crawler = Picrawler()

def handwork(speed):

    basic_step = []
    basic_step = crawler.step_list.get("sit")
    left_hand  = crawler.mix_step(basic_step,0,[0,50,80])
    right_hand  = crawler.mix_step(basic_step,1,[0,50,80])
    two_hand = crawler.mix_step(left_hand,1,[0,50,80])

    crawler.do_step('sit',speed)
    sleep(0.6)
    crawler.do_step(left_hand,speed)
    sleep(0.6)
    crawler.do_step(two_hand,speed)
    sleep(0.6)
    crawler.do_step(right_hand,speed)
    sleep(0.6)
    crawler.do_step('sit',speed)
    sleep(0.6)

def twist(speed):
    new_step=[[50, 50, -80], [50, 50, -80],[50, 50, -80], [50, 50, -80]]
    for i in range(4):
        for inc in range(30,60,5):
            rise = [50,50,(-80+inc*0.5)]
            drop = [50,50,(-80-inc)]

            new_step[i]=rise
            new_step[(i+2)%4] = drop
            new_step[(i+1)%4] = rise
            new_step[(i-1)%4] = drop
            crawler.do_step(new_step,speed)

## "[[右前足], [左前足], [左後足], [右後足]]")

def pushup(speed):
    up=[[80, 0, -100], [80, 0, -100],[0, 120, -60], [0, 120, -60]]
    down=[[80, 0, -30], [80, 0, -30],[0, 120, -60], [0, 120, -60]]
    crawler.do_step(up,speed)
    sleep(0.6)
    crawler.do_step(down,speed)
    sleep(0.6)

def swimming(speed):
    for i in range(100):
        crawler.do_step([[100-i,i,0],[100-i,i,0],[0,120,-60+i/5],[0,100,-40-i/5]],speed)

# main
def main():
    speed = 100

    swimming(speed)
    pushup(speed)
    handwork(speed)
    twist(speed)

    sleep(0.05)

if __name__ == "__main__":
    main()