Edit on GitHub

Table of Contents

Abstract

pycm module

System Functions

Submodule of pycm(CM-550)

Abstract

This is MicroPython APIs documentation of the ROBOTIS CM-550 controller.

pycm module

Definition

pycm is a module for controlling CM-550 hardware with MicoroPython, and it contains submodules for each function such as pycm.buzzer and pycm.led.

How to use

Example 1

All examples in the e-Manual of pycm use this method similarly.

pycm can be omitted when using its submodules.

# import pycm and all its submodules
from pycm import *

# Turn on Green LED
led.set(const.GREEN)
delay(1000)

Example 2

pycm should be specified when using submodules

# import pycm module only
import pycm

# Turn on Green LED (pycm must be specified before led module)
pycm.led.set(const.GREEN)
delay(1000)

System Functions

delay()

Description

wait for specified length of time (unit : 0.001 sec)

Syntax

Parameters

Returns

Example

# wait for 0.8 sec
delay(800)

console()

Description

Configure communication port for print() function

Syntax

Parameters

Returns

Example

# print through BLE
console(const.BLE)

# print through USB
console(const.USB)

# print through UART(4 pin port)
console(const.UART)

print()

Description

print number and/or text

Syntax

Parameters

Returns

Example

# Change line after print
print('Print with newline')

# Do not change line after print
print('without new line ', end = '')

# print the value of a variable
n = 791
print(n)

# print several values with SPACE between them
print('string', 1024, n)

# print several values without SPACE between them
print('string', 1024, n, sep='')

Submodule of pycm(CM-550)

Unless otherwise specified, the data type of function parameter is integer.

buzzer

buzzer.melody()

Description

play the melody of specified index number

Syntax

Parameters

Returns

Example

buzzer.wait()

Description

wait until melody or scale playing is finished

Syntax

Parameters

Returns

Example

from pycm import *


# play No. 1 melody
buzzer.melody(1)

# wait while the melody is playing
buzzer.wait()

buzzer.note()

Description

play the scale of specified index

Syntax

Parameters

Returns

Example

from pycm import *


# play No.20 scale for 0.8 sec
buzzer.note(20, 800)

# wait while the scale is playing
buzzer.wait()

led

led.set()

Description

turn on specified LEDs or turn off all LEDs

Syntax

Parameters

Returns

Example

from pycm import *

# Turn on Red and Green LED
led.set(const.RED | const.GREEN)
delay(800)

# Turn off all LEDs
led.set()

led.toggle()

Description

toggle the specified LEDs (ON -> OFF, OFF -> ON)

Syntax

Parameters

Returns

Example

from pycm import *

# Toggle Green and Blue LED
led.toggle(const.GREEN | const.BLUE)
delay(800)

# Toggle Green and Blue LED
led.toggle(const.GREEN | const.BLUE)
delay(800)

Constant values for led

button

button.pressed()

Description

If START button is pressed or not

Syntax

Parameters

Returns

Example

from pycm import *

while True:
    # GREEN LED on if START button is pressed
    # GREEN LED off if not pressed
    if button.pressed() == True :
        led.set(const.GREEN)
    else:
        led.set()

button.released()

Description

If START button is pressed then released

Syntax

Parameters

Returns

Example

from pycm import *

while True:
    # toggle GREEN if START button is pressed then released
    if button.released() == True :
        led.toggle(const.GREEN)

button.millis()

Description

Number of milliseconds START button was pressed

Syntax

Parameters

Returns

Example

from pycm import *
console(USB)

while True:
    if button.released() == True:
        ms = button.millis()
        print(ms)

button.seconds()

Description

Number of seconds START button was pressed

Syntax

Parameters

Returns

Example

from pycm import *
console(USB)

while True:
    if button.released() == True:
        s = button.seconds()
        print(s)

imu

eeprom.imu_type(direction)

Description

Syntax

Parameters

Returns

Example

from pycm import *

console(USB)

eeprom.imu_type(const.V)

imu.accel_x() / imu.accel_y() / imu.accel_z()

Description

Acceleration value in X/Y/Z-axis

Syntax

Parameters

Returns

Example

from pycm import *

console(USB)

eeprom.imu_type(const.V)
while True:
    ax = imu.accel_x()
    ay = imu.accel_y()
    az = imu.accel_z()
    print(ax, ay, az)
    delay(500)

