Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions module/onboarding/Accumulator/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Build our NUClear module
nuclear_module()
25 changes: 25 additions & 0 deletions module/onboarding/Accumulator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Accumulator

## Description

Performs iterative summation of integers from k=1 to n=10 without using loops. Receives iteration messages, adds the current value k to the running sum, and either continues the iteration or emits the final result

## Usage

Configuration from `Accumulator.yaml` (for log level settings)

## Consumes

- `message::onboarding::ComputeIteration`

## Emits

- `message::onboarding::ComputeIteration`
- `message::onboarding::FinalAnswer`

## Dependencies

- `message::onboarding::ComputeIteration` - Message type for iteration state
- `message::onboarding::FinalAnswer` - Message type for final result
- `onboarding::Starter` - Module that initiates the first ComputeIteration message
- `onboarding::Judge` - Module that validates the final answer
2 changes: 2 additions & 0 deletions module/onboarding/Accumulator/data/config/Accumulator.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Controls the minimum log level that NUClear log will display
log_level: INFO
55 changes: 55 additions & 0 deletions module/onboarding/Accumulator/src/Accumulator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include "Accumulator.hpp"

#include "extension/Configuration.hpp"
#include "message/onboarding/ComputeIteration.hpp"
#include "message/onboarding/FinalAnswer.hpp"


namespace module::onboarding {

using extension::Configuration;

Accumulator::Accumulator(std::unique_ptr<NUClear::Environment> environment) : Reactor(std::move(environment)) {

using message::onboarding::ComputeIteration;
using message::onboarding::FinalAnswer;

on<Configuration>("Accumulator.yaml").then([this](const Configuration& config) {
// Use configuration here from file Accumulator.yaml
this->log_level = config["log_level"].as<NUClear::LogLevel>();
});
on<Trigger<ComputeIteration>>().then([this](const ComputeIteration& compute_msg) {
// Get current values
uint32_t k = compute_msg.k;
uint32_t current_sum = compute_msg.sum;

// Add k to the sum
uint32_t new_sum = current_sum + k;

log<INFO>("Iteration k=", k, ": sum was", current_sum, ", adding", k, ", new sum is", new_sum);

// Maximum number of iterations (n=10)
const uint32_t MAX_N = 10;

// Check if we need to continue or finish
if (k < MAX_N) {
// Continue iterating - emit next iteration
auto next_iteration = std::make_unique<ComputeIteration>();
next_iteration->k = k + 1; // Increment k
next_iteration->sum = new_sum; // Pass along the new sum

log<INFO>("Continuing: emitting ComputeIteration with k=", (k + 1), ", sum=", new_sum);
emit(next_iteration);
}
else {
// We've reached k=10, time to finish
auto final_answer = std::make_unique<FinalAnswer>();
final_answer->result = new_sum;

log<INFO>("Computation complete! Final answer:", new_sum);
emit(final_answer);
}
});
}

} // namespace module::onboarding
21 changes: 21 additions & 0 deletions module/onboarding/Accumulator/src/Accumulator.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef MODULE_ONBOARDING_ACCUMULATOR_HPP
#define MODULE_ONBOARDING_ACCUMULATOR_HPP

#include <nuclear>

namespace module::onboarding {

class Accumulator : public NUClear::Reactor {
private:
/// @brief Stores configuration values
struct Config {
} cfg;

public:
/// @brief Called by the powerplant to build and setup the Accumulator reactor.
explicit Accumulator(std::unique_ptr<NUClear::Environment> environment);
};

} // namespace module::onboarding

#endif // MODULE_ONBOARDING_ACCUMULATOR_HPP
2 changes: 2 additions & 0 deletions module/onboarding/Judge/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Build our NUClear module
nuclear_module()
24 changes: 24 additions & 0 deletions module/onboarding/Judge/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Judge

## Description

Compares Accumulator output to expected result

## Usage

Configuration from `Judge.yaml` (for log level settings)

