Skip to content

Feature: LED Colour Controller Package#7

Open
Vicente-III-H wants to merge 24 commits into
mainfrom
feature/led-controller
Open

Feature: LED Colour Controller Package#7
Vicente-III-H wants to merge 24 commits into
mainfrom
feature/led-controller

Conversation

@Vicente-III-H

Copy link
Copy Markdown
Collaborator

This package contains a lifecycle node that publishes RGB values to the /led_colour topic and changes behaviour depending on the node's current lifecycle state:

  • on_configure() - Initializes node's publisher and timer, and publishes the colour yellow once to /led_colour
  • on_activate() - Publishes a random colour every second to the /led_colour
  • on_deactivate() - Publishes the colour red once to /led_colour
  • on_cleanup() and on_shutdown() - Cleans up node's publisher and timer

Instructions

Build and Run Package

To build the package, run:

colcon build --packages-select led_controller

Then, source the workspace:

source install/setup.bash

Then, run the LED Colour Controller:

ros2 run led_controller led_colour_controller

Node Commands

To change the state of the node, run the commands below:

ros2 lifecycle set led_colour_controller_node configure
ros2 lifecycle set led_colour_controller_node activate
ros2 lifecycle set led_colour_controller_node deactivate
ros2 lifecycle set led_colour_controller_node cleanup
ros2 lifecycle set led_colour_controller_node shutdown

To view the output of the node, run:

ros2 topic echo /led_colour

@billylin609

Copy link
Copy Markdown
Collaborator

can you add the setup instruction into README file under src/led_controller. Git action is complaining can you also take a look and we want the git action to build properly.

Comment thread src/led_controller/msg/RGB.msg Outdated
@@ -0,0 +1,3 @@
uint8 red_val
uint8 green_val
uint8 blue_val No newline at end of file

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://docs.ros.org/en/noetic/api/std_msgs/html/msg/ColorRGBA.html

This is the ros official message for RGB i think for compatibility we should use the standard message.

@@ -0,0 +1,99 @@
#include <chrono>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need header file for clean interface

timer_ = this->create_wall_timer(1s, std::bind(&LedColourControllerNode::publish_random_colour, this));
timer_->cancel(); // Start with the timer stopped

publish_colour(255, 255, 0); // Turn to yellow after configuring

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

color should not be magic numbers

colour->green_val = g;
colour->blue_val = b;

RCLCPP_INFO(this->get_logger(), "Publishing colour: R(%d), G(%d), B(%d)", colour->red_val, colour->green_val, colour->blue_val);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

two line for clarity

}

private:
void publish_colour(std::uint8_t r, std::uint8_t g, std::uint8_t b) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to return operation success or fail for debugging

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants