Common libraries to be shared across embedded board source code
The embedded common library can be used in ROS & C++ to expose the functionality of Parsing and Composing can messages. Follow these steps to ensure that the libraries are included, compilied and are usable in VSCode.
- Add
include_directories(${CMAKE_SOURCE_DIR}/../../hardware/QUTMS_Embedded_Common/Inc)
to the nodesCmakeLists.txt
- For each required library, add
add_compile_definitions(QUTMS_CAN_[XXX])
where[XXX]
could beVCU
orAMS
etc to theCMakeLists.txt
. - For each required library, add
${CMAKE_SOURCE_DIR}/../../hardware/QUTMS_Embedded_Common/Src/[XXX].c
to your nodesCMakeLists.txt
. - Add
SET_SOURCE_FILES_PROPERTIES(${SOURCES} PROPERTIES LANGUAGE CXX)
soCXX
is used forC
extension files. - For each required library, add
QUTMS_CAN_[XXX]
to thedefines
field in thec_cpp_properties.json
config.
Example:
CMakeLists.txt
:
add_compile_definitions(QUTMS_CAN_VCU)
include_directories(${CMAKE_SOURCE_DIR}/../../hardware/QUTMS_Embedded_Common/Inc)
set (SOURCES
${CMAKE_SOURCE_DIR}/../../hardware/QUTMS_Embedded_Common/Src/CAN_VCU.c
)
SET_SOURCE_FILES_PROPERTIES(${SOURCES} PROPERTIES LANGUAGE CXX )
c_cpp_properties
:
"defines": [
"QUTMS_CAN_VCU"
],
node.cpp
:
#include "CAN_VCU.h"
#include "QUTMS_can.h"
- cd to
Project/Software/Core/
- Run
git submodule add https://github.com/QUT-Motorsport/QUTMS_Embedded_Common.git ./Common/
- Go int STM32CubeIde, Right click on the Project, Properties->C/C++ General->Paths and Symbols->Includes->Add
- Add Core/Common/Inc
- Clean & Rebuild
- cd to the repository
- Run
git submodule update --init --recursive
to initalise the submodules. - Run
git submodule update --recursive
orgit submodule foreach git pull origin master
to update the submodules.
To update to the latest version of the submodule in a parent repo:
- Run
git submodule update --recursive
- Have a beer, you did a good job.
- CMSISv2 RTOS Wrapper
- FSM.h
- FSM.c
- xx_States.h -> (To be written by user)
- xx_States.c -> (To be written by user)
Main
#include "FSM.h"
// Create a new FSM
fsm_t *fsm = fsm_new(&userDefinedInitialState);
// Set its log user defined log method, prototype is:
// void log(char* msg, size_t len);
fsm_setLogFunction(fsm, &logFn);
// Reset the FSM to a given state, will keep log function.
fsm_reset(fsm, &userDefinedInitialState);
// Your main loop
for(;;)
{
// Iterate the FSM
fsm_iterate(fsm);
}
State Header
#include "fsm.h"
// Create the state
state_t stateName;
// Enter, Iterate and Exit functions
void stateName_enter(fsm_t *fsm);
void stateName_iterate(fsm_t *fsm);
void stateName_exit(fsm_t *fsm);
State C
#include "stateHeader.h"
stateName = {&stateName_enter, &stateName_iterate, &stateName_exit, "stateName_s"};
void stateName_enter(fsm_t *fsm)
{
// Do code here, maybe change the state, like this?
fsm_changeState(fsm, &stateName2); // FSM pointer is passed everywhere.
}
If you need any advice on implementation of the FSM, ask Tom or check the AMS repo and the following files:
- FSM.h
- FSM.c
- main.h
- main.c
- AMS_FSM_States.h
- AMS_FSM_States.c