Skip to content

Commit

Permalink
Create modules skeleton for new app structure (#382)
Browse files Browse the repository at this point in the history
* Add modules and main.cpp skeleton

* Fix typos
  • Loading branch information
cindyli-13 authored Jun 22, 2021
1 parent 49f90e2 commit acd0b4d
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 6 deletions.
4 changes: 2 additions & 2 deletions rover-apps/arm/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
add_executable(arm)
target_sources(arm PRIVATE src/main.cpp)
target_include_directories(arm PUBLIC include)
target_sources(arm PRIVATE ../common/src/main.cpp)
target_include_directories(arm PUBLIC include ../common/include)
target_link_libraries(arm
PRIVATE
#Control
Expand Down
9 changes: 9 additions & 0 deletions rover-apps/arm/include/AppConfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

#include <vector>

#include "Module.h"

std::vector<Module*> gModules = {
// put modules here
};
Empty file.
10 changes: 10 additions & 0 deletions rover-apps/common/include/Module.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once

class Module {
public:
virtual void periodic_10s(void) = 0;
virtual void periodic_1s(void) = 0;
virtual void periodic_100ms(void) = 0;
virtual void periodic_10ms(void) = 0;
virtual void periodic_1ms(void) = 0;
};
59 changes: 59 additions & 0 deletions rover-apps/common/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include "AppConfig.h"
#include "mbed.h"

Thread periodic_10s_thread(osPriorityNormal1);
Thread periodic_1s_thread(osPriorityNormal2);
Thread periodic_100ms_thread(osPriorityNormal3);
Thread periodic_10ms_thread(osPriorityNormal4);
Thread periodic_1ms_thread(osPriorityNormal5);

void periodic_10s(void) {
auto startTime = Kernel::Clock::now();
for (Module* module : gModules) {
module->periodic_10s();
}
ThisThread::sleep_until(startTime + 10s);
}

void periodic_1s(void) {
auto startTime = Kernel::Clock::now();
for (Module* module : gModules) {
module->periodic_1s();
}
ThisThread::sleep_until(startTime + 1s);
}

void periodic_100ms(void) {
auto startTime = Kernel::Clock::now();
for (Module* module : gModules) {
module->periodic_100ms();
}
ThisThread::sleep_until(startTime + 100ms);
}

void periodic_10ms(void) {
auto startTime = Kernel::Clock::now();
for (Module* module : gModules) {
module->periodic_10ms();
}
ThisThread::sleep_until(startTime + 10ms);
}

void periodic_1ms(void) {
auto startTime = Kernel::Clock::now();
for (Module* module : gModules) {
module->periodic_1ms();
}
ThisThread::sleep_until(startTime + 1ms);
}

int main() {
periodic_1ms_thread.start(periodic_1ms);
periodic_10ms_thread.start(periodic_10ms);
periodic_100ms_thread.start(periodic_100ms);
periodic_1s_thread.start(periodic_1s);
periodic_10s_thread.start(periodic_10s);

while (true) {
}
}
4 changes: 2 additions & 2 deletions rover-apps/gimbal/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
add_executable(gimbal)
target_sources(gimbal PRIVATE src/main.cpp)
target_include_directories(gimbal PUBLIC include)
target_sources(gimbal PRIVATE ../common/src/main.cpp)
target_include_directories(gimbal PUBLIC include ../common/include)
target_link_libraries(gimbal
PRIVATE
#Control
Expand Down
9 changes: 9 additions & 0 deletions rover-apps/gimbal/include/AppConfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

#include <vector>

#include "Module.h"

std::vector<Module*> gModules = {
// put modules here
};
4 changes: 2 additions & 2 deletions rover-apps/science/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
add_executable(science)
target_sources(science PRIVATE src/main.cpp)
target_include_directories(science PUBLIC include)
target_sources(science PRIVATE ../common/src/main.cpp)
target_include_directories(science PUBLIC include ../common/include)
target_link_libraries(science
PRIVATE
#Control
Expand Down
9 changes: 9 additions & 0 deletions rover-apps/science/include/AppConfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

#include <vector>

#include "Module.h"

std::vector<Module*> gModules = {
// put modules here
};

0 comments on commit acd0b4d

Please sign in to comment.