Adds basic robot control node structure
Introduces a basic structure for the robot control node. This includes: - A central brain component that manages the robot's logic. - A state management system using a singleton to ensure thread-safe access to shared data. - A simple main loop that can be started and stopped. - Initial CMakeLists.txt and gitignore configurations. This provides a foundation for implementing robot control logic.
This commit is contained in:
parent
fd274fef0b
commit
14336c70d5
8 changed files with 168 additions and 1 deletions
7
src/.gitignore
vendored
Normal file
7
src/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# Exclude all IntelliJ / JetBrains project settings everywhere
|
||||
**/.idea/
|
||||
**/.idea/**
|
||||
|
||||
# Also ignore IntelliJ module files anywhere
|
||||
*.iml
|
||||
*.iws
|
||||
2
.gitignore → src/RobotNode/.gitignore
vendored
2
.gitignore → src/RobotNode/.gitignore
vendored
|
|
@ -38,4 +38,4 @@
|
|||
*.app
|
||||
|
||||
# debug information files
|
||||
*.dwo
|
||||
*.dwo
|
||||
10
src/RobotNode/CMakeLists.txt
Normal file
10
src/RobotNode/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
cmake_minimum_required(VERSION 4.1)
|
||||
project(Dixon)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
|
||||
add_executable(Dixon main.cpp
|
||||
DixonNodeState.cpp
|
||||
DixonNodeState.h
|
||||
DixonBrain.cpp
|
||||
DixonBrain.h)
|
||||
50
src/RobotNode/DixonBrain.cpp
Normal file
50
src/RobotNode/DixonBrain.cpp
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
#include "DixonBrain.h"
|
||||
#include <iostream>
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
DixonBrain::DixonBrain()
|
||||
: state_(DixonNodeState::instance())
|
||||
{
|
||||
std::cout << "DixonBrain initialised\n";
|
||||
}
|
||||
|
||||
DixonBrain::~DixonBrain()
|
||||
{
|
||||
stop();
|
||||
std::cout << "DixonBrain destroyed\n";
|
||||
}
|
||||
|
||||
void DixonBrain::start()
|
||||
{
|
||||
if (state_.isBrainRunning())
|
||||
return;
|
||||
|
||||
state_.setBrainRunning(true);
|
||||
|
||||
loopThread_ = std::thread(&DixonBrain::runLoop, this);
|
||||
|
||||
std::cout << "DixonBrain started\n";
|
||||
}
|
||||
|
||||
void DixonBrain::stop()
|
||||
{
|
||||
if (!state_.isBrainRunning())
|
||||
return;
|
||||
|
||||
state_.setBrainRunning(false);
|
||||
|
||||
if (loopThread_.joinable())
|
||||
loopThread_.join();
|
||||
|
||||
std::cout << "DixonBrain stopped\n";
|
||||
}
|
||||
|
||||
void DixonBrain::runLoop()
|
||||
{
|
||||
while (state_.isBrainRunning())
|
||||
{
|
||||
// TODO: main control logic
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
}
|
||||
}
|
||||
19
src/RobotNode/DixonBrain.h
Normal file
19
src/RobotNode/DixonBrain.h
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#pragma once
|
||||
#include "DixonNodeState.h"
|
||||
#include <thread>
|
||||
|
||||
class DixonBrain
|
||||
{
|
||||
public:
|
||||
DixonBrain();
|
||||
~DixonBrain();
|
||||
|
||||
void start();
|
||||
void stop();
|
||||
|
||||
private:
|
||||
void runLoop();
|
||||
|
||||
DixonNodeState& state_;
|
||||
std::thread loopThread_;
|
||||
};
|
||||
31
src/RobotNode/DixonNodeState.cpp
Normal file
31
src/RobotNode/DixonNodeState.cpp
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
#include "DixonNodeState.h"
|
||||
|
||||
DixonNodeState& DixonNodeState::instance()
|
||||
{
|
||||
static DixonNodeState instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
void DixonNodeState::setConnected(bool value)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
connected_ = value;
|
||||
}
|
||||
|
||||
bool DixonNodeState::isConnected() const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
return connected_;
|
||||
}
|
||||
|
||||
void DixonNodeState::setBrainRunning(bool value)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
brainRunning_ = value;
|
||||
}
|
||||
|
||||
bool DixonNodeState::isBrainRunning() const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
return brainRunning_;
|
||||
}
|
||||
27
src/RobotNode/DixonNodeState.h
Normal file
27
src/RobotNode/DixonNodeState.h
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
#pragma once
|
||||
#include <mutex>
|
||||
|
||||
class DixonNodeState
|
||||
{
|
||||
public:
|
||||
static DixonNodeState& instance();
|
||||
|
||||
void setConnected(bool value);
|
||||
bool isConnected() const;
|
||||
|
||||
void setBrainRunning(bool value);
|
||||
bool isBrainRunning() const;
|
||||
|
||||
DixonNodeState(const DixonNodeState&) = delete;
|
||||
DixonNodeState& operator=(const DixonNodeState&) = delete;
|
||||
DixonNodeState(DixonNodeState&&) = delete;
|
||||
DixonNodeState& operator=(DixonNodeState&&) = delete;
|
||||
|
||||
private:
|
||||
DixonNodeState() = default;
|
||||
~DixonNodeState() = default;
|
||||
|
||||
mutable std::mutex mutex_;
|
||||
bool connected_ = false;
|
||||
bool brainRunning_ = false;
|
||||
};
|
||||
23
src/RobotNode/main.cpp
Normal file
23
src/RobotNode/main.cpp
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
#include <iostream>
|
||||
#include "DixonBrain.h"
|
||||
#include "DixonNodeState.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cout << "Starting Dixon...\n";
|
||||
|
||||
// Create the brain controller
|
||||
DixonBrain brain;
|
||||
|
||||
// Start the brain's control loop
|
||||
brain.start();
|
||||
|
||||
std::cout << "Dixon is running. Press Enter to stop...\n";
|
||||
std::cin.get();
|
||||
|
||||
// Stop the brain cleanly
|
||||
brain.stop();
|
||||
|
||||
std::cout << "Dixon shut down.\n";
|
||||
return 0;
|
||||
}
|
||||
Loading…
Reference in a new issue