Myro Reference Manual

From IPRE Wiki
Revision as of 17:42, 25 January 2007 by Ashgavs (Talk | contribs) (Robot Functional Interface)

Jump to: navigation, search

All the commands from Myro are available in Python by importing them. For example:

c:> python
>>> from myro import *

or

c:> python
>>> import myro

If you use the second method, then all classes and functions must be prefaced with myro. (note the dot). For example, in the functions below, if you use the second method, you would write myro.wait(1). Otherwise, if you use the first method, you can just write wait(1).

General Functions

ask(item) - will ask one time for item(s)

>>> ask("Name")
(window pops up, user enters Sarah, presses Ok button)
'Sarah'

raw_input(prompt) - will prompt user for input. Like ask, but no window.

>>> raw_input("How old are you? ")
How old are you? 19
'19'

askQuestion(question, [answerList]) - prompt a question and return answer.

>>> askQuestion("Are you ready?")
(window pops up, users selects Yes)
'Yes'
>>> askQuestion("How many lumps would you like?", ["One", "Two", "Three"])
(window pops up, user selects Three)
'Three'

wait(seconds) - Pause for the given amount of seconds. Seconds can be a decimal number.

>>> wait(5)
>>> 

currentTime() - the current time, in seconds from an arbitrary starting point in time, many years ago. Can you figure out the date of the start time?

>>> currentTime()
1164956956.2690001

flipCoin() - Returns "heads" or "tails" randomly.

>>> flipCoin()
'tails'
>>> flipCoin()
'tails'
>>> flipCoin()
'heads'

randomNumber() - Returns a random number between 0 (inclusive) and 1 (exclusive).

>>> randomNumber()
0.65218366496862357

File and Folder Functions

pickAFolder() pop up window.

pickAFolder() - allows you to select a folder

>>> pickAFolder()
'C:/Python24'
pickAFile() pop up window

pickAFile() - allows you to select a file

>>> pickAFile()
'C:/Python24/README.txt'

Media Functions

readSong(filename) - reads a file in the Song File Format and returns a list of tuples.

makeSong(text) - make a song in the Song File Format where lines are separated by semicolons.

>>> makeSong("c 1; g 1/4; a 1/2; e 3/4;")
[(523.29999999999995, 1.0), (784.0, 0.25), (880.0, 0.5), (659.29999999999995, 0.75)]
>>> singsong = makeSong("c 1; g 1/4; a 1/2; e 3/4;")

saveSong(text or song, filename) - saves a song in tuple format, or in text format

speak(message, async = 1) - text-to-speech, turns message into spoken words

stopSpeaking() - stop the speaking

setVoice(name) - set the voice to a known voice by name

getVoice() - get the voice of the current speaker

getVoices() - get a list of all of the possible voices

playSpeech(filename) - play a WAV file

saveSpeech(message, filename) - save the message as a WAV file

Robot Functional Interface

initialize(): initializes the Scribbler robot; may ask for a port

Initialize() Put in the corresponding port to start MyRo!
>>> initialize()
Hello, I'm Scribby!

simulator(): initializes the simulated Scribbler

Movement Functions

translate(amount): move forward and backwards. 0 to 1 moves forward; 0 to -1 moves backwards

>>> translate(1)  # full speed ahead
>>> translate(-1) # full speed backwards
>>> translate(0)  # stop in the translate direction

rotate(amount): turn left or right. 0 to 1 turns left, 0 to -1 turns right

>>> rotate(.5)  # half-speed to the left
>>> rotate(-1)  # full speed to the right

NOTE: translate and rotate are independent, although they both effect each the wheel.

move(translate, rotate): rotate and translate

forward(amount): move forward

>>> forward(1)

backward(amount): move backward

>>> forward(.9)

turn(direction, amount = .8): rotate in a direction

turnLeft(amount): turn left

>>> turnLeft(.4)

turnRight(amount): turn right

>>> turnRight(.5)

stop(): stop all movement

>>> stop()

motors(left, right): control the left and right motors

joyStick(): opens a joystick window; click and drag to move robot

Miscellaneous Functions

openConnection(): open the connection (done by default)

closeConnection(): close the connection

update(): update the readings (currently not used)

beep(self, duration, frequency, frequency2 = None): make a tone

restart(): reinitialize the robot

Get Sensor and Data Functions

get(sensor): read the sensor "stall"; or get all readings of "ir", "light", or "line"; or get "all" which is all of those

get(sensor, pos): read any of the following sensors or items by name and position

>>> get("stall")
0
>>> get("light", 0)
128
>>> get("line")
[0, 0]
>>> get("all")
{'light': [235, 13], 'line': [1, 0], 'ir': [0, 0], 'stall': 0}

getLight(pos): read a light sensor; defaults to "all"

getIR(pos): read an IR sensorl defaults to "all"

getLine(pos): read line sensor; defaults to "all"

getStall(): read stall sensor

NOTE: Every time you issue a move command, the stall sensor resets, and it needs to wait a short time to see whether the motors are stalled. This means that the sensor won’t give accurate results if you test it too soon after the robot starts to move.

getName(): read the robot's name

getAll(): read all positions of all of the sensors; returns a dictionary

getVolume(): returns 0 or 1

getStartSong(): returns name of start song

Not implemented yet.

getData(): get some bytes stored in the robots memory

Not implemented yet.

getInfo(): retrieve information about the robot

Scribbler only.

Setting Values

set(item, value): set a value (for "name", and "volume")

set(item, position, value): set a value (for "led")

>>> set("name", "Duckman")
>>> set("led", "center", "off")
>>> set("volume", "off")

setLED(position, value): set a LED

>>> setLED("left", "on")
>>> setLED("right", "off")

setName(name): set the robot's name (limit of 8 characters)

>>> setName("Howie")

setVolume(level): set the speaker's volume (0/"off" or 1/"on")

>>> setVolume("off")
>>> setVolume(0)
>>> setVolume("on")
>>> setVolume(1)

setStartSong(songname): set the start-up song; default "tada"

Not completed.

setData(position, value): set a byte of data in the robot's memory to a value between 0 and 255.

Not completed.

Robot Object Interface

This section describes the constructors and methods of the object-oriented interface.

Constructors

robot = Scribbler(port) - real robot constructor for the Scribbler; may ask for a port. You may also provide a name, which causes Myro to search the ports for such a robot.

>>> robot = Scribbler()
>>> robot = Scribbler("Scribby")
>>> robot = Scribbler("com4")

robot = Surveyor(port) - real robot constructor for the SRV-1; may ask for a port (this is under development)

robot = SimScribbler() - simulator constructor (this is currently under development)

Movement

All velocities are in the range of -1 to 1 (floats and ints ok).

robot.forward(amount) - move forward with velocity amount

robot.backward(amount) - move backward with velocity amount

robot.translate(amount) - move forward/backward with velocity amount

robot.turn(directionName | amount) - turn to "left", "right", "center" or velocity

robot.turnLeft(amount) - rotate to left with velocity amount

robot.turnRight(amount) - rotate to right with velocity amount

robot.rotate(amount) - rotate an amount (+ to left, - to right)

robot.move(translate, rotate) - move both translate and rotate

robot.motors(left, right) - apply left and right velocities to each wheel respectively

robot.stop() - stops all movement

robot.joyStick() - opens up a window to manual control robot

Getting Sensors and Data

robot.get(sensor) - get "name", "ir", "light", "line", or "all".

robot.get(sensor, position) - read a particular position of "ir", "light", or "line".

robot.getLight(position) - 3 light sensors on front

robot.getIR(position) - 2 IR on front

robot.getLine(position) - 2 line sensors on bottom; returns 0 or 1 in simulator

robot.getStall() - 0 if motors are able to turn; 1 if they are unable to turn

NOTE: Every time you issue a move command, the stall sensor resets, and it needs to wait a short time to see whether the motors are stalled. This means that the sensor won’t give accurate results if you test it too soon after the robot starts to move.

robot.getAll() - returns dictionary of all sensory data, where keys are "light", "ir", "line", or "stall"

robot.getName() - returns name of robot

robot.getVolume() - returns volume level

robot.getData(position, ...) - returns the bytes in the given positions, or all of no position is given

robot.getInfo(item, ...) - returns the item specified by name, or a dictionary of items if no items are given

Setting Items

robot.set(item, value) - item can be "data", "volume", or "name"; and value can be any valid setting.

robot.set(item, position, value) - item can be "led"; position can be "center", "left", and "right"; and value can be 0, "off", 1, or "on".

>>> robot.set("name", "Jill")
>>> robot.set("led", "left", "on")

robot.setLED(position name, value) - name is "center", "left", and "right", value is 0/"off" or 1/"on"

>>> robot.setLED("left", "on")

robot.setName(name) - sets the robot's name; persistent. Limited to 8 characters

>>> robot.setName("Harry")
>>> robot.set("name", "Jill")
>>> robot.getName()
>>> robot.get("name")

robot.setVolume(level) - sets the speaker's volume; level is 0/"off" or 1/"on"

>> robot.setVolume(0)
>> robot.setVolume("on")

robot.setStartSong(name) - sets the start up song by name; default is "tada"

Not implemented yet.

robot.setData(position, value) - sets a byte of memory on the robot's computer

Not implemented yet. But is imagined to work like:

>>> robot.setData(0, 255)
>>> robot.set("data", 1, 0)
>>> robot.getData(0)
>>> robot.get("data", 1)

Other Commands

robot.update() - currently, this is not necessary as the read commands do this automatically

robot.beep(duration, frequency, [frequency2]) - makes a sound (simulator just beeps on Linux; control+a on Windows?). Duration is given in seconds (floats are ok).

robot.restart() - sends some restart code to stop the motors and play a little song. Might do more in the future.

robot.open() - open serial port; already done by default

robot.close() - close the serial port

robot.playSong(song) - play a song in the Song File Format

Computer Object

The computer object is automatically created. In addition to the robot, the computer can also make sounds.

computer.speak(message) - computer will say the text message

computer.stopSpeaking() - stop talking

computer.setVoice(name) - set the voice to a named voice

computer.getVoice() - get the name of the current voice

computer.getVoices() - get alternative set of named voices

computer.playSpeech(filename) - play a speech file (wav file)

computer.saveSpeech(message, filename) - save speech to a wav file

computer.beep(duration, frequency, [frequency2]) - makes a sound from computer. Duration is given in seconds (floats are ok).

computer.playSong(song) - play a song in the Song File Format

Instant Messaging Interface

You can send and receive messages from other Myro users.

>>> chat = Chat("myname", "mypassword")
>>> chat.send("somebodyelse", "Hi, how are you?")
>>> chat.receive()
[("sombodyelse@myro.roboteducation.org", "I'm fine, thanks!")]

Remote Robot Control

The robot that will be controlled:

>>> robot.initializeRemoteControl("mypassword")
>>> robot.processRemoteControl()
>>> []
>>> robot.processRemoteControlLoop() # threaded, infinite loop
>>> 

The computer that will be the controller:

>>> chat = Chat("myname", "mypassword")
>>> chat.send("remoterobotname", "robot.turnLeft(.4)")
>>> chat.receive() 

There is also a RemoteRobot constructor which acts like a regular robot, but sends the commands to the other robot.

>>> robot = RemoteRobot("remoterobotname")
>>> robot.turnLeft(.4)