## Consumes

- `message::onboarding::FinalAnswer` - The computed sum result from the Accumulator module

## Emits

- `message::skill::Say` (as Task) - Text-to-speech command with head nodding when answer is

## Dependencies

- `extension::behaviour::BehaviourReactor` - Provides Task emission capabilities
- `message::onboarding::FinalAnswer` - Message type for receiving computation results
- `message::skill::Say` - Message type for robot speech and nodding
- `skill::Say` module - Must be included in role file to process Say messages
2 changes: 2 additions & 0 deletions module/onboarding/Judge/data/config/Judge.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Controls the minimum log level that NUClear log will display
log_level: INFO
14 changes: 14 additions & 0 deletions module/onboarding/Judge/data/scripts/NodYes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Head nodding sequence - nod down and back up
frames:
- duration: 0.5
servos:
HEAD_PITCH:
position: -0.4 # Look down (negative pitch)
gain: 30
torque: 100
- duration: 0.5
servos:
HEAD_PITCH:
position: 0.0 # Return to neutral
gain: 30
torque: 100
42 changes: 42 additions & 0 deletions module/onboarding/Judge/src/Judge.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include "Judge.hpp"

#include "extension/Configuration.hpp"

#include "message/actuation/Limbs.hpp"
#include "message/onboarding/FinalAnswer.hpp"

#include "utility/skill/Script.hpp"

namespace module::onboarding {

using extension::Configuration;
using message::actuation::HeadSequence;
using message::onboarding::FinalAnswer;
using utility::skill::load_script;

Judge::Judge(std::unique_ptr<NUClear::Environment> environment) : BehaviourReactor(std::move(environment)) {


on<Configuration>("Judge.yaml").then([this](const Configuration& config) {
// Use configuration here from file Judge.yaml
this->log_level = config["log_level"].as<NUClear::LogLevel>();
});
on<Trigger<FinalAnswer>>().then([this](const FinalAnswer& answer) {
// The correct answer for sum from k=1 to n=10 is 55
const uint32_t EXPECTED_ANSWER = 55;

log<INFO>("Received final answer:", answer.result);

if (answer.result == EXPECTED_ANSWER) {
log<INFO>("Answer is correct! Making robot nod yes.");

// Load and emit head nod sequence
emit<Task>(load_script<HeadSequence>("NodYes.yaml"));
}
else {
log<WARN>("Answer is incorrect. Expected:", EXPECTED_ANSWER, "Got:", answer.result);
}
});
}

} // namespace module::onboarding
25 changes: 25 additions & 0 deletions module/onboarding/Judge/src/Judge.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef MODULE_ONBOARDING_JUDGE_HPP
#define MODULE_ONBOARDING_JUDGE_HPP

#include <nuclear>
#include "extension/Behaviour.hpp"



namespace module::onboarding {

class Judge : public ::extension::behaviour::BehaviourReactor {

private:
/// @brief Stores configuration values
struct Config {
} cfg;

public:
/// @brief Called by the powerplant to build and setup the Judge reactor.
explicit Judge(std::unique_ptr<NUClear::Environment> environment);
};

} // namespace module::onboarding

#endif // MODULE_ONBOARDING_JUDGE_HPP
2 changes: 2 additions & 0 deletions module/onboarding/Ping/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Build our NUClear module
nuclear_module()
22 changes: 22 additions & 0 deletions module/onboarding/Ping/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Ping

## Description

Demonstration module that responds to Pong messages. Increments and logs a counter value with each ping.

## Usage

Configuration from `Ping.yaml`

## Consumes

- `message::onboarding::Pong`

## Emits

- `message::onboarding::Ping` with incremented counter

## Dependencies

- `message::onboarding::Ping`
- `message::onboarding::Pong`
2 changes: 2 additions & 0 deletions module/onboarding/Ping/data/config/Ping.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Controls the minimum log level that NUClear log will display
log_level: INFO
34 changes: 34 additions & 0 deletions module/onboarding/Ping/src/Ping.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "Ping.hpp"

