motion · Motors and motions

Controls the servo motors and creates motions.

Class: Motion

class openpibo.motion.Motion[source]

Bases: object

Functions: set_motor() set_motors() set_speed() set_speeds() set_acceleration() set_accelerations() get_motion() set_motion_raw() set_motion() set_mymotion() stop()

Controls piBo’s movement.

example:

from openpibo.motion import Motion

motion = Motion()
# 아래의 모든 예제 이전에 위 코드를 먼저 사용합니다.
set_motor(n, pos)[source]

Moves one motor to the given position.

example:

motion.set_motor(2, 30)
Parameters:
  • n (int) – Motor number A number from 0 to 9. For the position of each number, see 모터 번호당 위치 (position per motor number) above.

  • pos (int) – Motor angle A number from -80 to 80. For the exact range, see 모터 제한 각도 (motor angle limits) above.

set_motors(positions, movetime=None)[source]

Moves all motors to the given positions.

The shorter movetime is, the faster the motion. If movetime is None, the speed stays at the previous setting.

example:

motion.set_motors([0, 0, -80, 0, 0, 0, 0, 0, 80, 0])
Parameters:
  • positions (list) – Array of angles for motors 0-9

  • movetime (int) – Motor move time (ms) In units of 50ms; the time the motors take to reach the given positions (not precise, due to overhead with the motor controller)

set_speed(n, speed)[source]

Sets the speed of one motor.

example:

motion.set_speed(3, 255)
Parameters:
  • n (int) – Motor number

  • speed (int) – Motor speed A value from 0 to 255. The larger the number, the faster the speed.

set_speeds(speeds)[source]

Sets the speed of all motors.

example:

motion.set_speeds([20, 50, 40, 20, 20, 10, 20, 50, 40, 20])
Parameters:

speeds (list) – Array of speeds for motors 0-9 Each speed in the array is an integer from 0 to 255.

set_acceleration(n, accel)[source]

Sets the acceleration of one motor.

When acceleration is set, the speed starts at 0 and gradually increases to the set speed. It then gradually slows down and reaches 0 at the end point.

example:

motion.set_acceleration(3, 5)
Parameters:
  • n (int) – Motor number

  • accel (int) – Motor acceleration A value from 0 to 255. The larger the number, the larger the acceleration.

set_accelerations(accels)[source]

Sets the acceleration of all motors.

example:

motion.set_accelerations([5, 5, 5, 5, 10, 10, 5, 5, 5, 5])
Parameters:

accels (list) – Array of accelerations for motors 0-9 Each acceleration in the array is an integer from 0 to 255.

get_motion(name=None, path=None)[source]

Looks up the motion profile.

If the name parameter is None, returns the names of all motions stored in the motion profile; if it is not None, returns the data for the motion with that name.

example:

motion.get_motion('forward1')
Parameters:
  • name (str) – Motion name The name of a motion stored in the profile.

  • path (str) – Motion file path to use Path to the motion file. If not given, the default motion file is used.

Returns:

  • When name == None:

    # motion.get_motion()
    # motion.get_motion(path='/home/pi/mymotion.json')
    
    ['stop', 'stop_body', 'sleep', 'lookup', 'left', 'left_half',
    'right', 'right_half', 'forward1', 'forward2', ...]
    
  • When name != None:

    # motion.get_motion('stop')
    # motion.get_motion('stop', path='/home/pi/mymotion.json')
    
    {
      'comment': 'stop',
      'init_def': 1,
      'init': [0, 0, -70, -25, 0, 0, 0, 0, 70, 25]
    }
    

set_motion_raw(exe, cycle=1)[source]

Runs a motion from the motion profile.

example:

motion.set_motion_raw(
  {'init_def': 1, 'init': [0, 0, -70, -25, 0, 0, 0, 0, 70, 25]},
  1
)
Parameters:
  • exe (str) – Data recording the movement of each motor for a given motion. It uses the following format:: { “init_def”: 1 “init”:[0,0,-70,-25,0,0,0,0,70,25], “pos”:[ {“d”:[999,999,999,999, 30,999,999,999,999,999],”seq”:500}, {“d”:[999,999,999,999,-30,999,999,999,999,999],”seq”:2000}, … ] } * init_def indicates whether there is an initial pose. * init is the preparatory pose before the motion starts. * pos is a list of consecutive poses. It means the pose d is completed at time seq (ms).

  • cycle (int) – Sets how many times to repeat the motion.

set_motion(name, cycle=1, path=None)[source]

Runs a motion from the motion profile stored in the path file. If path is not set, the default motion profile is used.

example:

motion.set_motion('dance1')
#motion.set_motion('dance1', path='/home/pi/mymotion.json')
Parameters:
  • name (str) – Motion name The name of a motion stored in the motion profile.

  • cycle (int) – Number of repetitions

  • path (str) – Path to the motion file. If not given, the default motion file is used.

set_mymotion(name, cycle=1)[source]

Runs a motion from the motion profile stored in the /home/pi/mymotion.json file.

example:

motion.set_mymotion('test')
Parameters:
  • name (str) – Motion name The name of a motion stored in the motion profile.

  • cycle (int) – Number of repetitions

stop()[source]

Stops the motion in progress.

example:

# 동작을 수행 중일 때,
motion.stop()