12#ifndef RT_TASKS_GLOBALS_H
13#define RT_TASKS_GLOBALS_H
24 #define LIBRARY_EXPORT __declspec(dllexport)
25 #define LIBRARY_IMPORT __declspec(dllimport)
26#elif defined(__linux__)
27 #define LIBRARY_EXPORT __attribute__((visibility("default")))
28 #define LIBRARY_IMPORT __attribute__((visibility("default")))
30 #define LIBRARY_EXPORT
31 #define LIBRARY_IMPORT
34#define NAME(name) name
35#define CONCAT(left, right) left ## right
36#define RSI_TASK(name) \
37 void CONCAT(name, Core)(RSI::RapidCode::RealTimeTasks::GlobalData*); \
38 extern "C" LIBRARY_EXPORT int32_t NAME(name)(RSI::RapidCode::RealTimeTasks::GlobalData* data, char* buffer, const uint32_t size) { return CallFunction(CONCAT(name, Core), data, buffer, size); } \
39 void CONCAT(name, Core)(RSI::RapidCode::RealTimeTasks::GlobalData* data)
41template<
typename FunctionType>
42int32_t CallFunction(FunctionType&& func, RSI::RapidCode::RealTimeTasks::GlobalData* data,
char* buffer,
const uint32_t size)
49 catch(
const std::exception& error)
52 std::snprintf(buffer, size,
"%s", error.what());
57 std::snprintf(buffer, size,
"Unknown error occurred in task.");
67namespace RealTimeTasks
80 GlobalData() { std::memset(
this, 0,
sizeof(*
this)); }
81 GlobalData(GlobalData&& other) { std::memcpy(
this, &other,
sizeof(*
this)); }
84 RSI_GLOBAL(int64_t, counter);
87 RSI_GLOBAL(
double, average);
88 RSI_GLOBAL(
double, targetPosition);
91inline constexpr GlobalMetadataMap<RSI::RapidCode::RealTimeTasks::GlobalMaxSize> GlobalMetadata(
93 REGISTER_GLOBAL(counter),
94 REGISTER_GLOBAL(average),
95 REGISTER_GLOBAL(targetPosition),
101 LIBRARY_EXPORT int32_t GlobalMemberOffsetGet(
const char*
const name)
103 return GlobalMetadata[name].offset;
105 static_assert(std::is_same<
decltype(&GlobalMemberOffsetGet), GlobalMemberOffsetGetter>::value,
"GlobalMemberOffsetGet function signature does not match GlobalMemberOffsetGetter type.");
107 LIBRARY_EXPORT int32_t GlobalNamesFill(
const char* names[], int32_t capacity)
110 for (; index < GlobalMetadata.Size() && index < capacity; ++index)
112 names[index] = GlobalMetadata[index].key;
116 static_assert(std::is_same<
decltype(&GlobalNamesFill), GlobalNamesGetter>::value,
"GlobalNamesGet function signature does not match GlobalNamesGetter type.");
118 LIBRARY_EXPORT std::int32_t GlobalMemberTypeGet(
const char*
const name)
120 return static_cast<std::int32_t
>(GlobalMetadata[name].type);
122 static_assert(std::is_same<
decltype(&GlobalMemberTypeGet), GlobalMemberTypeGetter>::value,
"GlobalMemberTypeGet function signature does not match GlobalMemberTypeGetter type.");
125static_assert(
sizeof(GlobalData) <= RSI::RapidCode::RealTimeTasks::GlobalMaxSize,
"GlobalData struct is too large.");
134 LIBRARY_IMPORT
RSI::RapidCode::Axis* AxisGet(
const int32_t axisIndex,
char* errorBuffer,
const uint32_t errorBufferSize);
135 LIBRARY_IMPORT RSI::RapidCode::RapidCodeNetworkNode* NetworkNodeGet(
const int32_t index,
char* errorBuffer,
const uint32_t errorBufferSize);
136 LIBRARY_IMPORT
RSI::RapidCode::MultiAxis* MultiAxisGet(
const int32_t index,
char* errorBuffer,
const uint32_t errorBufferSize);
139template<
typename FunctionType,
typename ... Args>
140auto RTObjectGet(FunctionType&& func, Args&& ... args)
142 char errorBuffer[256] = {};
143 auto object = std::forward<FunctionType>(func)(std::forward<Args>(args)..., errorBuffer,
sizeof(errorBuffer));
144 if (
object ==
nullptr) {
throw std::runtime_error(errorBuffer); };
147inline auto RTMotionControllerGet() {
return RTObjectGet(MotionControllerGet); }
148inline auto RTAxisGet(
const int32_t index) {
return RTObjectGet(AxisGet, index); }
149inline auto RTMultiAxisGet(
const int32_t index) {
return RTObjectGet(MultiAxisGet, index); }
150inline auto RTNetworkNodeGet(
const int32_t index) {
return RTObjectGet(NetworkNodeGet, index); }
Represents a single axis of motion control. This class provides an interface for commanding motion,...
Represents the RMP soft motion controller. This class provides an interface to general controller con...
Represents multiple axes of motion control, allows you to map two or more Axis objects together for e...