Tag Archives: running

BricxCC for Mindstorms Running On Linux

BricxCC-RunningOnLinux
www.pdf24.org    Send article as PDF   
Bricx Command Center (BricxCC) is a Windows (95, 98, ME, NT, W2K, XP, Vista) program commonly known as an integrated development environment (IDE) for programming the Lego Mindstorms NXT, RCX (all versions), Scout, Cybermaster, and Spybot programmable bricks using Dave Baum’s Not Quite C (NQC) language. BricxCC now also supports programming the new LEGO Mindstorms NXT brick using Not eXactly C (NXC), Next Byte Codes (NBC), and a simple on-brick programming language called NPG.

If all went to plan, you can now access your NXT Brick from Linux. You can also add NXT-G and LabView to your Windows Virtual Machine as well if you wish like show below!s programming the Scout, RCX2, and Spybot using The LEGO Company’s MindScript(tm) and LASM(tm) languages via the Mindstorms 2.5 SDK. It supports programming RCX bricks in C, C++, Pascal, Forth, and Java using the brickOS, pbForth, and leJOS alternate firmwares.

Downloading and Setting Up The Tools

  1. Install the required Free Pascal Compiler. The tools are written in PASCAL. sudo aptitude install fpc libusb-dev
  2. Download the bricxcc source from SVN. Only the SVN version (as of now) contains support for some of the new sensors included with the NXT 2.0 brick and works with 64-bit Linux. https://bricxcc.svn.sourceforge.net/svnroot/bricxcc/
  3. Enter the bricxcc source code. cd bricxcc
  4. Build NeXTTool, used for transferring files to and from the brick, and other miscellaneous operations. make -f ./nexttool.mak
  5. Enter the NXT directory, inside of bricxcc source code. cd NXT
  6. Build the NCB/NXC compilers. make -f nbcunix.mak
  7. Install the build tools. I copy my to ${HOME}/bin, which means that you need to have it included in your PATH. cp nbc ../NeXTTool ~/bin

 

 

Setup Aliases For Your NXT Bricks

Using the NBC/NXC tools, you can setup aliases for your NXT bricks. This means that if you connect two bricks at the same time, you can pick which one to communicate to by specifying it’s alias. If you are only connecting one brick via USB, you do not have to setup any aliases as a default one called “usb” is created. However, if you plan to use Bluetooth, you have to setup an alias by following these steps:

  1. Connect your brick in any way you want to communicate with it, either via Bluetooth (see beginning of “Transferring Code Over Bluetooth“), USB or both.
  2. Dump all found bricks to a file called nxt.dat, located in your home directory. The following command will create a new file, overwriting an existing file, and fill it with all found bricks. If you do not want to overwrite the existing file, because you already have some bricks listed, just run the command before > to display the list of found bricks and append them manually.

    NeXTTool -listbricks > ~/nxt.dat

  3. Open the ~/nxt.dat file using your favourite text editor. Each line lists a found device, with the part before = being the alias and the part after being the device ID. The device ID will be unique, and automatically generated by your brick. Don’t touch it! Mine looks like the following:

    000000000000=USB0::0o0000::000000::000000000000::RAW BTH::NXT=BTH::NXT::00:00:00:00:00:00::5

    The first line is my brick connected via USB, and the second line is my brick connected via Bluetooth.

  4. Change the part before the equal sign, the alias, to something that you will remember. Save your changes. The following is my ~/nxt.dat file after my changes:

    usb=USB0::0o0000::000000::000000000000::RAW bt=BTH::NXT::00:00:00:00:00:00::5

  5. Now you can use either of the aliases above for communicating with your brick. When I am connected via usb, I use the alias usb. When I am connected via Bluetooth, I use the alias bt. You use these aliases by adding the flag -S=alias to nbc or /COM=alias to NeXTTool.

 

 

Transferring Code Over USB

  1. Create a file called 45-legonxt.rules with the following contents and place it into the /etc/udev/rules.d directory. Make sure to set the GROUP variable to a group that exists. On Ubuntu, plugdev is the group that all users that can use pluggable devices belong to. On Gentoo, I use the usb

    group.SUBSYSTEM==usb_device”, ACTION==add, SYSFS{idVendor}==0694?, SYSFS{idProduct}==0002?, SYMLINK+=legonxt-%k, GROUP=plugdev, MODE=0660?, RUN+=/etc/udev/legonxt.sh

  2. Create a file called legonxt.sh with the following contents and place it into the /etc/udev directory. Don’t forget to edit the GROUP variable here too.

  3. Make the legonxt.sh file executable

    sudo chmod +x /etc/udev/legonxt.sh

  4. Plug in the NXT brick via USB and turn it on. You should now see a new file under /dev corresponding to it named /dev/legonxt-#-#. If it does not exist, then something is wrong.

    ls /dev | grep legonxt

  5. Find out your NXT firmware version, which is found by navigating the NXT brick LCD display using the arrow buttons. The version is found under: Settings -> NXT Version. It is the first row.
  6. Download my helloworld.nxc code (or write your own), unpack it and run the following command.

    nbc -d -v=128 helloworld.nxc

    • The -d flag tells the nbc to download the compiled code to the brick.
    • The -v=128 tells nbc to compile the code for firmware version 1.28. Without this, I couldn’t get the transfer to work. Replace 128 with any other version that you are using, and make sure to drop the dot (Notice I wrote 128 and NOT 1.28. That is not a typo.)
    • helloworld.nxc is the file to compile and transfer. You can also also type dancer.nbc to transfer the byte-code file. The command (both NBC and NXC use the nbc command) and other options are exactly the same for both.
  7. If everything worked correctly, then wait for a beep from the NXT brick. No beep means that there was a problem, even if no error messages were printer.
  8. On the NXT brick, get to the main menu by pressing the gray button repeatedly. Then navigate to My Files->Software files and find the file that you compiled, without the extension. Press the aqua button to select it, and press the aqua button once more to run it.

 

 

