nxt_automation_implementation
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
nxt_automation_implementation [2024/11/23 18:31] – hhameed | nxt_automation_implementation [2024/11/25 13:55] (current) – hhameed | ||
---|---|---|---|
Line 11: | Line 11: | ||
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> | <fs x-large> | ||
- | + | \\ | |
+ | *LEGO NXT | ||
+ | *[[http:// | ||
+ | *[[https:// | ||
+ | *[[https:// | ||
+ | *[[https:// | ||
<fs x-large> | <fs x-large> | ||
Line 108: | Line 114: | ||
Data may be passed from external sensors/ | Data may be passed from external sensors/ | ||
- | 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=" | ||
+ | // | ||
+ | |||
+ | 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, | ||
+ | pinMode(yleft, | ||
+ | pinMode(button, | ||
+ | analogWrite(yright, | ||
+ | analogWrite(yleft, | ||
+ | digitalWrite(button, | ||
+ | } | ||
+ | |||
+ | void loop() { | ||
+ | |||
+ | //when communication is not actively occurring, use last defined speed value | ||
+ | while(!Serial.available()){ | ||
+ | analogWrite(yright, | ||
+ | analogWrite(yleft, | ||
+ | } | ||
+ | |||
+ | message = Serial.readString().toInt(); | ||
+ | |||
+ | //case statements with edge cases | ||
+ | //if the " | ||
+ | //if the " | ||
+ | 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, | ||
+ | delay(250); | ||
+ | digitalWrite(button, | ||
+ | delay(250); | ||
+ | digitalWrite(button, | ||
+ | delay(250); | ||
+ | digitalWrite(button, | ||
+ | } | ||
+ | |||
+ | //message will print to terminal of external ide | ||
+ | Serial.println(message); | ||
+ | Serial.println(speedRight); | ||
+ | Serial.println(speedLeft); | ||
+ | } | ||
+ | |||
+ | } | ||
+ | </ | ||
**<fs x-large> | **<fs x-large> | ||
Line 122: | Line 199: | ||
{{: | {{: | ||
{{: | {{: | ||
+ | |||
+ | <fs x-large> | ||
nxt_automation_implementation.1732415469.txt.gz · Last modified: by hhameed