-
Notifications
You must be signed in to change notification settings - Fork 0
commit cbs panel code and merge latest old arm code #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
126 changes: 126 additions & 0 deletions
126
arduino_firmware/arm_joystick_panel/arm_joystick_panel.ino
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
|
|
||
|
|
||
| //Joystick right Pins | ||
| const int xAxisPin2 = A1; | ||
| const int yAxisPin2 = A0; | ||
| const int zAxisPin2 = A2; | ||
| const int buttonPin2 = 2; | ||
|
|
||
| //Joystick left Pins | ||
| const int xAxisPin1 = A4; | ||
| const int yAxisPin1 = A3; | ||
| const int zAxisPin1 = A5; | ||
| const int buttonPin1 = 3; | ||
|
|
||
| const int centerValue = 512; // Analog midpoint | ||
| const int deadZoneMin = 440; // Lower dead zone threshold | ||
| const int deadZoneMax = 583; // Upper dead zone threshold | ||
| const int minAnalog = 0; // Min Analog value | ||
| const int maxAnalog = 1023; // Max Analog value | ||
|
|
||
| //#define minAnalogZ 0 | ||
| //#define maxAnalogZ 600 | ||
|
|
||
| #define RATE_HZ 100 | ||
|
|
||
| //#define TEST //Uncomment to print raw values instead of adj values | ||
|
|
||
| long interval_ms = 99; | ||
| long last_time = 0; | ||
| long current_time = 0; | ||
| void setup() { | ||
| pinMode(buttonPin1, INPUT_PULLUP); | ||
| pinMode(buttonPin2, INPUT_PULLUP); | ||
| Serial.begin(19200); | ||
| interval_ms = 1/RATE_HZ * 1000; //interval in ms | ||
|
|
||
| } | ||
|
|
||
| void loop() { | ||
| current_time = millis(); | ||
| if(current_time - last_time > interval_ms){ | ||
| last_time = millis(); | ||
|
|
||
|
|
||
| //Read raw values | ||
| int rawX1 = analogRead(xAxisPin1); | ||
| int rawY1 = analogRead(yAxisPin1); | ||
| int rawZ1 = analogRead(zAxisPin1); | ||
| int buttonState1 = digitalRead(buttonPin1); | ||
|
|
||
| int rawX2 = analogRead(xAxisPin2); | ||
| int rawY2 = analogRead(yAxisPin2); | ||
| int rawZ2 = analogRead(zAxisPin2); | ||
| int buttonState2 = digitalRead(buttonPin2); | ||
|
|
||
| #ifdef TEST | ||
| Serial.print("TESING: "); | ||
| // Print joystick values with adjusted dead zone | ||
| Serial.print(rawX1); | ||
| Serial.print(","); | ||
| Serial.print(rawY1); | ||
| Serial.print(","); | ||
| Serial.print(rawZ1); | ||
| Serial.print(","); | ||
| Serial.print(buttonState1 == LOW ? "1" : "0"); | ||
|
|
||
| Serial.print(","); | ||
| Serial.print(rawX2); | ||
| Serial.print(","); | ||
| Serial.print(rawY2); | ||
| Serial.print(","); | ||
| Serial.print(rawZ2); | ||
| Serial.print(","); | ||
| Serial.print(buttonState2 == LOW ? "1" : "0"); | ||
| Serial.println(")"); | ||
|
|
||
| #else | ||
| int adjX1 = mapJoystickToPercentage(rawX1); | ||
| int adjY1 = mapJoystickToPercentage(rawY1); | ||
| int adjZ1 = mapJoystickToPercentage(rawZ1); | ||
|
|
||
| int adjX2 = mapJoystickToPercentage(rawX2); | ||
| int adjY2 = mapJoystickToPercentage(rawY2); | ||
| int adjZ2 = mapJoystickToPercentage(rawZ2); | ||
|
|
||
|
|
||
| // Print joystick values with adjusted dead zone | ||
| Serial.print("$arm_joy_panel("); | ||
| Serial.print(adjX1, DEC); | ||
| Serial.print(","); | ||
| Serial.print(adjY1); | ||
| Serial.print(","); | ||
| Serial.print(adjZ1); | ||
| Serial.print(","); | ||
| Serial.print(buttonState1 == LOW ? "1" : "0"); | ||
|
|
||
| Serial.print(","); | ||
| Serial.print(adjX2, DEC); | ||
| Serial.print(","); | ||
| Serial.print(adjY2); | ||
| Serial.print(","); | ||
| Serial.print(adjZ2); | ||
| Serial.print(","); | ||
| Serial.print(buttonState2 == LOW ? "1" : "0"); | ||
| Serial.println(")"); | ||
|
|
||
| #endif | ||
| // Function to map values to 1-100 percentage with deadzone | ||
| }else{ | ||
| delay(10); //delay not really needed but eh | ||
| } | ||
|
|
||
| } | ||
|
|
||
| // Function to scale joystick input to 1-100 with deadzone | ||
| int mapJoystickToPercentage(int rawValue) { | ||
| if (rawValue >= deadZoneMin && rawValue <= deadZoneMax) { | ||
| return 50; // Keep the dead zone at 50% | ||
| } | ||
| else if (rawValue < deadZoneMin) { | ||
| return map(rawValue, minAnalog, deadZoneMin - 1, 1, 49); // Scale below dead zone | ||
| } | ||
| else { | ||
| return map(rawValue, deadZoneMax + 1, maxAnalog, 51, 100); // Scale above dead zone | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| //MCU for general left panel | ||
|
|
||
| #define BAUDRATE 9600 | ||
| #define TX_RATE_HZ 30 | ||
|
|
||
|
|
||
| #define SW_T00_PIN 2 | ||
| //T0 is just one flat switch currently | ||
|
|
||
| #define SW_T10_PIN 3 | ||
| #define SW_T11_PIN 4 | ||
|
|
||
| #define SW_T20_PIN 5 | ||
| #define SW_T21_PIN 6 | ||
|
|
||
| #define BT_T30_PIN 7 | ||
| #define BT_T31_PIN 8 | ||
|
|
||
| #define BT_T40_PIN 9 | ||
| #define BT_T41_PIN 10 | ||
|
|
||
| #define BT_T50_PIN 11 //This Button Needs replacement | ||
| #define BT_T51_PIN 12 | ||
|
|
||
|
|
||
| long interval_ms = 99; | ||
| long last_time = 0; | ||
| long current_time = 0; | ||
|
|
||
| void setup() { | ||
| pinMode(SW_T00_PIN, INPUT_PULLUP); | ||
| pinMode(SW_T10_PIN, INPUT_PULLUP); | ||
| pinMode(SW_T11_PIN, INPUT_PULLUP); | ||
| pinMode(SW_T20_PIN, INPUT_PULLUP); | ||
| pinMode(SW_T21_PIN, INPUT_PULLUP); | ||
| pinMode(BT_T30_PIN, INPUT_PULLUP); | ||
| pinMode(BT_T31_PIN, INPUT_PULLUP); | ||
| pinMode(BT_T40_PIN, INPUT_PULLUP); | ||
| pinMode(BT_T41_PIN, INPUT_PULLUP); | ||
| pinMode(BT_T50_PIN, INPUT_PULLUP); | ||
| pinMode(BT_T51_PIN, INPUT_PULLUP); | ||
| interval_ms = 1000/TX_RATE_HZ; | ||
|
|
||
| Serial.begin(BAUDRATE); | ||
|
|
||
| } | ||
|
|
||
| void loop() { | ||
| current_time = millis(); | ||
| if(current_time - last_time > interval_ms){ | ||
| last_time = millis(); | ||
| //might wanna use arrays but ehh our main problem is gonna be not mixing up the inputs | ||
| int SW_T00 = digitalRead(SW_T00_PIN) == LOW ? 1 : 0; | ||
| int SW_T10 = digitalRead(SW_T10_PIN) == LOW ? 1 : 0; | ||
| int SW_T11 = digitalRead(SW_T11_PIN) == LOW ? 0 : 1; | ||
| int SW_T20 = digitalRead(SW_T20_PIN) == LOW ? 1 : 0; | ||
| int SW_T21 = digitalRead(SW_T21_PIN) == LOW ? 1 : 0;; | ||
| int BT_T30 = digitalRead(BT_T30_PIN); | ||
| int BT_T31 = digitalRead(BT_T31_PIN); | ||
| int BT_T40 = digitalRead(BT_T40_PIN); | ||
| int BT_T41 = digitalRead(BT_T41_PIN); | ||
| int BT_T50 = digitalRead(BT_T50_PIN); | ||
| int BT_T51 = digitalRead(BT_T51_PIN); | ||
|
|
||
|
|
||
| // int SW_T30 = digitalRead(SW_T00_PIN); | ||
|
|
||
| String outmsg = "$gen_left_A("; | ||
| outmsg = outmsg + SW_T00 + ","; // for some reason += messes up the string | ||
| outmsg = outmsg + SW_T10 + ","; | ||
| outmsg = outmsg + SW_T11 + ","; | ||
| outmsg = outmsg + SW_T20 + ","; | ||
| outmsg = outmsg + SW_T21 + ","; | ||
| outmsg = outmsg + BT_T30 + ","; | ||
| outmsg = outmsg + BT_T31 + ","; | ||
| outmsg = outmsg + BT_T40 + ","; | ||
| outmsg = outmsg + BT_T41 + ","; | ||
| outmsg = outmsg + BT_T50 + ","; | ||
| outmsg = outmsg + BT_T51; | ||
|
|
||
| // outmsg += SW_T10 + ""; | ||
| outmsg = outmsg + ")"; | ||
| Serial.println(outmsg); | ||
|
|
||
| } | ||
| delay(1); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,4 @@ | ||
| echo LOADING HEX | ||
| teensy_loader_cli -w -v --mcu TEENSY41 build/zephyr/zephyr.hex | ||
| sudo teensy_loader_cli -w -v --mcu TEENSY41 build/zephyr/zephyr.hex | ||
| sleep 1.0 | ||
| teensy_loader_cli -w -v --mcu TEENSY41 build/zephyr/zephyr.hex | ||
|
|
||
| sudo teensy_loader_cli -w -v --mcu TEENSY41 build/zephyr/zephyr.hex |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is the num axes increase intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup, one of the axes is used for the end effector