Installing VirtualBox

For using Linux as a Host OS for VirtualBox, I will show you how to create a Windows virtual machine that can interact with shared network folders in a Windows network as if it were an actual machine instead of a virtual one. In this article, I will also show you how to mount local Linux directories as network drives within your Windows Guest OS. I’ll start by assuming that you already have VirtualBox installed (available here).

This tip assumes that you have legitimate installation media for Windows XP. Start by selecting “New” to create a new virtual machine. vbox1.jpg Indicate the Virtual Appliance name, and select the type of Operating System. In this case, it will be Windows XP. vbox2.jpg Select the amount of RAM that you want the virtual machine to use. I chose 1024 megabytes, as my system machine has 4GB of RAM. vbox3.jpg Choose an exisiting virtual hard disk, or create a new one. I will assume that you wish to create a new virtual disk image (VDI). vbox4.jpg Choose either a dynamically expanding or fixed size virtual disk. I’m a fan of dynamically expanding storage, as it takes up less room on your hard drive if the virtual hard disk is not full. vbox5.jpg Choose the size of your hard disk. In VirtualBox, expanding the size of virtual disk is a relatively time-consuming endeavor, so give yourself some breathing room here. vbox6.jpg Verify your hard disk choices and choose “Finish”. vbox7.jpg Verify the rest of your choices, and click “Finish” again, vbox8.jpg Your Guest OS should now be in your VirtualBox menu. Before installing, we need to change some of settings, so highlight your virtual machine and click on “Settings”. vbox9.jpg If you wish to install XP from an actual disk, the you need to enable the drive through the host OS. Under “Storage”, select the CD icon under IDE controller, and select “Host Drive” under “CD/DVD Device”. vbox10.jpg

Insert the OS disk, start the virtual machine, and install Windows XP as if it were a normal machine. I found that mounting a WindowsXP Disc image to be faster and more liable. Installing Guest Additions to the Windows XP Guest After installing the OS, I would recommend installing Guest Additions to your Windows XP machine. There is an entire chapter of the VirtualBox Manual dedicated to Guest Additions, and I encourage you to read it, but here is the manual’s description of what Guest Additions can do. The Guest Additions offer the following features:

  • Mouse pointer integration – To overcome the limitations for mouse support that were described in the section called “Capturing and releasing keyboard and mouse”, this provides you with seamless mouse support. You will only have one mouse pointer and pressing the Host key is no longer required to “free” the mouse from being captured by the guest OS. To make this work, a special mouse driver is installed in the guest that communicates with the “real” mouse driver on your host and moves the guest mouse pointer accordingly.
  • Better video support – While the virtual graphics card which VirtualBox emulates for any guest operating system provides all the basic features, the custom video drivers that are installed with the Guest Additions provide you with extra high and non-standard video modes as well as accelerated video performance.
  • In addition, with Windows and recent Linux, Solaris and OpenSolaris guests, if the Guest Additions are installed, you can resize the virtual machine’s window, and the video resolution in the guest will be automatically adjusted (as if you had manually entered an arbitrary resolution in the guest’s display settings).
  • For Linux and Solaris guests, the Xorg server version 1.3 or later is required for automatic resizing (the feature has been disabled on Fedora 9 guests due to a bug in the X server they supply). The server version can be checked with Xorg -version.

