Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
fe9d1c8
Create template package
Vicente-III-H Jun 10, 2026
bfacc2d
Add logic for LED controller publisher
Vicente-III-H Jun 14, 2026
95c1c22
Fix dependencies
Vicente-III-H Jun 14, 2026
0dde467
Add main to run node
Vicente-III-H Jun 14, 2026
76a5e7c
Fix timer behaviour
Vicente-III-H Jun 14, 2026
41b3bf0
Add alternate CMake line for adding custom interface
Vicente-III-H Jun 14, 2026
2298676
Replace custom RGB msg with ROS2 standard RGBA msg
Vicente-III-H Jun 24, 2026
3bc0780
Add README for package
Vicente-III-H Jun 24, 2026
6a47962
Change formatting for clarity
Vicente-III-H Jun 24, 2026
175b0a1
Moved LED functionality to separate cpp file
Vicente-III-H Jun 24, 2026
ab68dac
Add functionality to change LED colour based on keyword
Vicente-III-H Jun 24, 2026
7d8ee5c
Add more LED colour keywords
Vicente-III-H Jun 25, 2026
12e84a1
Fix formatting
Vicente-III-H Jun 25, 2026
56fcb7d
Fix formatting
Vicente-III-H Jun 25, 2026
c898a8d
Add return values to LED class methods for debugging
Vicente-III-H Jun 25, 2026
b99363b
Change formatting and fix set_colour logger arguments
Vicente-III-H Jun 25, 2026
79b0a7b
Merge branch 'main' into feature/led-controller
Vicente-III-H Jun 25, 2026
d70581b
Remove unused msg files
Vicente-III-H Jun 25, 2026
4929ac1
Merge branch 'feature/led-controller' of github.com:uwrobotics/Sparky…
Vicente-III-H Jun 25, 2026
30e4360
Merge branch 'main' into feature/led-controller
Vicente-III-H Jul 3, 2026
1d7bff2
Add LED Lifecycle flowchart
Vicente-III-H Jul 3, 2026
87a7b6c
Fix mermaid diagram appearance
Vicente-III-H Jul 3, 2026
ea79207
Add on_cleanup behaviour to LED flowchart
Vicente-III-H Jul 3, 2026
059b085
Update README.md for clarity
Vicente-III-H Jul 3, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions src/led_controller/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
cmake_minimum_required(VERSION 3.8)
project(led_controller)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rosidl_default_generators REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclcpp_lifecycle REQUIRED)
# uncomment the following section in order to fill in
# further dependencies manually.
# find_package(<dependency> REQUIRED)

set(msg_files
"msg/RGB.msg"
)

rosidl_generate_interfaces(${PROJECT_NAME}
${msg_files}
)

ament_export_dependencies(rosidl_default_runtime)

add_executable(led_colour_controller src/led_colour_controller.cpp)
ament_target_dependencies(led_colour_controller
rclcpp
rclcpp_lifecycle
)

rosidl_get_typesupport_target(cpp_typesupport_target
${PROJECT_NAME} rosidl_typesupport_cpp)

target_link_libraries(led_colour_controller "${cpp_typesupport_target}")

# Replacing the rosidl_get_typesupport_target and target_link_libraries lines above with the one below also works
# target_link_libraries(led_colour_controller ${PROJECT_NAME}__rosidl_typesupport_cpp)

install(TARGETS led_colour_controller
DESTINATION lib/${PROJECT_NAME})

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
# the following line skips the linter which checks for copyrights
# comment the line when a copyright and license is added to all source files
set(ament_cmake_copyright_FOUND TRUE)
# the following line skips cpplint (only works in a git repo)
# comment the line when this package is in a git repo and when
# a copyright and license is added to all source files
set(ament_cmake_cpplint_FOUND TRUE)
ament_lint_auto_find_test_dependencies()
endif()

ament_package()
17 changes: 17 additions & 0 deletions src/led_controller/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
3 changes: 3 additions & 0 deletions src/led_controller/msg/RGB.msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
uint8 red_val
uint8 green_val
uint8 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.

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.

26 changes: 26 additions & 0 deletions src/led_controller/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>led_controller</name>
<version>0.0.0</version>
<description>TODO: Package description</description>
<maintainer email="dev3@todo.todo">dev3</maintainer>
<license>MIT</license>

<depend>rclcpp</depend>
<depend>rclcpp_lifecycle</depend>

<buildtool_depend>ament_cmake</buildtool_depend>
<buildtool_depend>rosidl_default_generators</buildtool_depend>

<exec_depend>rosidl_default_runtime</exec_depend>

<member_of_group>rosidl_interface_packages</member_of_group>

<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>

<export>
<build_type>ament_cmake</build_type>
</export>
</package>
99 changes: 99 additions & 0 deletions src/led_controller/src/led_colour_controller.cpp
Original file line number Diff line number Diff line change
@@ -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

#include <cstdlib>

#include "rclcpp/rclcpp.hpp"
#include "rclcpp_lifecycle/lifecycle_node.hpp"
#include "led_controller/msg/rgb.hpp"

using namespace std::chrono_literals;

using LifecycleCallback = rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn;

class LedColourControllerNode : public rclcpp_lifecycle::LifecycleNode {
public:
explicit LedColourControllerNode(const std::string &name) : rclcpp_lifecycle::LifecycleNode(name) {}

LifecycleCallback on_configure(const rclcpp_lifecycle::State &) {
RCLCPP_INFO(this->get_logger(), "Configuring LED Colour Controller");

pub_ = this->create_publisher<led_controller::msg::RGB>("led_colour", 10);

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


return LifecycleCallback::SUCCESS;
}

LifecycleCallback on_activate(const rclcpp_lifecycle::State &state) {
RCLCPP_INFO(this->get_logger(), "Activating LED Colour Controller");

LifecycleNode::on_activate(state);

timer_->reset(); // Resume timer on activate

return LifecycleCallback::SUCCESS;
}

LifecycleCallback on_deactivate(const rclcpp_lifecycle::State &state) {
RCLCPP_INFO(this->get_logger(), "Deactivating LED Colour Controller");

LifecycleNode::on_deactivate(state);

timer_->cancel();

publish_colour(255, 0, 0); // Turn to red on deactivate

return LifecycleCallback::SUCCESS;
}

LifecycleCallback on_cleanup(const rclcpp_lifecycle::State &state) {
RCLCPP_INFO(this->get_logger(), "Cleaning up LED Colour Controller");

timer_.reset();
pub_.reset();

return LifecycleCallback::SUCCESS;
}

LifecycleCallback on_shutdown(const rclcpp_lifecycle::State &state) {
RCLCPP_INFO(this->get_logger(), "Shuting down LED Colour Controller");

timer_.reset();
pub_.reset();

return LifecycleCallback::SUCCESS;
}

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

auto colour = std::make_unique<led_controller::msg::RGB>();
colour->red_val = r;
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

pub_->publish(std::move(colour));
};
void publish_random_colour() {
publish_colour(rand() % 256, rand() % 256, rand() % 256);
};

// Using regular publisher to allow colour changing in inactive state
std::shared_ptr<rclcpp::Publisher<led_controller::msg::RGB>> pub_;
std::shared_ptr<rclcpp::TimerBase> timer_;
};

int main(int argc, char * argv[]) {
rclcpp::init(argc, argv);

rclcpp::executors::SingleThreadedExecutor executor;
auto node = std::make_shared<LedColourControllerNode>("led_colour_controller_node");

executor.add_node(node->get_node_base_interface());
executor.spin();

rclcpp::shutdown();
return 0;
}
Loading