keyboard interface
meowmechanic from Hong Kong  [2 posts]
16 year
Hi  Roborealm experts,

I just tried the roborealm with my Lego NXT using the 'keyboard interface', the purpose is to control the NXT running forward when pressed [cursor up] and backward when pressed [cursor down]. From the NXT interface module, it seems that the motor should rotate in different directions when greater or less than 128. However, I got the following problems:

1) [cursor up] did not work, only [cursor down] works.
2) the VBScript do not initialize the LEFT_MOTOR and RIGHT_MOTOR values to 128, so the NXT runs immediately after 'start', even no keys are pressed.

I have attached the simple program for reference, could you pls advise what I have missed in the setting, thanks a lot!
Lego NXT Keyboard
16 year

you almost had it. Two problems.

First was that you had the "clear on release" checkbox set in the keyboard interface. This will remove the variable after the key has been released effectively setting the variable to 0. Unchecking this checkbox will keep the current value until changed. Thus it will continue to move forward until told to move backwards. To stop use another key (like space) to set the variables to 128.

Second, in your VBScript you needed to surrounding the two setVariable statements with a conditional that only executes once ... i.e. when the variables do not have any values at the very beginning of the program. If you do not then the variables will always be overwritten with the 128 values.

To debug use the Statements->Watch_Variables and you should see the left_motor and right_motor values change according to the keypresses. Once you've confirmed this you can attach on the motors to those variables.

We've included the fixed script ... try it out and let us know if that improves things ... remember that the robot will not stop, so you may want to add in another key to stop the movement.

meowmechanic from Hong Kong  [2 posts] 16 year
Thanks STeven, it works!

This forum thread has been closed due to inactivity (more than 4 months) or number of replies (more than 50 messages). Please start a New Post and enter a new forum thread with the appropriate title.

 New Post   Forum Index