LoginSignup
1
0

More than 5 years have passed since last update.

タイムラインボックスで作成したモーションをpythonボックスにする

Last updated at Posted at 2018-12-25

1. はじめに

Pepperのモーションをタイムラインボックスを利用して作成したとき、「同じモーションなんだけどゆっくりにしたい」だとか、「複数のタイムラインボックスの動きを簡単につなげたい」なんて言いながら、結局、別のタイムラインボックスを作ったりすることがあったりなかったり。
というわけで、タイムラインボックスで作成したモーションをpythonボックスにしてみようと思います。

2.手順

2.1 タイムラインボックスでモーションを作成する

とりあえず、適当なモーションを作成します。

2.2 タイムラインボックスからpythonのコードをエクスポートする

タイムラインボックスを開き、タイムライン上で右クリックして、「クリップボードにモーションをエクスポート」-「Python」-「ベジエ曲線」でモーションをエクスポートします。

2.3 コードを加工する

pythonボックスで利用するために、エディタ等でエクスポートしたコードを加工します。

エクスポートしたコードがこちらです。

export.py
# Choregraphe bezier export in Python.
from naoqi import ALProxy
names = list()
times = list()
keys = list()

names.append("HeadPitch")
times.append([0.966667, 1.96667, 2.96667, 3.96667])
keys.append([[-0.380427, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.205554, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.380428, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.200952, [3, -0.333333, 0], [3, 0, 0]]])

names.append("HeadYaw")
times.append([0.966667, 1.96667, 2.96667, 3.96667])
keys.append([[0.0230098, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.00153399, [3, -0.333333, 0], [3, 0.333333, 0]], [0.0230097, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.00460196, [3, -0.333333, 0], [3, 0, 0]]])

names.append("HipPitch")
times.append([0.966667, 1.96667, 2.96667, 3.96667])
keys.append([[-0.0306797, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.0322137, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.0306797, [3, -0.333333, -0.000511328], [3, 0.333333, 0.000511328]], [-0.0291457, [3, -0.333333, 0], [3, 0, 0]]])

names.append("HipRoll")
times.append([0.966667, 1.96667, 2.96667, 3.96667])
keys.append([[-0.00766993, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.00613594, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.00766992, [3, -0.333333, 6.76193e-09], [3, 0.333333, -6.76193e-09]], [-0.00766993, [3, -0.333333, 0], [3, 0, 0]]])

names.append("KneePitch")
times.append([0.966667, 1.96667, 2.96667, 3.96667])
keys.append([[-0.00460196, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.0184078, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.00460196, [3, -0.333333, -0.00153399], [3, 0.333333, 0.00153399]], [-0.00306797, [3, -0.333333, 0], [3, 0, 0]]])

names.append("LElbowRoll")
times.append([0.966667, 1.96667, 2.96667, 3.96667])
keys.append([[-1.43413, [3, -0.333333, 0], [3, 0.333333, 0]], [-1.31177, [3, -0.333333, 0], [3, 0.333333, 0]], [-1.43413, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.524621, [3, -0.333333, 0], [3, 0, 0]]])

names.append("LElbowYaw")
times.append([0.966667, 1.96667, 2.96667, 3.96667])
keys.append([[-0.983282, [3, -0.333333, 0], [3, 0.333333, 0]], [-1.93128, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.983282, [3, -0.333333, 0], [3, 0.333333, 0]], [-1.22105, [3, -0.333333, 0], [3, 0, 0]]])

names.append("LHand")
times.append([0.966667, 1.96667, 2.96667, 3.96667])
keys.append([[0.165202, [3, -0.333333, 0], [3, 0.333333, 0]], [0.855009, [3, -0.333333, 0], [3, 0.333333, 0]], [0.165202, [3, -0.333333, 0], [3, 0.333333, 0]], [0.603691, [3, -0.333333, 0], [3, 0, 0]]])

names.append("LShoulderPitch")
times.append([0.966667, 1.96667, 2.96667, 3.96667])
keys.append([[0.682622, [3, -0.333333, 0], [3, 0.333333, 0]], [0.447922, [3, -0.333333, 0], [3, 0.333333, 0]], [0.682621, [3, -0.333333, -0.186634], [3, 0.333333, 0.186634]], [1.56773, [3, -0.333333, 0], [3, 0, 0]]])

names.append("LShoulderRoll")
times.append([0.966667, 1.96667, 2.96667, 3.96667])
keys.append([[0.265379, [3, -0.333333, 0], [3, 0.333333, 0]], [0.406505, [3, -0.333333, 0], [3, 0.333333, 0]], [0.265379, [3, -0.333333, 0.0472977], [3, 0.333333, -0.0472977]], [0.122719, [3, -0.333333, 0], [3, 0, 0]]])

names.append("LWristYaw")
times.append([0.966667, 1.96667, 2.96667, 3.96667])
keys.append([[0.615176, [3, -0.333333, 0], [3, 0.333333, 0]], [0.863684, [3, -0.333333, 0], [3, 0.333333, 0]], [0.615176, [3, -0.333333, 0.141398], [3, 0.333333, -0.141398]], [0.0152981, [3, -0.333333, 0], [3, 0, 0]]])

names.append("RElbowRoll")
times.append([0.966667, 1.96667, 2.96667, 3.96667])
keys.append([[1.43413, [3, -0.333333, 0], [3, 0.333333, 0]], [1.31177, [3, -0.333333, 0], [3, 0.333333, 0]], [1.43413, [3, -0.333333, 0], [3, 0.333333, 0]], [0.524621, [3, -0.333333, 0], [3, 0, 0]]])

names.append("RElbowYaw")
times.append([0.966667, 1.96667, 2.96667, 3.96667])
keys.append([[0.983282, [3, -0.333333, 0], [3, 0.333333, 0]], [1.93128, [3, -0.333333, 0], [3, 0.333333, 0]], [0.983282, [3, -0.333333, 0], [3, 0.333333, 0]], [1.22718, [3, -0.333333, 0], [3, 0, 0]]])

names.append("RHand")
times.append([0.966667, 1.96667, 2.96667, 3.96667])
keys.append([[0.165202, [3, -0.333333, 0], [3, 0.333333, 0]], [0.855009, [3, -0.333333, 0], [3, 0.333333, 0]], [0.165202, [3, -0.333333, 0], [3, 0.333333, 0]], [0.605448, [3, -0.333333, 0], [3, 0, 0]]])

names.append("RShoulderPitch")
times.append([0.966667, 1.96667, 2.96667, 3.96667])
keys.append([[0.682622, [3, -0.333333, 0], [3, 0.333333, 0]], [0.447922, [3, -0.333333, 0], [3, 0.333333, 0]], [0.682621, [3, -0.333333, -0.185612], [3, 0.333333, 0.185612]], [1.56159, [3, -0.333333, 0], [3, 0, 0]]])

names.append("RShoulderRoll")
times.append([0.966667, 1.96667, 2.96667, 3.96667])
keys.append([[-0.265379, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.406505, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.265379, [3, -0.333333, -0.0472977], [3, 0.333333, 0.0472977]], [-0.122719, [3, -0.333333, 0], [3, 0, 0]]])

names.append("RWristYaw")
times.append([0.966667, 1.96667, 2.96667, 3.96667])
keys.append([[-0.615176, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.863684, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.615176, [3, -0.333333, -0.141128], [3, 0.333333, 0.141128]], [-0.016916, [3, -0.333333, 0], [3, 0, 0]]])

try:
  # uncomment the following line and modify the IP if you use this script outside Choregraphe.
  # motion = ALProxy("ALMotion", IP, 9559)
  motion = ALProxy("ALMotion")
  motion.angleInterpolationBezier(names, times, keys)
except BaseException, err:
  print err

上記コードを下記のように加工します。
(変数に"self"を付けただけです。)

mod_export.py
# Choregraphe bezier export in Python.
from naoqi import ALProxy
self.names = list()
self.times = list()
self.keys = list()

self.names.append("HeadPitch")
self.times.append([0.966667, 1.96667, 2.96667, 3.96667])
self.keys.append([[-0.380427, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.205554, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.380428, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.200952, [3, -0.333333, 0], [3, 0, 0]]])

self.names.append("HeadYaw")
self.times.append([0.966667, 1.96667, 2.96667, 3.96667])
self.keys.append([[0.0230098, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.00153399, [3, -0.333333, 0], [3, 0.333333, 0]], [0.0230097, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.00460196, [3, -0.333333, 0], [3, 0, 0]]])

self.names.append("HipPitch")
self.times.append([0.966667, 1.96667, 2.96667, 3.96667])
self.keys.append([[-0.0306797, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.0322137, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.0306797, [3, -0.333333, -0.000511328], [3, 0.333333, 0.000511328]], [-0.0291457, [3, -0.333333, 0], [3, 0, 0]]])

self.names.append("HipRoll")
self.times.append([0.966667, 1.96667, 2.96667, 3.96667])
self.keys.append([[-0.00766993, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.00613594, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.00766992, [3, -0.333333, 6.76193e-09], [3, 0.333333, -6.76193e-09]], [-0.00766993, [3, -0.333333, 0], [3, 0, 0]]])

self.names.append("KneePitch")
self.times.append([0.966667, 1.96667, 2.96667, 3.96667])
self.keys.append([[-0.00460196, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.0184078, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.00460196, [3, -0.333333, -0.00153399], [3, 0.333333, 0.00153399]], [-0.00306797, [3, -0.333333, 0], [3, 0, 0]]])

self.names.append("LElbowRoll")
self.times.append([0.966667, 1.96667, 2.96667, 3.96667])
self.keys.append([[-1.43413, [3, -0.333333, 0], [3, 0.333333, 0]], [-1.31177, [3, -0.333333, 0], [3, 0.333333, 0]], [-1.43413, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.524621, [3, -0.333333, 0], [3, 0, 0]]])

self.names.append("LElbowYaw")
self.times.append([0.966667, 1.96667, 2.96667, 3.96667])
self.keys.append([[-0.983282, [3, -0.333333, 0], [3, 0.333333, 0]], [-1.93128, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.983282, [3, -0.333333, 0], [3, 0.333333, 0]], [-1.22105, [3, -0.333333, 0], [3, 0, 0]]])

self.names.append("LHand")
self.times.append([0.966667, 1.96667, 2.96667, 3.96667])
self.keys.append([[0.165202, [3, -0.333333, 0], [3, 0.333333, 0]], [0.855009, [3, -0.333333, 0], [3, 0.333333, 0]], [0.165202, [3, -0.333333, 0], [3, 0.333333, 0]], [0.603691, [3, -0.333333, 0], [3, 0, 0]]])

self.names.append("LShoulderPitch")
self.times.append([0.966667, 1.96667, 2.96667, 3.96667])
self.keys.append([[0.682622, [3, -0.333333, 0], [3, 0.333333, 0]], [0.447922, [3, -0.333333, 0], [3, 0.333333, 0]], [0.682621, [3, -0.333333, -0.186634], [3, 0.333333, 0.186634]], [1.56773, [3, -0.333333, 0], [3, 0, 0]]])

self.names.append("LShoulderRoll")
self.times.append([0.966667, 1.96667, 2.96667, 3.96667])
self.keys.append([[0.265379, [3, -0.333333, 0], [3, 0.333333, 0]], [0.406505, [3, -0.333333, 0], [3, 0.333333, 0]], [0.265379, [3, -0.333333, 0.0472977], [3, 0.333333, -0.0472977]], [0.122719, [3, -0.333333, 0], [3, 0, 0]]])

self.names.append("LWristYaw")
self.times.append([0.966667, 1.96667, 2.96667, 3.96667])
self.keys.append([[0.615176, [3, -0.333333, 0], [3, 0.333333, 0]], [0.863684, [3, -0.333333, 0], [3, 0.333333, 0]], [0.615176, [3, -0.333333, 0.141398], [3, 0.333333, -0.141398]], [0.0152981, [3, -0.333333, 0], [3, 0, 0]]])

self.names.append("RElbowRoll")
self.times.append([0.966667, 1.96667, 2.96667, 3.96667])
self.keys.append([[1.43413, [3, -0.333333, 0], [3, 0.333333, 0]], [1.31177, [3, -0.333333, 0], [3, 0.333333, 0]], [1.43413, [3, -0.333333, 0], [3, 0.333333, 0]], [0.524621, [3, -0.333333, 0], [3, 0, 0]]])

self.names.append("RElbowYaw")
self.times.append([0.966667, 1.96667, 2.96667, 3.96667])
self.keys.append([[0.983282, [3, -0.333333, 0], [3, 0.333333, 0]], [1.93128, [3, -0.333333, 0], [3, 0.333333, 0]], [0.983282, [3, -0.333333, 0], [3, 0.333333, 0]], [1.22718, [3, -0.333333, 0], [3, 0, 0]]])

self.names.append("RHand")
self.times.append([0.966667, 1.96667, 2.96667, 3.96667])
self.keys.append([[0.165202, [3, -0.333333, 0], [3, 0.333333, 0]], [0.855009, [3, -0.333333, 0], [3, 0.333333, 0]], [0.165202, [3, -0.333333, 0], [3, 0.333333, 0]], [0.605448, [3, -0.333333, 0], [3, 0, 0]]])

self.names.append("RShoulderPitch")
self.times.append([0.966667, 1.96667, 2.96667, 3.96667])
self.keys.append([[0.682622, [3, -0.333333, 0], [3, 0.333333, 0]], [0.447922, [3, -0.333333, 0], [3, 0.333333, 0]], [0.682621, [3, -0.333333, -0.185612], [3, 0.333333, 0.185612]], [1.56159, [3, -0.333333, 0], [3, 0, 0]]])

self.names.append("RShoulderRoll")
self.times.append([0.966667, 1.96667, 2.96667, 3.96667])
self.keys.append([[-0.265379, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.406505, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.265379, [3, -0.333333, -0.0472977], [3, 0.333333, 0.0472977]], [-0.122719, [3, -0.333333, 0], [3, 0, 0]]])

self.names.append("RWristYaw")
self.times.append([0.966667, 1.96667, 2.96667, 3.96667])
self.keys.append([[-0.615176, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.863684, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.615176, [3, -0.333333, -0.141128], [3, 0.333333, 0.141128]], [-0.016916, [3, -0.333333, 0], [3, 0, 0]]])

try:
  # uncomment the following line and modify the IP if you use this script outside Choregraphe.
  # motion = ALProxy("ALMotion", IP, 9559)
  self.motion = ALProxy("ALMotion")
  self.motion.angleInterpolationBezier(self.names, self.times, self.keys)
except BaseException, err:
  print err

2.4 加工後のコードをpythonボックスに反映する

各関節のモーションデータはonLoad()に、onInput_Start()にモーション実行部分を反映します。

motion_test.py
from naoqi import ALProxy

