# MyroNXT Reference

MyroNXT is a new framework for programming robots. It is written in the language Python and designed for use in Introductory Computing courses. It is being developed by the Institute for Personal Robots in Education.

## Getting Started

All the commands from MyroNXT are available in Python by importing them. Here is a quick start list:

1. Double-click on the "Start Python" icon on the desktop
2. Enter: from MyroNXT import *
3. Turn on the robot, and connect via Bluetooth
4. Now, you can enter init(PortName) where PortName is the COM port of your robot

### Manual Drive

Currently all commands must be entered into either the Calico shell or as functions in a python file.

senses(): Opens a window to see the robot's sensor values.

## Output Functions

beep(self, duration, frequency, frequency2 = None): make a tone. If two tones are given, the robot will combine them.

## Input Functions

Currently there are no actual input functions for the NXT, but perhaps could be implemented with help from the Myro library.

## Movement Functions

All Myro movement functions have equivalents and there are additional functions to compensate for the ability to control multiple motors attached to multiple ports.

forward(amount, seconds): move forward, stop any rotation, for number of seconds

```>>> forward(1, .5)
```

backward(amount, seconds): move backward, stop any rotation, for number of seconds

```>>> backward(.9, 2)
```

turnLeft(amount, seconds): turn left, stop any forward movement, for number of seconds

```>>> turnLeft(.4, 1)
```

turnRight(amount, seconds): turn right, stop any forward movement, for number of seconds

```>>> turnRight(.5, 1)
```

stop(): stop all movement

```>>> stop()
```

translate(amount): move forward and backwards. 0 to 1 moves forward; 0 to -1 moves backwards rotate(amount): turn left or right. 0 to 1 turns left, 0 to -1 turns right

NOTE: translate and rotate are independent, although they may both effect each the wheel. That means that a translate() and a rotate() will blend into a meaningful combination.

```>>> translate(1)  # full speed ahead
>>> translate(-1) # full speed backwards
>>> translate(0)  # stop in the translate direction
>>> rotate(.5)  # half-speed to the left
>>> rotate(-1)  # full speed to the right
```

move(translate, rotate): rotate and translate

```>>> move(0, 1)  # turn full speed to left
>>> move(0, -1) # turn full speed to right
>>> move(1, 1)  # turn full speed to left while moving full speed ahead
>>> move(.5, 0) # go forward half speed
```

SetMotorPort(port,direction): This assigns the specified direction to the port. Valid ports are (“A”,”B” or “C”), valid directions are (“left” and “right”). Default assignments are based on the base robot shown in the NXT manual.

```>>> SetMotorPort("A", "left") # assign motor port A the direction left
```

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

```>>> motors(.6,.8) # left motor at 60 percent and right motor at 80.
```

motors(port,amount,seconds): control the specified motor. The motor will run for number of seconds, if “seconds” is 0 the motor will run indefinitely.

```>>> motors("A",.8,4) # run motor port A at 80 percent for 4 seconds
```

motors(amountA,amountB,amountC): move motors A, B and C at the respective amounts. Requires the stop() command afterward

There are no default sensor bindings, all sensors must be initiated. So far there is support for the touch, sound. light and ultrasonic sensors. The sensor ports are numbered 1-4 and when a port is requested it can simply be entered as a number 1-4. The types must be entered as “touch”, “sound”, “light” or "ultrasonic".

SetSensors(port,type): Initiates the specified port. If the ports are uninitiated they cannot be read.

```>>> SetSensors(1,"touch") # initiates a touch sensor attached to port 1
```

senses(): Presents a GUI with the state of all initiated sensors

getTouch(port): This returns true or false based on the state of the touch sensor attached to the port. Again, port must be initiated.

getLight(port): This returns the scaled value of the light sensor attached to the port, a value between 0-100. Port must be initialized

getSound(port): This returns the scaled value of the sound sensor attached to the port, a value between 0-100. Port must be initialized.

resetSensors(): This command will reset all sensor ports. When the NXT is initialized the ports are cleared.

## Setting Values

The values that need setting are the sensor ports SetSensors(port,type), the assignment of left and right if not using the default assignment SetMotorPort(port,direction) and the setting of the robot's forwardness setForwardness(orientation). These assignment fucntions can be found in their respective sections.

## Flow of Control

Currently there are no flow of control functions implemented into MyroNXT, however the available functions in the Myro library may be adapted to use with the NXT.

## Image processing

Since there is no camera for the NXT, no image processing is needed.

## Miscellaneous commands

Miscellaneous functions such as wait(seconds) may be adapted from the Myro library with little difficulty.

### Random decisions

The random decision functions may also be adapted from the Myro libary.

### File and Folder Functions

This section is not applicable for the NXT, while there is onboard storage it is not currently used for user file storage.

### Media Functions

This section is not applicable for the NXT.

## Web development

This section is not applicable for the NXT.

Currently all commands must be entered through either the terminal or in a python file. However, gamepad use may be possible with help from the Myro library.

## Arrays

Not applicable for the NXT

### System commands

Not applicable for the NXT

## Robot Object Interface

Not applicable for the NXT

## Computer Object

Not applicable for the NXT

## Instant Messaging Interface

Not applicable for the NXT

## Remote Robot Control

Not applicable for the NXT

#### Robot's Orientation

The default forward direction is the direction that the sensor ports are facing. This can be changed using the setForwardness function.

setForwardness(orientation): orientation can be 0/"sensor-forward" or 1/"motor-forward"

getForwardness(): Returns the orientation of the robot "sensor-forward" or "motor-forward"