#include "extension/Configuration.hpp"

#include "message/onboarding/Ping.hpp"
#include "message/onboarding/Pong.hpp"

namespace module::onboarding {

using extension::Configuration;

Ping::Ping(std::unique_ptr<NUClear::Environment> environment) : Reactor(std::move(environment)) {

using message::onboarding::Ping;
using message::onboarding::Pong;

on<Configuration>("Ping.yaml").then([this](const Configuration& config) {
// Use configuration here from file Ping.yaml
this->log_level = config["log_level"].as<NUClear::LogLevel>();
});

on<Startup>().then([this] {
// Vibe
});

on<Trigger<Pong>>().then([this](const Pong& pong_msg) {
auto ping_msg = std::make_unique<Ping>();
ping_msg->count = ++counter;// TODO: Assign counter value.
log<INFO>("Ping");
emit(ping_msg);
});
}

} // namespace module::onboarding
23 changes: 23 additions & 0 deletions module/onboarding/Ping/src/Ping.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef MODULE_ONBOARDING_PING_HPP
#define MODULE_ONBOARDING_PING_HPP

#include <nuclear>

namespace module::onboarding {

class Ping : public NUClear::Reactor {
private:
/// @brief Stores configuration values
struct Config {
} cfg;

public:
/// @brief Called by the powerplant to build and setup the Ping reactor.
explicit Ping(std::unique_ptr<NUClear::Environment> environment);
uint32_t counter = 0;

};

} // namespace module::onboarding

#endif // MODULE_ONBOARDING_PING_HPP
2 changes: 2 additions & 0 deletions module/onboarding/Pong/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Build our NUClear module
nuclear_module()
16 changes: 16 additions & 0 deletions module/onboarding/Pong/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Pong

## Description


## Usage


## Consumes


## Emits


## Dependencies

2 changes: 2 additions & 0 deletions module/onboarding/Pong/data/config/Pong.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Controls the minimum log level that NUClear log will display
log_level: INFO
40 changes: 40 additions & 0 deletions module/onboarding/Pong/src/Pong.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include "Pong.hpp"

#include "extension/Configuration.hpp"

#include "message/onboarding/Ping.hpp"
#include "message/onboarding/Pong.hpp"

namespace module::onboarding {

using extension::Configuration;

Pong::Pong(std::unique_ptr<NUClear::Environment> environment) : Reactor(std::move(environment)) {

using message::onboarding::Ping;
using message::onboarding::Pong;

on<Configuration>("Pong.yaml").then([this](const Configuration& config) {
// Use configuration here from file Pong.yaml
this->log_level = config["log_level"].as<NUClear::LogLevel>();
});

on<Startup>().then([this] {
// Start the ping pong chain
auto pong_msg = std::make_unique<Pong>();
emit(pong_msg);
});

on<Trigger<Ping>>().then([this](const Ping& ping_msg) {
//Log a INFO level message with the text "Pong"
auto pong_msg = std::make_unique<Pong>();
log<INFO>("Pong", ping_msg.count);

//Emit a Pong message
emit(pong_msg);
//change after pull test
//another change
});
}

} // namespace module::onboarding
21 changes: 21 additions & 0 deletions module/onboarding/Pong/src/Pong.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef MODULE_ONBOARDING_PONG_HPP
#define MODULE_ONBOARDING_PONG_HPP

#include <nuclear>

namespace module::onboarding {

class Pong : public NUClear::Reactor {
private:
/// @brief Stores configuration values
struct Config {
} cfg;

public:
/// @brief Called by the powerplant to build and setup the Pong reactor.
explicit Pong(std::unique_ptr<NUClear::Environment> environment);
};

} // namespace module::onboarding

#endif // MODULE_ONBOARDING_PONG_HPP
Loading
Loading