class MyClass(GeneratedClass):
    def __init__(self):
        GeneratedClass.__init__(self)

    def onLoad(self):
        #各関節のモーションデータ
        self.names = list()
        self.times = list()
        self.keys = list()

        self.names.append("HeadPitch")
        self.times.append([0.966667, 1.96667, 2.96667, 3.96667])
        self.keys.append([[-0.380427, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.205554, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.380428, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.200952, [3, -0.333333, 0], [3, 0, 0]]])

        self.names.append("HeadYaw")
        self.times.append([0.966667, 1.96667, 2.96667, 3.96667])
        self.keys.append([[0.0230098, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.00153399, [3, -0.333333, 0], [3, 0.333333, 0]], [0.0230097, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.00460196, [3, -0.333333, 0], [3, 0, 0]]])

        self.names.append("HipPitch")
        self.times.append([0.966667, 1.96667, 2.96667, 3.96667])
        self.keys.append([[-0.0306797, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.0322137, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.0306797, [3, -0.333333, -0.000511328], [3, 0.333333, 0.000511328]], [-0.0291457, [3, -0.333333, 0], [3, 0, 0]]])

        self.names.append("HipRoll")
        self.times.append([0.966667, 1.96667, 2.96667, 3.96667])
        self.keys.append([[-0.00766993, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.00613594, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.00766992, [3, -0.333333, 6.76193e-09], [3, 0.333333, -6.76193e-09]], [-0.00766993, [3, -0.333333, 0], [3, 0, 0]]])

        self.names.append("KneePitch")
        self.times.append([0.966667, 1.96667, 2.96667, 3.96667])
        self.keys.append([[-0.00460196, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.0184078, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.00460196, [3, -0.333333, -0.00153399], [3, 0.333333, 0.00153399]], [-0.00306797, [3, -0.333333, 0], [3, 0, 0]]])

        self.names.append("LElbowRoll")
        self.times.append([0.966667, 1.96667, 2.96667, 3.96667])
        self.keys.append([[-1.43413, [3, -0.333333, 0], [3, 0.333333, 0]], [-1.31177, [3, -0.333333, 0], [3, 0.333333, 0]], [-1.43413, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.524621, [3, -0.333333, 0], [3, 0, 0]]])

        self.names.append("LElbowYaw")
        self.times.append([0.966667, 1.96667, 2.96667, 3.96667])
        self.keys.append([[-0.983282, [3, -0.333333, 0], [3, 0.333333, 0]], [-1.93128, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.983282, [3, -0.333333, 0], [3, 0.333333, 0]], [-1.22105, [3, -0.333333, 0], [3, 0, 0]]])

        self.names.append("LHand")
        self.times.append([0.966667, 1.96667, 2.96667, 3.96667])
        self.keys.append([[0.165202, [3, -0.333333, 0], [3, 0.333333, 0]], [0.855009, [3, -0.333333, 0], [3, 0.333333, 0]], [0.165202, [3, -0.333333, 0], [3, 0.333333, 0]], [0.603691, [3, -0.333333, 0], [3, 0, 0]]])

        self.names.append("LShoulderPitch")
        self.times.append([0.966667, 1.96667, 2.96667, 3.96667])
        self.keys.append([[0.682622, [3, -0.333333, 0], [3, 0.333333, 0]], [0.447922, [3, -0.333333, 0], [3, 0.333333, 0]], [0.682621, [3, -0.333333, -0.186634], [3, 0.333333, 0.186634]], [1.56773, [3, -0.333333, 0], [3, 0, 0]]])

        self.names.append("LShoulderRoll")
        self.times.append([0.966667, 1.96667, 2.96667, 3.96667])
        self.keys.append([[0.265379, [3, -0.333333, 0], [3, 0.333333, 0]], [0.406505, [3, -0.333333, 0], [3, 0.333333, 0]], [0.265379, [3, -0.333333, 0.0472977], [3, 0.333333, -0.0472977]], [0.122719, [3, -0.333333, 0], [3, 0, 0]]])

        self.names.append("LWristYaw")
        self.times.append([0.966667, 1.96667, 2.96667, 3.96667])
        self.keys.append([[0.615176, [3, -0.333333, 0], [3, 0.333333, 0]], [0.863684, [3, -0.333333, 0], [3, 0.333333, 0]], [0.615176, [3, -0.333333, 0.141398], [3, 0.333333, -0.141398]], [0.0152981, [3, -0.333333, 0], [3, 0, 0]]])

        self.names.append("RElbowRoll")
        self.times.append([0.966667, 1.96667, 2.96667, 3.96667])
        self.keys.append([[1.43413, [3, -0.333333, 0], [3, 0.333333, 0]], [1.31177, [3, -0.333333, 0], [3, 0.333333, 0]], [1.43413, [3, -0.333333, 0], [3, 0.333333, 0]], [0.524621, [3, -0.333333, 0], [3, 0, 0]]])

        self.names.append("RElbowYaw")
        self.times.append([0.966667, 1.96667, 2.96667, 3.96667])
        self.keys.append([[0.983282, [3, -0.333333, 0], [3, 0.333333, 0]], [1.93128, [3, -0.333333, 0], [3, 0.333333, 0]], [0.983282, [3, -0.333333, 0], [3, 0.333333, 0]], [1.22718, [3, -0.333333, 0], [3, 0, 0]]])

        self.names.append("RHand")
        self.times.append([0.966667, 1.96667, 2.96667, 3.96667])
        self.keys.append([[0.165202, [3, -0.333333, 0], [3, 0.333333, 0]], [0.855009, [3, -0.333333, 0], [3, 0.333333, 0]], [0.165202, [3, -0.333333, 0], [3, 0.333333, 0]], [0.605448, [3, -0.333333, 0], [3, 0, 0]]])

        self.names.append("RShoulderPitch")
        self.times.append([0.966667, 1.96667, 2.96667, 3.96667])
        self.keys.append([[0.682622, [3, -0.333333, 0], [3, 0.333333, 0]], [0.447922, [3, -0.333333, 0], [3, 0.333333, 0]], [0.682621, [3, -0.333333, -0.185612], [3, 0.333333, 0.185612]], [1.56159, [3, -0.333333, 0], [3, 0, 0]]])

        self.names.append("RShoulderRoll")
        self.times.append([0.966667, 1.96667, 2.96667, 3.96667])
        self.keys.append([[-0.265379, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.406505, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.265379, [3, -0.333333, -0.0472977], [3, 0.333333, 0.0472977]], [-0.122719, [3, -0.333333, 0], [3, 0, 0]]])

        self.names.append("RWristYaw")
        self.times.append([0.966667, 1.96667, 2.96667, 3.96667])
        self.keys.append([[-0.615176, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.863684, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.615176, [3, -0.333333, -0.141128], [3, 0.333333, 0.141128]], [-0.016916, [3, -0.333333, 0], [3, 0, 0]]])
        #put initialization code here
        pass

    def onUnload(self):
        #put clean-up code here
        pass

    def onInput_onStart(self):
        #モーション実行部分
        try:
            self.motion = ALProxy("ALMotion")
            self.motion.angleInterpolationBezier(self.names, self.times, self.keys)
        except BaseException, err:
            print err

        self.onStopped() #activate the output of the box
        pass

    def onInput_onStop(self):
        self.onUnload() #it is recommended to reuse the clean-up as the box is stopped
        self.onStopped() #activate the output of the box

motion_test.pyのコードをpythonボックスにコピー&ペーストしてchoregrapheで実行するとPepperが両手を挙げる動作をします。

3.モーションの実行時間を変えてみる

motion_test.pyのモーションは2秒で作成しているのですが、これをpythonボックスに引数pで数字を指定して「2*p秒」で実行するように変えてみます。
onLoad()で各関節ごとにtimesへタイムラインの時間を設定しているのですが、この部分をonInput_onStart()でまとめて変更できるようにします。

motion_test2.py
from naoqi import ALProxy

class MyClass(GeneratedClass):
    def __init__(self):
        GeneratedClass.__init__(self)

    def onLoad(self):
        self.motion = ALProxy("ALMotion")
        self.names = list()
        self.times = list()
        self.keys = list()

        self.names.append("HeadPitch")
        self.keys.append([[-0.380427, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.205554, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.380428, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.200952, [3, -0.333333, 0], [3, 0, 0]]])

        self.names.append("HeadYaw")
        self.keys.append([[0.0230098, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.00153399, [3, -0.333333, 0], [3, 0.333333, 0]], [0.0230097, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.00460196, [3, -0.333333, 0], [3, 0, 0]]])

        self.names.append("HipPitch")
        self.keys.append([[-0.0306797, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.0322137, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.0306797, [3, -0.333333, -0.000511328], [3, 0.333333, 0.000511328]], [-0.0291457, [3, -0.333333, 0], [3, 0, 0]]])

        self.names.append("HipRoll")
        self.keys.append([[-0.00766993, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.00613594, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.00766992, [3, -0.333333, 6.76193e-09], [3, 0.333333, -6.76193e-09]], [-0.00766993, [3, -0.333333, 0], [3, 0, 0]]])

        self.names.append("KneePitch")
        self.keys.append([[-0.00460196, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.0184078, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.00460196, [3, -0.333333, -0.00153399], [3, 0.333333, 0.00153399]], [-0.00306797, [3, -0.333333, 0], [3, 0, 0]]])

        self.names.append("LElbowRoll")
        self.keys.append([[-1.43413, [3, -0.333333, 0], [3, 0.333333, 0]], [-1.31177, [3, -0.333333, 0], [3, 0.333333, 0]], [-1.43413, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.524621, [3, -0.333333, 0], [3, 0, 0]]])

        self.names.append("LElbowYaw")
        self.keys.append([[-0.983282, [3, -0.333333, 0], [3, 0.333333, 0]], [-1.93128, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.983282, [3, -0.333333, 0], [3, 0.333333, 0]], [-1.22105, [3, -0.333333, 0], [3, 0, 0]]])

        self.names.append("LHand")
        self.keys.append([[0.165202, [3, -0.333333, 0], [3, 0.333333, 0]], [0.855009, [3, -0.333333, 0], [3, 0.333333, 0]], [0.165202, [3, -0.333333, 0], [3, 0.333333, 0]], [0.603691, [3, -0.333333, 0], [3, 0, 0]]])

        self.names.append("LShoulderPitch")
        self.keys.append([[0.682622, [3, -0.333333, 0], [3, 0.333333, 0]], [0.447922, [3, -0.333333, 0], [3, 0.333333, 0]], [0.682621, [3, -0.333333, -0.186634], [3, 0.333333, 0.186634]], [1.56773, [3, -0.333333, 0], [3, 0, 0]]])

        self.names.append("LShoulderRoll")
        self.keys.append([[0.265379, [3, -0.333333, 0], [3, 0.333333, 0]], [0.406505, [3, -0.333333, 0], [3, 0.333333, 0]], [0.265379, [3, -0.333333, 0.0472977], [3, 0.333333, -0.0472977]], [0.122719, [3, -0.333333, 0], [3, 0, 0]]])

        self.names.append("LWristYaw")
        self.keys.append([[0.615176, [3, -0.333333, 0], [3, 0.333333, 0]], [0.863684, [3, -0.333333, 0], [3, 0.333333, 0]], [0.615176, [3, -0.333333, 0.141398], [3, 0.333333, -0.141398]], [0.0152981, [3, -0.333333, 0], [3, 0, 0]]])

        self.names.append("RElbowRoll")
        self.keys.append([[1.43413, [3, -0.333333, 0], [3, 0.333333, 0]], [1.31177, [3, -0.333333, 0], [3, 0.333333, 0]], [1.43413, [3, -0.333333, 0], [3, 0.333333, 0]], [0.524621, [3, -0.333333, 0], [3, 0, 0]]])

        self.names.append("RElbowYaw")
        self.keys.append([[0.983282, [3, -0.333333, 0], [3, 0.333333, 0]], [1.93128, [3, -0.333333, 0], [3, 0.333333, 0]], [0.983282, [3, -0.333333, 0], [3, 0.333333, 0]], [1.22718, [3, -0.333333, 0], [3, 0, 0]]])

        self.names.append("RHand")
        self.keys.append([[0.165202, [3, -0.333333, 0], [3, 0.333333, 0]], [0.855009, [3, -0.333333, 0], [3, 0.333333, 0]], [0.165202, [3, -0.333333, 0], [3, 0.333333, 0]], [0.605448, [3, -0.333333, 0], [3, 0, 0]]])

        self.names.append("RShoulderPitch")
        self.keys.append([[0.682622, [3, -0.333333, 0], [3, 0.333333, 0]], [0.447922, [3, -0.333333, 0], [3, 0.333333, 0]], [0.682621, [3, -0.333333, -0.185612], [3, 0.333333, 0.185612]], [1.56159, [3, -0.333333, 0], [3, 0, 0]]])

        self.names.append("RShoulderRoll")
        self.keys.append([[-0.265379, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.406505, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.265379, [3, -0.333333, -0.0472977], [3, 0.333333, 0.0472977]], [-0.122719, [3, -0.333333, 0], [3, 0, 0]]])

        self.names.append("RWristYaw")
        self.keys.append([[-0.615176, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.863684, [3, -0.333333, 0], [3, 0.333333, 0]], [-0.615176, [3, -0.333333, -0.141128], [3, 0.333333, 0.141128]], [-0.016916, [3, -0.333333, 0], [3, 0, 0]]])
        #put initialization code here
        pass

    def onUnload(self):
        #put clean-up code here
        pass

    #引数pを加える。
    #choregrapheのほうでもpythonボックスのボックス編集からonStartに変数(数字)を追加してください。
    def onInput_onStart(self,p):
        self.basetime = [0.966667, 1.96667, 2.96667, 3.96667]
        self.basetimelist = list()

        #引数を使って時間を変える
        for x in self.basetime:
            self.basetimelist.append(float(x * p))

        #各関節数分のデータを作成
        self.times = list()
        for i in range(len(self.names)):
            self.times.append(self.basetimelist)

        try:
            self.motion.angleInterpolationBezier(self.names, self.times, self.keys)
        except BaseException, err:
            print err

        self.onStopped() #activate the output of the box
        pass

    def onInput_onStop(self):
        self.onUnload() #it is recommended to reuse the clean-up as the box is stopped
        self.onStopped() #activate the output of the box

pythonボックスの前にNumberEditボックスを置いたりして、引数の値を変えて動かしてみてください。(値を小さくすると動きが激しくなるのでご注意を)

4.まとめ

工夫次第でいろいろとできそうだなと思います。

ALMotion APIについて

 → Naoqi2.5 ドキュメント ALMotion API

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0