Help us understand the problem. What is going on with this article?

Pepperハッカソン 音の方向にPepperが動いてくれる

More than 5 years have passed since last update.

SoundLoation.png

今日のハッカソンの、音の方向にPepperが動いてくれるBoxを忘れないうちにメモ。各パラメータは以下。

soundLocparam.png
moveTowardParampng.png
「Wait3」boxは、60秒。「Wait4」boxは3秒で設定しました。

「Move Toward」boxにinputを一つ追加。(inputの付近で右クリックで、AddInputすれば画面でます。)
inputxy.png
そして、最後に「Move Toward」boxをダブルクリックして、

頭に

import math

を追加。そして

def onInput_inputxy(self, p):
    self.lock.acquire()
    try:
        self.test = p[0]
        self.shouldRun = True
        self.updateMovement()

    finally:
        self.lock.release()

を追加して

def updateMovement(self):の
        #x = self.getParameter("X")
        #y = self.getParameter("Y")
        x = math.cos(self.test)
        y = math.sin(self.test)

の書き換えをすれば完了です。

全体のソースは以下に。ただ時間内に動かす目的だけに作ったのでご了承ください。

import time
import math
import threading

class MyClass(GeneratedClass):
def init(self):
GeneratedClass.init(self, False)

def onLoad(self):
    self.motion = ALProxy("ALMotion")
    self.shouldRun = False
    self.x = 0
    self.y = 0
    self.theta = 0
    self.timer = None
    self.lock = threading.RLock()

def onUnload(self):
    self.lock.acquire()
    try:
        self.shouldRun = False
        if self.timer:
            self.timer.cancel()
            self.timer = None

        self.x = 0
        self.y = 0
        self.theta = 0
        self.motion.moveToward(0, 0, 0)
        self.motion.waitUntilMoveIsFinished()
    finally:
        self.lock.release()

def onInput_onStop(self):
    self.lock.acquire()
    try:
        self.onUnload()
        self.onStopped()
    finally:
        self.lock.release()

def onInput_onStart(self):
    self.lock.acquire()
    try:
        self.shouldRun = True
        self.updateMovement()
    finally:
        self.lock.release()

def onInput_inputxy(self, p):
    self.lock.acquire()
    try:
        self.test = p[0]
        self.shouldRun = True
        self.updateMovement()

    finally:
        self.lock.release()

def updateMovement(self):
    self.lock.acquire()
    try:
        if self.timer:
            self.timer.cancel()
            self.timer = None
        enableArms = self.getParameter("Arms movement enabled")
        self.motion.setMoveArmsEnabled(enableArms, enableArms)
        #x = self.getParameter("X")
        #y = self.getParameter("Y")
        x = math.cos(self.test)
        y = math.sin(self.test)
        theta = self.getParameter("Theta")
        period = self.getParameter("Period of direction update (s)")
        epsilon = 0.0001
        dx = math.fabs(x - self.x)
        dy = math.fabs(y - self.y)
        dt = math.fabs((theta - self.theta))
        if(dx > epsilon or dy > epsilon or dt > epsilon):
            self.x=x
            self.y=y
            self.theta=theta
            self.motion.moveToward(self.x, self.y, self.theta)

        if self.shouldRun:
            self.timer = threading.Timer(period, self.updateMovement)
            self.timer.start()
    finally:
        self.lock.release()

以上

inamasu175
公共系webエンジニアです。Javaしか触った事ないですが、10年振りぐらいにプログラムに触れて楽しんでます。
https://www.facebook.com/inamasu.hiroshi
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした