Lego NXT remote using Phonegap, Angular, and Typescript.
The primary purpose of this project is to help teach children how to program. The javascript API allows easier access to robot programming without getting very low level. The firmware of the Lego NXT brick does not need to be changed to use the API.
To setup the project run the following commands:
git clone git://github.com/mronemous/lego-nxt-remote.git && cd lego-nxt-remote
npm install
bower install
grunt create:cordova
Import the android project (/build/cordova/platforms/android) with your favorite IDE.
To run the local file watches and also start a local webserver.
grunt serve
TODO: grunt build currently only handles web code. Ideally it would allow release / debug configurations to create platform artifacts.
Create a Brick
var mac = "XX:XX:XX:XX:XX:XX"; //Mac of your brick. var brick = new Nxt.Brick(); var driveL = new Nxt.Motor(); var driveR = new Nxt.Motor(); var cameraLift = new Nxt.Motor(); var sonarFront = new Nxt.SonarSensor(); sonarFront.name = "Front"; var sonarBack = new Nxt.SonarSensor(); sonarBack.name = "Back"; var compass = new Nxt.CompassSensor(); compass.name = "Heading"; var touch = new Nxt.TouchSensor(); touch.name = "Pressed"; brick.portA = driveL; brick.portB = cameraLift; brick.portC = driveR; brick.port1 = sonarFront; brick.port2 = touch; brick.port3 = sonarBack; brick.port4 = compass;
Connect to Brick
brick.connect(mac, function() { //connected }, function(){ //error connecting });
Disconnect from Brick
brick.disconnect(mac, function() { //disconnected }, function(){ //error disconnecting });
Write to a Motor
driveL.power = 100; driveL.mode = Nxt.Motor.Modes.On; driveL.regulation = Nxt.Motor.Regulation.None; driveL.write(false);
Read a Sensor
compass.read(Nxt.CompassSensor.Registers.Degree, function(reading) { //Reading obtained by sensor. }, function() { //Failed to get a reading from the sensor. });
Play tone
brick.playTone(frequency, duration);
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.