-
Notifications
You must be signed in to change notification settings - Fork 2
Testing phase of Ledi Firmware #176
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
Open
Gobind-Kailey
wants to merge
4
commits into
main
Choose a base branch
from
ledi_firmware
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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 |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| #include "led.h" | ||
|
|
||
| // Initialize the variables here | ||
| rcl_subscription_t led_sub; | ||
| std_msgs__msg__Int32 led_msg; | ||
| rclc_executor_t led_executor; | ||
|
|
||
| volatile LED_States current_led_state = LED_STATE_OFF; | ||
| unsigned long last_flash_time = 0; | ||
| bool flash_state = false; | ||
|
|
||
| void LED_setup() { | ||
| pinMode(PIN_LED_RED, OUTPUT); | ||
| pinMode(PIN_LED_GREEN, OUTPUT); | ||
| pinMode(PIN_LED_BLUE, OUTPUT); | ||
| LED_SM(); | ||
|
Gobind-Kailey marked this conversation as resolved.
|
||
| } | ||
|
|
||
| bool led_setup_subscription(rcl_node_t *node, rclc_support_t *support, rcl_allocator_t *allocator) { | ||
| rcl_ret_t rc = rclc_subscription_init_default( | ||
| &led_sub, | ||
| node, | ||
| ROSIDL_GET_MSG_TYPE_SUPPORT(std_msgs, msg, Int32), | ||
| "rover_led_state" | ||
| ); | ||
| if (rc != RCL_RET_OK) { return false; } | ||
|
|
||
| rc = rclc_executor_init(&led_executor, &support->context, 1, allocator); | ||
| if (rc != RCL_RET_OK) { return false; } | ||
|
|
||
| rc = rclc_executor_add_subscription( | ||
| &led_executor, | ||
| &led_sub, | ||
| &led_msg, | ||
| &led_subscription_callback, | ||
| ON_NEW_DATA | ||
| ); | ||
| return rc == RCL_RET_OK; | ||
| } | ||
| // Subscriber Callback | ||
| void led_subscription_callback(const void * msgin) { | ||
| const std_msgs__msg__Int32 * msg = (const std_msgs__msg__Int32 *)msgin; | ||
| current_led_state = static_cast<LED_States>(msg->data); | ||
| } | ||
|
|
||
| // State Machine | ||
| void LED_SM() { | ||
| switch (current_led_state) { | ||
| case LED_STATE_AUTO: // Solid Red | ||
| analogWrite(PIN_LED_RED, 255); | ||
| analogWrite(PIN_LED_GREEN, 0); | ||
| analogWrite(PIN_LED_BLUE, 0); | ||
| break; | ||
|
|
||
| case LED_STATE_TELEOP: // Solid Blue | ||
| analogWrite(PIN_LED_RED, 0); | ||
| analogWrite(PIN_LED_GREEN, 0); | ||
| analogWrite(PIN_LED_BLUE, 255); | ||
| break; | ||
|
|
||
| case LED_STATE_ARRIVED: // Flashing Green | ||
| analogWrite(PIN_LED_RED, 0); | ||
| analogWrite(PIN_LED_BLUE, 0); | ||
| if (millis() - last_flash_time > 500) { | ||
| last_flash_time = millis(); | ||
| flash_state = !flash_state; | ||
| analogWrite(PIN_LED_GREEN, flash_state ? 255 : 0); | ||
| } | ||
| break; | ||
|
|
||
| default: // Off / Idle | ||
| analogWrite(PIN_LED_RED, 0); | ||
| analogWrite(PIN_LED_GREEN, 0); | ||
| analogWrite(PIN_LED_BLUE, 0); | ||
| break; | ||
| } | ||
| } | ||
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,29 @@ | ||
| #ifndef LED_H | ||
| #define LED_H | ||
|
|
||
| #include <Arduino.h> | ||
| #include <micro_ros_arduino.h> | ||
| #include <rcl/rcl.h> | ||
| #include <rclc/rclc.h> | ||
| #include <rclc/executor.h> // <--- This explicitly fixes the 'does not name a type' error! | ||
| #include <std_msgs/msg/int32.h> | ||
| #include "enums.h" // <--- Kept your awesome enum update | ||
|
|
||
| // --- LED INDICATOR PINS --- | ||
| #define PIN_LED_RED 2 | ||
| #define PIN_LED_GREEN 3 | ||
| #define PIN_LED_BLUE 4 | ||
|
|
||
| // --- GLOBAL VARIABLES --- | ||
| extern rcl_subscription_t led_sub; | ||
| extern std_msgs__msg__Int32 led_msg; | ||
| extern rclc_executor_t led_executor; | ||
| extern volatile LED_States current_led_state; // Kept your enum type | ||
|
|
||
| // --- FUNCTION PROTOTYPES --- | ||
| void LED_setup(); | ||
| bool led_setup_subscription(rcl_node_t *node, rclc_support_t *support, rcl_allocator_t *allocator); | ||
| void led_subscription_callback(const void * msgin); | ||
| void LED_SM(); | ||
|
|
||
| #endif |
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
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
ros_ws/src/robot_description/config/joint_names_robot_description.yaml
This file was deleted.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
I know this is just for testing, but eventually we will need to change how we control the LEDs (may require a more precise method for controlling PWM, like DMA?)
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.
Yeah the basic pin setup is just to verify the micro-Ros state machine is working. I agree, we are going to require a DMA driver for the LEDs. I think I should finish testing this state machine first and then move on to creating that.