User Tools

Site Tools


lego_nxt_teleoperation_introduction

LEGO NXT Teleoperation Introduction
Author: Hashim H., Email: hameeh1@unlv.nevada.edu
Date: Last modified on [08/04/24]
Keywords: NXT, Teleoperation

Motivation and Audience

The following tutorial has the motivation of education on teleoperation using the Lego NXT module using readily available peripherals. This tutorial assumes:

*BricxCC (Bricx Command Center) application setup
*A basic understanding of C++ (or general object oriented programming)

Parts List and Sources

Part Name/Description Vendor Vendor Number or URL Price QTY
Lego NXT Kit Lego N/A N/A 1
Sony Playstation 2 Controller Interface for NXT or EV3 mindsensors.com http://www.mindsensors.com/ev3-and-nxt/29-sony-playstation-2-controller-interface-for-nxt-or-ev3 $42.95 1

Software

Setup

Step 1

Ensure your NXT module is sufficiently powered with either a battery pack or six AA batteries and connect to your device hosting the BricxCC IDE via USB. It is suggested to have the USB-A end plugged in prior to the USB-B to avoid connectivity issues.

Step 2

After seating two AAA batteries in the PS2 controller, connect the PS2 controller receiver module (with the receiver connected) to the NXT on the port labeled “1” (*connecting via a letter port may cause damage to the receiver and/or module*), ensuring the connection is valid by actuating buttons on the controller as this should cause a green LED to activate on the receiver.

Step 3

Download the required NXC library and sample/demo on the controller product page listed above or here. It is highly recommended that you compile and run the included sample to understand how to interface with the library.

Programming

In any file using the PS2 library, always import the library file and define/instantiate related variables such as the module address (for communication), sensor port, and controller stat/pressure variables.

The following is an example of moving a motor connected to port A based (pictured above) on the input of the PS2 controller’s left stick:

Library Download

basic_movement.nxc
  1. //imports the library
  2. #include "PSP-Nx-v4-lib.nxc"
  3.  
  4. //Defines receiver module address for I2C communication
  5. #define ADDR 0x02
  6.  
  7. //Defines input port as 1 (change as seen fit)
  8. const byte SensorPort = IN_1;
  9.  
  10. task main(){
  11.  
  12. //Initializes variables associated with button/stick inputs
  13. psp currState;
  14. psp pressures;
  15.  
  16. //Initializes PS2 controller connection
  17. PSPV4_Init(SensorPort, ADDR);
  18.  
  19. while(true) {
  20.  
  21. //continuously reads controller button and stick values
  22. PSPV4_ReadButtonStateWithPressure(SensorPort, ADDR, currState, pressures);
  23.  
  24. //Puts current state of left joystick ranged [-100:100] into integer variable
  25. int leftStick = currState.l_j_y;
  26.  
  27. //Move motor forward based on leftStick value
  28. OnFwd(OUT_A, leftStick);
  29. }
  30. }

Given verification of user input given controller output, robotic teleoperation can be performed by building out the module with two motors in a manner similar to the domabot’s base (full instructions here) and determining output based on controller input.

Video Example

The following are examples of functions to use in your main loop for teleoperation (assuming motors connected to ports B and C [pictured above]):

drive_functions.nxc
  1. //Pass in the current state of a given joystick axis to the respective field(s)
  2. void tankDrive(int rightStickY, int leftStickY){
  3. OnFwd(OUT_B, leftStickY);
  4. OnFwd(OUT_C, rightStickY);
  5. }
  6.  
  7. void arcadeDrive(int rightStickX, int leftStickY){
  8. OnFwd(OUT_B, leftStickY+rightStickX);
  9. OnFwd(OUT_C, leftStickY-rightStickX);
  10. }

Considering cases where peripheral devices/appendages such as those below are utilized for teleoperation, it is helpful to create functions defining their movement.

The following are example functions that may be used and adjusted based on peripheral construction and purpose:

peripheral_functions.nxc
  1. //Rotates a motor forward and backward using the square button
  2. //Can be used in mechanisms such as a gripper/claw and projectile “kicker”
  3. //Fill variable “pressures.square” into respective field
  4.  
  5. //Boolean variables "closed" and "valid" are instantiated outside of function
  6. //as doing so within while loop resets the respective states each iteration
  7.  
  8. bool closed;
  9. bool valid;
  10.  
  11. void doUndo(int square){
  12.  
  13. if(square == 100 && !valid){
  14. valid = true;
  15. if(!closed){
  16. closed = true;
  17. RotateMotor(OUT_A, 75, -50);
  18. }else if(closed){
  19. closed = false;
  20. RotateMotor(OUT_A, 75, 50);
  21. }
  22. }else if(square == 0 && valid){
  23. valid = false;
  24. }
  25.  
  26. }
  27.  
  28. //Rotates a motor continuously CW or CCW if holding a particular shoulder button
  29. //Can be used in mechanisms such as a projectile “kicker”
  30. //Insert variables “pressures.r2” and “pressures.l2” into respective fields
  31.  
  32. void continuousRotation(int rightBumper, int leftBumper){
  33.  
  34. if(rightBumper == 100){
  35. OnFwd(OUT_A, 80);
  36. }else if(leftBumper == 100){
  37. OnRev(OUT_A, 80);
  38. }else{
  39. Off(OUT_A);
  40. }
  41.  
  42. }

Additional Build Instructions

The following are links to various mobile robot builds and mechanisms to be customized for your teleoperational purposes:

Castor Bot & Kick Mechanism
Elevated Castor Robot
Claw Mechanism
"Band-Powered"
Corrale & Kick

Final Words

The purpose of this tutorial has been to inform of the potential for teleoperation using the Lego NXT module, a user utilizing a remote controller to execute defined functions which while explained for mechanical use, may extent far beyond such.

Speculating future work derived from this tutorial includes that of autonomous NXT module operation with an emphasis on function execution in response to visual data.

lego_nxt_teleoperation_introduction.txt · Last modified: by hhameed