Pepper Hackason 소리의 방향으로 Pepper가 움직입니다.
3793 단어 Pepper

오늘의 해커슨의, 소리의 방향으로 Pepper가 움직여 주는 Box를 잊지 않는 사이에 메모. 각 파라미터는 이하.


Wait3 box는 60초. 'Wait4' 박스가 3초 안에 설정되었습니다.
Move Toward box에 input을 하나 추가. (input 부근에서 오른쪽 클릭으로 AddInput하면 화면입니다.)

그리고 마지막으로 "Move Toward"박스를 더블 클릭하여,
머리에
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()
이상
Reference
이 문제에 관하여(Pepper Hackason 소리의 방향으로 Pepper가 움직입니다.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/inamasu175/items/1b80ee629ef78b298ff9텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)