Finally, if the Guest Additions are installed, 3D graphics for guest applications can be accelerated; see the section called “Hardware 3D acceleration (OpenGL and Direct3D 8/9)”.

  • Time synchronization – With the Guest Additions installed, VirtualBox can ensure that the guest’s system time is better synchronized. This fixes the problem that an operating system normally expects to have 100% of a computer’s time for itself without interference, which is no longer the case when your VM runs together with your host operating system and possibly other applications on your host. As a result, your guest operating system’s timing will soon be off significantly. The Guest Additions will re-synchronize the time regularly. See the section called “Tuning the guest time synchronization parameters” for how to configure the parameters of the time synchronization mechanism.
  • Shared folders – These provide an easy way to exchange files between the host and the guest. Much like ordinary Windows network shares, you can tell VirtualBox to treat a certain host directory as a shared folder, and VirtualBox will make it available to the guest operating system as a network share. For details, please refer to the section called “Folder sharing”.
  • Seamless windows – With this feature, the individual windows that are displayed on the desktop of the virtual machine can be mapped on the host’s desktop, as if the underlying application was actually running on the host. See the section called “Seamless windows” for details.
  • Shared clipboard – With the Guest Additions installed, the clipboard of the guest operating system can optionally be shared with your host operating system; see the section called “General settings”.
  • Automated Windows logons – (Credentials passing; Windows guests only) For details, please see the section called “Automated Windows guest logins”.

OK, Now you should be convinced that installing Guest Additions is a good idea. Luckily, installing Guest Additions is easy! While your virtual machine is running, click the “Devices” menu and select “Install Guest Additions.”

vbox16.jpgA setup wizard should begin shortly. Choose to continue. vbox17.jpgTwice during the install, Windows will freak out and warn you that the drivers that are being installed haven’t passed “Windows Logo testing”. It’s OK. Choose to “Continue Anyway”. vbox18.jpgWindows will ask you to reboot your (virtual) machine. Do it. vbox19.jpgCongratulations. VirtualBox Guest Additions have now been installed.


Now that Guest Additions have been installed, let’s take advantage of the feature that allows you to mount a Linux directory as a network share. Select your Virtual Machine from the menu, and select “Settings” vbox9.jpgUnder “Shared Folders”, click the vbox27.jpgAdd Shared Folder icon on the right side of the window. vbox12.jpgUnder “Folder Path”, select “Other”. vbox15.jpgBrowse to the directory that you wish to share, and select “Open”. vbox13.jpgVerify your selection, choose the name of the shared folder, choose whether or not to have “read-only” access, and click “OK”. vbox14.jpgStart your virtual machine, click the start menu, right click “My Computer” and select “Map Network Drive”. vbox20.jpgChoose the drive letter of your network drive, and click “Browse” to find your directory. vbox28.jpgYour share should be listed under:

 

 

 

 

Select “OK”, then select “Finish” vbox21.jpgMarvel at your new “Network Drive” shared folder. This is one way to get around resizing your virtual machine if you are running out of virtual hard drive space. vbox22.jpg

 

 

 


If you wish that your Guest OS can access and share files on your Windows file sharing network, you will need to change the way that your virtual machine interacts with the Internet. Under “Settings”/”Network”, change “NAT” to “Bridged Adapter”. vbox11.jpgPlease understand, the choice to use Bridged Networking does have security repercussions. The VirtualBox Manual explains the benefits and limitations of the different networking modes that are available, but this statement from the VirtualBox manual sums it up rather well:

In bridged networking mode, all traffic goes through a physical interface of the host system. It is therefore possible to attach a packet sniffer (such as Wireshark) to the host interface and log all traffic that goes over it. If, for any reason, you prefer two or more VMs on the same machine to communicate privately, hiding their data from both the host system and the user, bridged networking therefore is not an option.

I will assume that you are willing to accept the security risks that go with using this networking mode, as well as the additional risks of allowing file sharing within Windows. Choose the directory that you wish to share, right-click it, and select “Sharing and Security” vbox23.jpgYou may have to complete the Network setup wizard to enable File and Printer Sharing. vbox24.jpgCheck “Share this folder on the network”, the click “OK”. It may ask you to reboot your (virtual) machine again. vbox25.jpgWhen you restart the computer, you will notice that your directory is listed as a shared directory, and it will be accessible as a Samba share on your Linux host machine, as well as all other machines on your network. Enjoy! vbox26.jpg

Installing BricxCC to the Windows Guest

  1. Install the USB Drivers for the Lego NXT Brick from your NXT-G Disc.
  2. Download the Latest version of BricxCC.
  3. Shut down your Windows.
  4. Add your Username to the Lego & VirtualBox Groups via Menu / Adminstration / Users & Groups “.
  5. Connect your Lego NXT Brick to your PC via USB.
  6. From the VirtualBox Control Panel select the settings for your Windows Guest and go to the USB Tab.
  7. Add the Lego NXT Brick to the Guest. The NXT Brick will Show up as “Unknown device 03EB:6124 [0110]” or similar. By right-clicking the NXT Filter you can edit the name to something like “NXT Brick #01”for ease of recognition. Note that Lego’s Vendor ID is 0694.
  8. Now start your Windows Virtual Machine (Guest)

If all went to plan, you can now access your NXT Brick from Linux. You can also add NXT-G and LabView to your Windows Virtual Machine as well if you wish like show below!

Lego NXT Software Suite Running On Linux:

NXT Laser Target Sensor Test



Do NOT follow this link or you will be banned from the site!
error: Content is protected !!