2#include <sys/_stdint.h>
21typedef volatile float64_t DecimalPosition;
22typedef volatile int32_t IntegerPosition;
23typedef volatile float32_t ControlParameter;
25typedef void (*frame_function_pointer)();
27#define CORE_FRAME_PERIOD_US 40
28#define CORE_FRAME_PERIOD_S CORE_FRAME_PERIOD_US / 1000000
29#define CORE_FRAME_FREQ_HZ 1000000 / CORE_FRAME_PERIOD_US
30#define MAX_NUM_FRAME_FUNCTIONS 10
32#define KILOHERTZ_PLUGIN_PERIOD_US 1000
44#define STANDARD_RATIO_MM 0.01
45#define STANDARD_RATIO_IN 0.0003937
48#define PLUGIN_FRAME_PRE_CHANNEL 0
49#define PLUGIN_FRAME_POST_CHANNEL 1
50#define PLUGIN_KILOHERTZ 2
52#define PLUGIN_INPUT_PORT 4
75void add_function_to_frame(frame_function_pointer target_function);
78void stepdance_metrics_reset();
79float stepdance_get_cpu_usage();
80static volatile float stepdance_max_cpu_usage = 0;
81static volatile uint32_t stepdance_interrupt_entry_cycle_count = 0;
86#define MAX_NUM_INPUT_PORT_FRAME_PLUGINS 10
87#define MAX_NUM_PRE_CHANNEL_FRAME_PLUGINS 10
88#define MAX_NUM_POST_CHANNEL_FRAME_PLUGINS 10
89#define MAX_NUM_KILOHERTZ_PLUGINS 10
90#define MAX_NUM_LOOP_PLUGINS 10
99 static void run_input_port_frame_plugins();
100 static void run_pre_channel_frame_plugins();
101 static void run_post_channel_frame_plugins();
102 static void run_kilohertz_plugins();
103 static void run_loop_plugins();
105 virtual void enable();
106 virtual void disable();
107 virtual void enroll(RPC *rpc,
const String& instance_name);
108 virtual void push_deep();
109 virtual void pull_deep();
112 static Plugin* registered_input_port_frame_plugins[MAX_NUM_INPUT_PORT_FRAME_PLUGINS];
113 static Plugin* registered_pre_channel_frame_plugins[MAX_NUM_PRE_CHANNEL_FRAME_PLUGINS];
114 static Plugin* registered_post_channel_frame_plugins[MAX_NUM_POST_CHANNEL_FRAME_PLUGINS];
115 static Plugin* registered_kilohertz_plugins[MAX_NUM_KILOHERTZ_PLUGINS];
116 static Plugin* registered_loop_plugins[MAX_NUM_LOOP_PLUGINS];
117 static uint8_t num_registered_input_port_frame_plugins;
118 static uint8_t num_registered_pre_channel_frame_plugins;
119 static uint8_t num_registered_post_channel_frame_plugins;
120 static uint8_t num_registered_kilohertz_plugins;
121 static uint8_t num_registered_loop_plugins;
124 void register_plugin();
125 void register_plugin(uint8_t execution_target);
161 void set_ratio(
float world_units,
float block_units = 1.0);
170 map(map_target, INCREMENTAL);
192 void write(float64_t value, uint8_t mode);
194 void write_now(float64_t);
195 float64_t read_target();
203 void begin(
volatile float64_t *target, uint8_t direction = BLOCKPORT_UNDEFINED, Plugin *parent =
nullptr);
204 void set_target(
volatile float64_t *target);
206 void reverse_update();
207 void set(float64_t value, uint8_t mode);
208 inline void set(float64_t value){
209 set(value, ABSOLUTE);
211 void reset(float64_t value,
bool raw =
false);
213 void push(uint8_t mode);
218 void pull(uint8_t mode);
225 void push_deep(DecimalPosition abs_value);
226 DecimalPosition pull_deep();
229 inline void reset_deep(DecimalPosition abs_value){
230 push_deep(abs_value);
232 inline DecimalPosition read_deep(){
239 volatile float64_t incremental_buffer = 0;
240 volatile float64_t absolute_buffer = 0;
242 inline float64_t convert_block_to_world_units(float64_t block_units){
243 return block_units * world_to_block_ratio;
245 inline float64_t convert_world_to_block_units(float64_t world_units){
246 return world_units / world_to_block_ratio;
249 volatile float64_t* target =
nullptr;
251 void enroll(RPC *rpc,
const String& instance_name);
254 volatile bool update_has_run =
false;
255 uint8_t mode = INCREMENTAL;
256 volatile uint8_t push_pull_enabled =
true;
259 float64_t world_to_block_ratio = 1;
262 Plugin* parent_Plugin =
nullptr;
263 uint8_t blockport_direction = BLOCKPORT_UNDEFINED;
276static volatile float stepdance_loop_time_ms;
277static volatile uint32_t stepdance_loop_entry_cycle_count = 0;
282 void periodic_call(
void (*callback_function)(),
float interval_ms);
285 float time_since_last_call_ms;
float64_t read_absolute()
Returns the absolute position value of the BlockPort in world units.
float64_t read(uint8_t mode)
Returns the position value of the BlockPort in world units. Reading in INCREMENTAL mode returns the c...
void map(BlockPort *map_target, uint8_t mode)
Maps this BlockPort to a target BlockPort with a specified mode (INCREMENTAL or ABSOLUTE).
BlockPort()
Default constructor for BlockPort. Initializes a BlockPort instance. You do not need to call this dir...
void set_ratio(float world_units, float block_units=1.0)
Sets the ratio between world units and block units for this BlockPort for automatic conversion....
RPC class for handling remote procedure calls over serial streams.
Definition rpc.hpp:35