iRobot Create - Playing two songs

1.8k views Asked by At

Here's my code:

import create 
robot = create.Create(3) 
robot.toFullMode()

robot.setSong(0,[(36,16),(36,16),(38,32),(36,32),(53,32),(52,32),\
(36,16),(36,16),(38,32),(36,32),(55,32),(41,32),\
(36,16),(36,16),(48,32),(33,32)]) 

robot.setSong(1,[(53,32),(40,32),(38,32),(34,16),(34,16),\
(33,32),(41,32),(43,32),(41,32)])  

robot.playSongNumber(0)
robot.playSongNumber(1) 

The first song plays, but the second one won't...any ideas as to why? This is being coded with the create.py Python interface to the iRobot Create:

2

There are 2 answers

1
abarnert On BEST ANSWER

Without seeing any documentation or source code, this is a wild guess, but…

I'll bet the playSongNumber function just sends the robot the play command, without waiting for it to finish, and when you send it a play command while it's already playing something, it ignores you.

If I'm right, then hopefully the API provides some way to wait until it's done. If it doesn't provide that, but it does provide a way to poll the current state, you can do that in a loop (sleeping briefly between each check) until it's done. If it doesn't even provide that, then you have to work out how long the song will take by counting the number of notes (or adding the durations, if one of the numbers in each of those pairs is a duration) and sleep that long.

0
amo On

playSongNumber checks whether a song is currently playing, and it will ignore new songs until the first one is done playing. You can check whether the song is done by polling the song-playing? sensor (number 37).

The Create open interface document is located here:

http://www.irobot.com/filelibrary/pdfs/hrd/create/create%20open%20interface_v2.pdf

From that document:

Play Song

This command lets you select a song to play from the songs added to iRobot Create using the Song command. You must add one or more songs to Create using the Song command in order for the Play command to work. Also, this command does not work if a song is already playing. Wait until a currently playing song is done before sending this command. Note that the “song playing” sensor packet can be used to check whether Create is ready to accept this command.

Song Playing

Packet ID: 37 Data Bytes: 1 unsigned

The state of the OI song player is returned. 1 = OI song currently playing; 0 = OI song not playing.