imu.gyro_x() / imu.gyro_y() / imu.gyro_z()

Description

gyroeration value in X/Y/Z-axis

Syntax

Parameters

Returns

Example

from pycm import *

console(USB)

eeprom.imu_type(const.V)
while True:
    gx = imu.gyro_x()
    gy = imu.gyro_y()
    gz = imu.gyro_z()
    print(gx, gy, gz)
    delay(500)

imu.roll()

Description

roll value

Syntax

Parameters

Returns

Example

from pycm import *

console(USB)

eeprom.imu_type(const.V)
while True:
    r = imu.roll()
    print(r)
    delay(500)

imu.pitch()

Description

pitch value

Syntax

Parameters

Returns

Example

from pycm import *

console(USB)

eeprom.imu_type(const.V)
while True:
    p = imu.pitch()
    print(p)
    delay(500)

imu.yaw()

Description

yaw value

Syntax

Parameters

Returns

Example

from pycm import *

console(USB)

eeprom.imu_type(const.V)
while True:
    y = imu.yaw()
    print(y)
    delay(500)

mic

mic.counting()

Description

The counting number of clapping sound currently playing continuously

Syntax

Parameters

Returns

Example

from pycm import *
console(USB)

while True:
    now = mic.counting()
    print(now)
    delay(600)

mic.counted()

Description

The counting number of previously finished clapping sound

Syntax

Parameters

Returns

Example

from pycm import *

console(USB)
while True:
    now = mic.counting()
    final = mic.counted()
    print(now, final)
    delay(600)

Result

0  0
0  0
1  0     # clapping started
2  0     # counting() +1
3  0     # counting() +1
4  0     # counting() +1
5  0     # counting() +1
0  5     # clapping stopped, counting() become 0, counted() changed to 5
0  5     # counted() is still 5

mic.clear()

Description

Clear mic.counted() value to 0

Syntax

Parameters

Returns

Example

from pycm import *

console(USB)
while True:
    if mic.counted() > 0 :
        print('final_detect =', mic.counted())
        mic.clear()
        print('cleared_count =', mic.counted())

Result

final_detect = 3
cleared_count = 0
final_detect = 2
cleared_count = 0
final_detect = 13
cleared_count = 0
final_detect = 10
cleared_count = 0

rc

rc.received()

Description

If a unread remocon packet is available

Syntax

Parameters

Returns

Example

from pycm import *

while True:
    if rc.received() == True:
        led.set(CONST.RED)
    else:
        led.set()

rc.read()

Description

read the value of the last arrived remocon packet

Syntax

Parameters

Returns

Example

from pycm import *

console(USB)
while True:
  if rc.received() == True :
    r = rc.read()

    print('Receive :')

    if r & rc.BTN_U > 0:
      print('U key')
    if r & rc.BTN_D > 0:
      print('D key')
    if r & rc.BTN_L > 0:
      print('L key')
    if r & rc.BTN_R > 0:
      print('R key')

Constant values for rc

motion

motion.wait()

Description

Wait until the currently playing motion is finished

Syntax

Parameters

Returns

Example

from pycm import *

motion.play(1)
motion.wait()

led.set(CONST.GREEN)

delay(1000)

motion.play()

Description

play specified motion

Syntax

Parameters

Returns

Example

from pycm import *
console(USB)

while True:
    motion.play(1)
    print('play motion 1')
    motion.wait()
    print('play motion 2\n')
    motion.play(2)
    motion.wait()
    delay(1000)

    motion.play(1, 2)
    print('play motion 1 (with motion 2 reserved)')
    motion.wait()
    print('play motion 2\n')
    motion.play(2)
    motion.wait()
    delay(1000)

motion.status()

Description

If any motion is playing currently

Syntax

Parameters

Returns

Example

from pycm import *

motion.play(1)

while True:
    if motion.status() == True:
        led.set(CONST.RED)
    else:
        led.set()

motion.count()

Description

The number of motions stored in CM-550 controller

Syntax

Parameters

Returns

Example

from pycm import *

console(USB)

print(motion.count())

OLLO APIs

OLLO()

Description

Generate an object for the specified 5-pin port with specified 5-pin module type

Syntax

Parameters

module_type port_num
const.OLLO_WHEEL_SPEED 1, 2
const.OLLO_JOINT_POSITION 1, 2
const.OLLO_JOINT_SPEED 1, 2
const.OLLO_IR 1, 2
const.OLLO_MOISTURE 1, 2
const.OLLO_MOISTURE_TEMP 1, 2
const.OLLO_RED_BRIGHTNESS 1, 2
const.OLLO_BLUE_BRIGHTNESS 1, 2
const.OLLO_DMS 1,2,3,4,5
const.OLLO_TOUCH 1,2,3,4,5
const.OLLO_LED 1,2,3,4,5
const.OLLO_USER 1,2,3,4,5
const.OLLO_TEMPERATURE 1,2,3,4,5
const.OLLO_MAGNET 1,2,3,4,5
const.OLLO_MOTION_DETECTION 1,2,3,4,5
const.OLLO_COLOR 1,2,3,4,5
const.OLLO_BRIGHTNESS 1,2,3,4,5

Returns

Example

from pycm import *


# object stands for Wheel Motor connected to port 1
wheel_1 = OLLO(1, const.OLLO_WHEEL_SPEED)
# set wheel speed to 500, CCW
wheel_1.write(500)

delay(4000)

object.read()

Description

Read sensing value of specified 5-pin module object

Syntax

Parameters

Returns

module_type (device link) Function Meaning of return value Range
OLLO_WHEEL_SPEED read() Wheel motor speed [0, 1023] CCW
[1024, 2047] CW
OLLO_JOINT_POSITION read() Servo motor position [0, 1023]
OLLO_JOINT_SPEED read() Servo motor speed [0, 1023]
OLLO_IR read() IR sensor value [0, 1023]
OLLO_MOISTURE read() Relative humidity value [0, 100] (%)
OLLO_MOISTURE_TEMP read() Temperature value [-20, 105] (°C)
OLLO_RED_BRIGHTNESS read() Red brightness of Red-Blue LED Module [0, 100] (%)
OLLO_BLUE_BRIGHTNESS read() Blue brightness of Red-Blue LED Module [0, 100] (%)
OLLO_DMS read() DMS sensor value [0, 1023]
OLLO_TOUCH read() Tact switch sensor status 0 : Released
1 : Pushed
OLLO_LED read() LED module status 0 : Both OFF
1 : Left OFF, Right ON
2 : Left ON, Right OFF
3 : Both ON
OLLO_USER read() Analog value of User Device [0, 1023]
OLLO_TEMPERATURE read() temperature value [-20, 105] (°C)
OLLO_MAGNET read() Magnet sensor status 0 : No magnet
1 : Magnet detected
OLLO_MOTION_DETECTION read() Motion sensor status 0 : No motion
1 : Motion detected
OLLO_COLOR read() Sensed color index 0 : Unknown
1 : White
2 : Black
3 : Red
4 : Green
5 : Blue
6 : Yellow
OLLO_BRIGHTNESS read() Brightness [0, 1023]

NOTE: OLLO_MOISTURE, OLLO_MOISTURE_TEMP and OLLO_BRIGHTNESS’s manuals are currently available for Korean instruction only.

Example

from pycm import *

console(USB)

servo_1 = OLLO(1, const.OLLO_JOINT_POSITION)

position = servo_1.read()
print('servo 1 position = ', position)

object.write()

Description

Change 5-pin module object’s parameter

Syntax

Parameters

module_type (device link) Function Meaning of parameter Range
OLLO_WHEEL_SPEED write(velocity) Wheel motor velocity [0, 1023] CCW
[1024, 2047] CW
OLLO_JOINT_POSITION write(position) Servo motor position [0, 1023]
OLLO_JOINT_SPEED write(speed) Servo motor speed for position control [0, 1023]
OLLO_LED write(left, write) left : control value for left LED
right : control value for right LED
0 : OFF
1 : ON
OLLO_USER write(out1, out2) out1 : control value for OUT1 pin
out2 : control value for OUT2 pin
0 : 0V
1 : 5V

Returns

Example

from pycm import *

ledl_1 = OLLO(1, const.OLLO_LED)
# turn on left LED, turn off right LED
led_1.write(1, 0)

delay(4000)

Constant values for OLLO