The HTWay programs, both the NXT-G and the NXC versions, are designed so that the control code and the balance code are separate. This makes it possible to modify the control code without effecting the balance code. Want to add different sensors such as a Light sensor for line tracking or Ultrasonic for obstacle avoidance, then you can do that in the control code without having to worry about the details needed to make the robot balance. This post will show you and example of how that can be done by creating a remote controlled Bluetooth version using a second NXT for the Bluetooth controller. This second NXT features active controls using the NXT motors that will self-center when you let go of them.
If you look at the NXT-G program for the HTWay it will see that it looks like this:
In the top part of the program you see the initialization and the balance code. This starts of with getting the wheel size from the user, then getting the initial gyro offset, and right before it starts to balance it plays the beep sequence. The loop here is the main balance code, you can leave that alone.
Below the main balance code you see another loop that starts of with the IR Receiver sensor block. This loop runs at the same time as the balance code and communicates with the balance code through two global variables: controlDrive and controlSteer. In this loop the IR Receiver block is used to read the values for the red and blue sub-channels for IR channel 1. Then these red and blue values are used to set the controlDrive and the controlSteer. Basically, the sum of the red and blue, times a constant, set the controlDrive and the difference of the red and blue set the controlSteer. If you want to make the robot do something else, all you have to do is replace this loop with your own code that sets the controlDrive and controlSteer variables.
The variables controlDrive and controlSteer and in the units degrees per second. For controlDrive, this is the sum of the motors and for controlSteer it is the difference between the motors (left-right). For example, if you set the controlDrive to 400 and then let it run for one second, then the sum of the two motors should change by 400. If you set controlSteer to 400 and let it run for one second, then the difference of left-right will change by 400. In other words, the robot will turn to the right. These values can both be set independently so the robot can drive and turn at the same time.
The first Bluetooth controlled HTWay
A young robot builder in Norway, Christian I., created a Bluetooth version of the HTWay. He used a second NXT with four touch sensors for his controller and programmed it to send BT messages to the HTWay which would then use the messages to drive the robot via the controlDrive and controlSteer variables. What to go, Christian! Nice job! Here are some photos he sent me as well as the youtube video:
|Top View, left for steering, right for driving||Bottom View, bottom of beam presses touch sensors.|
Here is the video of Christian’s BT HTWay:
Official HiTechnic HTWay – Bluetooth Edition
Inspired by Christian’s fine work, here at the HiTechnic workshop we have developed an official HiTechnic version of the Bluetooth HTWay. It also uses a second NXT for the BT controller but instead of buttons, it uses two NXT motors. The controller can be built from either a LEGO Mindstorms 1.0 or 2.0 set, just note that the part colors and tires are different. The controller is programmed so that the motors are self-centering and have limited travel. If you push them all the way forwards, then they will send a 100 for that side, all the way back is -100. If you let go of the wheel, it will go back to the zero position.
Update(July 28, 2010):The NXT-G Program in the download above has been updated to use the new 2.0 Gyro sensor block available for download from the Downloads page. If you are using the original 1.0 Gyro sensor block, you must update it to the new 2.0 block for use with this program.
Currently the programs are only available in NXT-G for LEGO Mindstorms 2.0. Also included in the programs Zip file are the compiled .rxe files. If you don’t have LEGO Mindstorms 2.0, you can still download these files to the NXTs from the LEGO Mindstorms 1.0 software. Your NXTs will still need to have a firmware associated with LEGO Mindstorms 2.0 (firmware version 1.26 or greater) which you can download from this LEGO downloads page.
- Build the HTWay exactly like the original version except without the IR Receiver sensor. If you want, you can replace the L-Beam that is supposed to hold the IR Receiver with a 3 Beam. Like this:
- Build the Remote from the instructions with the link above. The remote is buildable from either a NXT 1.0 or 2.0 set though the program is designed for LEGO Mindstorms 2.0.
- If you have LEGO Mindstorms 2.0, I recommend that you create a new profile for the HTWay as there are a lot of MyBlocks that are specific to this project. In the new profile; open the two .rbtx files. Download the HTWayG-BT to the HTWay NXT and download HTWayG-BTRem to the controller NXT.
If you have LEGO Mindstorms 1.0, you can download the .rxe files directly to the NXT. From the LEGO Mindstorms software; create or open a program and then click on the upper-left button in the group of 5 buttons on the lower-right corner of the window. Click on the Memory tab and then click Download. Download the HTWayG-BT.rxe to the HTWay NXT and HTWayG-BTRem.rxe to the controller NXT.
- Before you run the programs, you need to establish the Bluetooth connection between the NXT. First of all, turn on Bluetooth on both NXTs by selecting Bluetooth on the main NXT menu and then selecting On/Off, then On. From the Controller NXT, you now need to initiate the communication by first selecting Bluetooth on the main NXT menu, and then select Search. The NXT will now search for Bluetooth devices around. This may take a while. When it is done searching, select the NXT of the HTWay. Then select Connection 1. You will now need to accept the pass-key on both NXTs.
- You are now ready to run the programs. Like the original NXT, the HTWay will first ask you to select the wheel size. After the wheels size is selected, lay the robot down flat in order to give it a chance to get an initial Gyro offset value. As soon as the robot starts to beep, hold it up vertically as balanced as possible. On the long beep, let go.
That’s it! You should now be ready to drive the HTWay.
Here you can see this version in action:
Just like Chistian’s version, only the control loop of the HTWay was modified. The Balance code is exactly like the original version. If you want to make the HTWay do different things, you can try changing the control code on your own to see what you can make it do. Try adding other sensors such as the Light sensor or Ultrasonic sensors.