Enchanting 0.0.1 - Now Exports Code

I have got Enchanting exporting LeJOS code that will actually compile and run on your NXT. I have only tested it enough to see that it works, and I know there are bugs remaining to be found.

If you’d like to try it, and have LeJOS installed and set up, download it here. (36 MB)

New in this version:

  • exporting actually works.
    • if you want to mess with it, play with the two files starting with ‘lejos’ in the locale directory.
  • you should be able to double-click on Enchanting.exe/Enchanting.app to start the program, instead of dragging and dropping the image. (Not tested on Windows).
  • I have removed blocks that do not export, and created a few that translate nicely into LeJOS.

So, open up Enchanting, and create a script.

Dream up a Script

Right click on your sprite and choose “Export”. You’ll be prompted for a name. Please, use a name that can be used as a Java class — stick to letters and numbers (and maybe underscores) and you’ll be fine.

Export the File

Then, go to your trusty terminal and compile and upload the program:

Compile and upload your code

And run it on your NXT!

Please let me know how well it works for you and what fixes I need to make.

Addendum

I forgot to mention that variables and lists do not work at all, and that the following configuration is assumed:

Motors

  • Left is Motor C.
  • Right is Motor A.
  • ‘Claw’ is Motor B.

Sensors

  • Touch Sensor is on port 1
  • Sound Sensor is on port 2
  • Light Sensor is on port 3
  • Ultrasonic Sensor is on port 4

If you don’t have a given sensor attached, it should not be a problem.

Posted by Clinton Blackmore - Thursday August 26, 2010.
Posted in .
Comment

Status of Exporting Code from Enchanting

In the far-too-brief periods of time I’ve been able to put into Enchanting of late, I’ve been working on making it so that you can export code. I wanted to put up some incomplete results of my work.

If I construct the following script:

Sample Line-Follower Program

middle click on the sprite that owns the script and choose “export code”:

Export Code (context sensitive menu)

a window pops up with the text converted into a Java-esque format:

    public void WhenGreenFlagClicked()
    {
        // GoTo(-100, 0);
        // ClearDisplay();
        // PenDown();
        // PlaySound();
        // PlayDrum(48, 0.2);
        // WaitSecs(RandomRange(1, 10) / 5);
        // WaitSecs(Math.pow(Math.E, 10));
    }

public void WhenGreenFlagClicked() { LightSensor.SetMaxPoint(LightSensor.GetRawReading()); LightSensor.SetMinPoint(LightSensor.GetRawReading()); LeftMotor.runUnlimited(); Right Motor.runUnlimited(); for (int i = 0; i < n; ++i) { if (LightSensor.GetRawReading() > LightSensor.GetMaxPoint()) { LightSensor.SetMaxPoint(LightSensor.GetRawReading()); } if (LightSensor.GetRawReading() < LightSensor.GetMinPoint()) { LightSensor.SetMinPoint(LightSensor.GetRawReading()); } } while(true) { LeftMotor.setPower(LightSensor.GetBrightness()); Right Motor.setPower(); } }

There are still flaws and shortcomings to overcome, and it isn’t real code yet, but I’m pleased with the progress.

If you want to try it out (without getting the latest from version control), download this snapshot of the program, drag and drop Enchanting.image onto your Enchanting.exe or Enchanting.app, and have fun.

The files of note are:

  • the Enchanting.image file, which has all the code changes
  • locale/lejos.exp — a translation file used to translate from Scratch to the java-esque output (go ahead and play with it; it is reloaded every time you click export)
  • the ReferenceImages folder, which has pictures of the different code blocks with their block specification name in English. (This is handy for translating, and, if you hold down Shift and click on the file menu, there is an option to generate these files.)

Posted by Clinton Blackmore - Saturday August 14, 2010.
Posted in .
Comment

Arduino + NXTMMX + LEGO Motors

When I first learned that Mindsensors.com (who make several really neat sensors for use with the NXT) was making a motor multiplexer, I contacted them to ask if it would work with the Arduino (yes!) … and then I asked if I could buy a prototype and was thrilled when they sent me one. (Thanks!)

This video shows how well it works.

Oh man. I love the NXT, but I really like the possibilities that this affords. The NXTMMX allows you to connect two LEGO motors to a device that issues I2C commands, and gives you one more port to plug in another NXT device. There is a good tech spec documenting the commands, so there is no reason it wouldn’t work with your microcontroller of choice, by merely connecting four wires (with a cable like this, or something from here) and supplying power with a battery pack.

Better than that, though, is that there are other I2C sensors for the NXT which will work. When I run the I2CScanner example sketch, I am able to see a HiTechnic Compass Sensor and a Mindsensor’s Line Leader. Most of my other sensors do not use the I2C bus to communicate and would need to be connected differently to use with an Arduino. [For anyone who wants to try, allow me to recommend Extreme NXT: Extending the LEGO MINDSTORMS NXT to the Next Level, or download the NXT Hardware Development KitLEGO was kind and wise enough to offer schematics on how the parts works.] One I2C sensor that did not work was LEGO’s Ultrasonic sensor. I suspect that if I provided a 9V power signal to it, it would work.

I have started an open-source project called NXT I2C Devices for Arduino. The project contains my initial code to run the NXTMMX (ported from the Not eXactly C API for the device), and, Mindsensors has been contributing code so you can use it with other sensors that they sell! Right now you need to install the Bazaar version control system to get the latest code. (I’ll update these instructions if/when I make a more straightforward download available.) At a command prompt, change to the Arduino library directory (on my Mac it is /Applications/Arduino.app/Contents/Resources/Java/libraries/), and issue this command:

bzr branch lp:nxti2cdevice NXTI2CDevice

If you’d prefer to use a graphical tool, take a look at the first few steps of my previous post explaining the use of Bazaar Explorer with Enchanting. Just make a branch of lp:nxti2cdevice, and then copy/move/symlink the folder into your Arduino libraries folder.

Oh, and if you are interested in helping out on the project, drop me a line.

Happy Hacking!

Posted by Clinton Blackmore - Wednesday July 7, 2010.
Posted in .
Comment