User Tools

Site Tools


nxt_automation_implementation

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
nxt_automation_implementation [2024/11/23 15:12] – created hhameednxt_automation_implementation [2024/11/25 13:55] (current) hhameed
Line 8: Line 8:
  
 <fs x-large>**Motivation and Audience**</fs> <fs x-large>**Motivation and Audience**</fs>
 +
 +The following tutorial has the motivation of documenting a means of wireless communication to a LEGO NXT module for the purpose of automation with a concentration on mobile robots. This tutorial assumes:
 +
 +  *BricxCC (Bricx Command Center) application setup
 +  *A basic understanding of C+ + (or general object oriented programming) 
 +  *Access to basic electrical components
 +
 +<fs x-large>**Parts List and Sources**</fs>
 +\\
 +  *LEGO NXT
 +  *[[http://www.mindsensors.com/ev3-and-nxt/29-sony-playstation-2-controller-interface-for-nxt-or-ev3|Sony Playstation 2 Controller Interface for NXT or EV3]]
 +  *[[https://www.brookaccessory.com/products/wingmanps2/index.html|Brook Wingman PS2]]
 +  *[[https://www.amazon.com/Logitech-Wireless-Nano-Receiver-Controller-Vibration/dp/B0041RR0TW?crid=3CA24GQASRV0V&dib=eyJ2IjoiMSJ9.Dpo5bvFXpJM3oQEDxlrPqmP4TRDfE4f8jZYDWWs0-zfZulhTOqzvztLb4u8wiH0X2r79i_fAdbJJ-opjjFkpMtZRn3qE7NZqZnjjiRi0fwl2wtIU_GJQY-lK4HgTHY4mfNYxzU-dBCF_oezbP9Mxws493giWpE0urfRldViaHgJXUCIHs3cmi9vqJ5Nh5iNuHJY29zX02arsvn9J8lZ_IkWjwVKOXrOLA_Y3buJ804s.3u1z3FfpARLiWgLPpZ2KYgU6wYiFBY9DuZRkZyNyv9o&dib_tag=se&keywords=logitech%2Bf710&qid=1732413989&sprefix=logitech%2Bf%2Caps%2C144&sr=8-1&th=1|Logitech F710]]
 +  *[[https://www.amazon.com/AITRIP-ESP-WROOM-32-Development-Microcontroller-Integrated/dp/B0DF2YJSHN?dib=eyJ2IjoiMSJ9.J8fl2PuZsBFTQRqqz9O9mEmyW62U4_MpGp5foNJRgelWypISvNbbm65DtPAI9DzhViCB-x3lbNUDgupbZhCbxSDVwBBMwtxW_bgXqq9RyaIYGRk49OAKmhrFw_OKJdupc5G0u4I1gW7rkdlTuLLVACDXdiQFeOYfhHiV8AOgwIMv8TQfESYUxBC8714aMXMEUBk-H-kpkaVbEzudR8qffCO6tua6TvQSKq7ggfZuV88.U3LiQYOUYERI_is6ZEJiMS6iwDWPcd1npboG-NrB1Io&dib_tag=se&keywords=esp32%2Busbc&qid=1732415679&sr=8-3&th=1|ESP32 USB-C]]
  
 <fs x-large>**Software**</fs> <fs x-large>**Software**</fs>
 \\ \\
 +  *[[https://www.arduino.cc/en/software|Arduino IDE]]
 +  * [[https://pypi.org/project/pyserial/|Pyserial]]
   * [[http://sourceforge.net/projects/bricxcc/files/bricxcc|BricxCC]]   * [[http://sourceforge.net/projects/bricxcc/files/bricxcc|BricxCC]]
   * (If needed) [[https://www.daslhub.org/unlv/courses/me425-625/lesson-B-simpleMachines1-leversShaftsAndCranks/lab/NXT_USB_Driver_120.zip|NXT USB Driver]]   * (If needed) [[https://www.daslhub.org/unlv/courses/me425-625/lesson-B-simpleMachines1-leversShaftsAndCranks/lab/NXT_USB_Driver_120.zip|NXT USB Driver]]
   * (If needed) [[https://www.daslhub.org/unlv/courses/me425-625/lesson-B-simpleMachines1-leversShaftsAndCranks/lab/lms_arm_nbcnxc_131.rfw|NXC Firmware]]   * (If needed) [[https://www.daslhub.org/unlv/courses/me425-625/lesson-B-simpleMachines1-leversShaftsAndCranks/lab/lms_arm_nbcnxc_131.rfw|NXC Firmware]]
 +
  
 <fs x-large>**Setup**</fs> <fs x-large>**Setup**</fs>
Line 19: Line 36:
 **Step 1 [Teleoperation Verification]** **Step 1 [Teleoperation Verification]**
  
-Follow the instructions within the “LEGO NXT Teleoperation Introduction” tutorial and verify the NXT module can drive motors using either the Playstation 2 Controller or a controller compatible with the Brooke Translation peripheral (operation detailed in following section). Verify the mobile robot platform built prior to the tutorial’s remainder. +Follow the instructions within the “[[lego_nxt_teleoperation_introduction|LEGO NXT Teleoperation Introduction]]” tutorial and verify the NXT module can drive motors using either the Playstation 2 Controller or a controller compatible with the Brooke Translation peripheral (operation detailed in following section). Verify the mobile robot platform built prior to the tutorial’s remainder. 
  
 **Step 2 [Brooke Wingman PS2 Setup]** **Step 2 [Brooke Wingman PS2 Setup]**
Line 25: Line 42:
 The Brooke peripheral requires provision of a 5V voltage source, which the NXT module in many cases is incapable of providing. In order to remedy this, utilize a buck converter/step down converter to translate a battery of choice’s voltage (12V LiPo demonstrated) to 5V delivered through an attached breakout micro USB cable.  The Brooke peripheral requires provision of a 5V voltage source, which the NXT module in many cases is incapable of providing. In order to remedy this, utilize a buck converter/step down converter to translate a battery of choice’s voltage (12V LiPo demonstrated) to 5V delivered through an attached breakout micro USB cable. 
  
-Verify operation of the Brook peripheral on a functioning NXT module by powering on the module, connecting the 5V power supply if seen necessary, and using a compatible Logitech F710 wireless controller (if not immediately available, the linked page lists all compatible controllers)+{{::brook_buck.jpg?400|}} 
 + 
 +Verify operation of the Brook peripheral on a functioning NXT module by powering on the module, connecting the 5V power supply if seen necessary, and using a compatible Logitech F710 wireless controller (if not immediately available, the [[https://www.brookaccessory.com/products/wingmanps2/index.html|linked page]] lists all compatible controllers) 
 + 
 +{{:brook_setup.jpg?400|}}
  
 **Step 3 [Communication]** **Step 3 [Communication]**
  
-Disassemble the Logitech F710 controller. Observe the wireless transmitter soldered onto the mainboard, with connections tied to input(s) as seen below and further documented here (required reading). This transmitter may be used connected to the mainboard (pictured) or desoldered and connected to power via the specified pins for a more permanent connection. +Disassemble the Logitech F710 controller. Observe the wireless transmitter soldered onto the mainboard, with connections tied to input(s) as seen below and further documented [[https://hackaday.io/project/189333-logitech-f710-gamepad-bluetooth-module|here]] (__required reading__). This transmitter may be used connected to the mainboard (pictured) or desoldered and connected to power via the specified pins for a more permanent connection.  
 + 
 +{{::basic_dac_connections.png?400|}}
  
 It is important to note that each connection handles a voltage of up to roughly 2.1V, with analog inputs accepting any value between 0V-2.1V, so as to not provide excess current. To verify, utilize a multimeter to measure input voltage relative to ground for any given pin. Measurement is additionally recommended in the case of analog input to determine voltage output for desired value(s). Power and voltage may be provided through use of a microcontroller (ESP32 used).  It is important to note that each connection handles a voltage of up to roughly 2.1V, with analog inputs accepting any value between 0V-2.1V, so as to not provide excess current. To verify, utilize a multimeter to measure input voltage relative to ground for any given pin. Measurement is additionally recommended in the case of analog input to determine voltage output for desired value(s). Power and voltage may be provided through use of a microcontroller (ESP32 used). 
Line 39: Line 62:
 A very simple DAC can be made from a Resistor-Capacitor (RC) circuit network. The resistor and capacitor capacitor values are 1kΩ and 100μF respectively. As shown in the figure below, source voltage is connected in series with the resistor in turn connected in series with the capacitor, with the positive end of the capacitor being the analog output voltage.  A very simple DAC can be made from a Resistor-Capacitor (RC) circuit network. The resistor and capacitor capacitor values are 1kΩ and 100μF respectively. As shown in the figure below, source voltage is connected in series with the resistor in turn connected in series with the capacitor, with the positive end of the capacitor being the analog output voltage. 
  
 +{{:basic_dac.png?400|}}
  
 Use the described circuit for any analog input, using a multimeter on the leg of the capacitor relative to ground to verify constant voltage output between 3.3V-0V as output by a given PWM pin on your microcontroller. Read the respective DAC theory section to learn about how you can reconfigure or iterate upon this circuit.  Use the described circuit for any analog input, using a multimeter on the leg of the capacitor relative to ground to verify constant voltage output between 3.3V-0V as output by a given PWM pin on your microcontroller. Read the respective DAC theory section to learn about how you can reconfigure or iterate upon this circuit. 
Line 89: Line 112:
 </code> </code>
  
-Data may be passed from external sensors/devices such as cameras or even motion capture to inform the NXT module’s movement. In order to communicate with the microcontroller, the given device(s) are ideally able to run through a script containing some form of serial communication. Used in this case is the Python pyserial library. Following installation, it is recommended that this tutorial be followed to verify communication between a python script and the script running on the microcontroller. Using this as a base, we may create a more robust stimulus-based movement. +Data may be passed from external sensors/devices such as cameras or even motion capture to inform the NXT module’s movement. In order to communicate with the microcontroller, the given device(s) are ideally able to run through a script containing some form of serial communication. Used in this case is the Python [[https://pypi.org/project/pyserial/|pyserial]] library. Following installation, it is recommended that [[https://projecthub.arduino.cc/ansh2919/serial-communication-between-python-and-arduino-663756|this tutorial]] be followed to verify communication between a python script and the script running on the microcontroller. Using this as a base, we may create a more robust stimulus-based movement. 
  
-The following code shows an arduino ino file with serial communication used to inform motor speed for a mobile robot NXT. +The following code shows an arduino ino file with serial communication used to inform motor speed for a mobile robot NXT
 + 
 +<code c [enable_line_numbers="true"] mobile_starter.ino> 
 +//instantiates pins & speed(s) 
 + 
 +const int yright = 16; 
 +const int yleft = 17; 
 + 
 +const int button = 18; 
 + 
 +int message; 
 +int stop = 75; 
 +int speedRight = stop;  
 +int speedLeft = stop; 
 + 
 +//Setting up pins to be output & setting analog joystick value to neutral 
 +//Starting serial for script communication 
 +void setup() { 
 +  Serial.begin(115200); 
 +  Serial.setTimeout(1); 
 +  pinMode(yright, OUTPUT); 
 +  pinMode(yleft, OUTPUT); 
 +  pinMode(button, OUTPUT); 
 +  analogWrite(yright, 90); 
 +  analogWrite(yleft, 90); 
 +  digitalWrite(button, LOW); 
 +
 + 
 +void loop() { 
 + 
 +//when communication is not actively occurring, use last defined speed value 
 +  while(!Serial.available()){ 
 +    analogWrite(yright, speedRight); 
 +    analogWrite(yleft, speedLeft); 
 +  } 
 + 
 +  message = Serial.readString().toInt(); 
 + 
 +//case statements with edge cases 
 +//if the "message" value is within the defined voltage range, it will be mapped accordingly 
 +//if the "message" value outputs 300, stops robot and performs action 
 +if(message != 0){ 
 +   
 +  if(message > 0 && message < 200){ 
 +    speedRight = stop + message; 
 +    speedLeft = stop - message; 
 +  }else if(message < 0){ 
 +    speedRight = stop + message; 
 +    speedLeft = stop - message; 
 +  }else if (message = 200){ 
 +    speedRight = 125; 
 +    speedLeft = speedRight; 
 +  }else if (message = 300){ 
 +    speedRight = stop; 
 +    speedLeft = stop; 
 +    digitalWrite(button, HIGH); 
 +    delay(250); 
 +    digitalWrite(button, LOW); 
 +    delay(250); 
 +    digitalWrite(button, HIGH); 
 +    delay(250); 
 +    digitalWrite(button, LOW); 
 +  } 
 +   
 +//message will print to terminal of external ide 
 +  Serial.println(message); 
 +  Serial.println(speedRight); 
 +  Serial.println(speedLeft); 
 +
 + 
 +
 +</code>
  
 **<fs x-large>Theory</fs>** **<fs x-large>Theory</fs>**
Line 102: Line 196:
  
 Given the provided configuration, heightening either the resistor or capacitor value will lead to a greater degree of latency and more accurate analog voltage, and lowering these values will see these effects inverted. More complex capacitor networks may be utilized to remedy these issues, though are beyond the scope of this tutorial. It is recommended that external research be done regarding such networks prior to implementation.  Given the provided configuration, heightening either the resistor or capacitor value will lead to a greater degree of latency and more accurate analog voltage, and lowering these values will see these effects inverted. More complex capacitor networks may be utilized to remedy these issues, though are beyond the scope of this tutorial. It is recommended that external research be done regarding such networks prior to implementation. 
 +
 +{{:time_constant_demo.png?400|}}{{::time_constant_demo2.png?400|}}
 +{{:time_constant_demo3.png?400|}}{{:time_constant_demo4.png?400|}}
 +
 +<fs x-large>**Final Words**</fs>
  
  
nxt_automation_implementation.1732403559.txt.gz · Last modified: by hhameed