User Tools

Site Tools


nxt_automation_implementation

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
nxt_automation_implementation [2024/11/23 18:47] hhameednxt_automation_implementation [2024/11/25 13:55] (current) hhameed
Line 10: Line 10:
  
 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: 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> <fs x-large>**Parts List and Sources**</fs>
Line 110: Line 114:
 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.  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 124: Line 199:
 {{:time_constant_demo.png?400|}}{{::time_constant_demo2.png?400|}} {{:time_constant_demo.png?400|}}{{::time_constant_demo2.png?400|}}
 {{:time_constant_demo3.png?400|}}{{:time_constant_demo4.png?400|}} {{:time_constant_demo3.png?400|}}{{:time_constant_demo4.png?400|}}
 +
 +<fs x-large>**Final Words**</fs>
  
  
nxt_automation_implementation.1732416448.txt.gz · Last modified: by hhameed