Stepdance Software Library
Loading...
Searching...
No Matches
kinematics.hpp
1#include "arm_math.h"
2/*
3Kinematics Module of the StepDance Control System
4
5This module provides a variety of mechanism kinematics to go from one motion space (e.g. XY) to another (e.g. AB or RT) via e.g. an h-bot or polar mechanism, etc.
6
7[More Details to be Added]
8
9A part of the Mixing Metaphors Project
10(c) 2025 Ilan Moyer, Jennifer Jacobs, Devon Frost
11*/
12
13#include "core.hpp"
14
15#ifndef kinematics_h //prevent importing twice
16#define kinematics_h
17
25class KinematicsCoreXY : public Plugin{
26 public:
27 KinematicsCoreXY();
31 void begin();
36 void enroll(RPC *rpc, const String& instance_name);
38
39 // BlockPorts
56
57 // Synchronization
58 void push_deep() override; //is not user-facing.
59 void pull_deep() override; //is not user-facing.
60 DecimalPosition read_deep(BlockPort& in_blockport) override; //is not user-facing.
61
62 private:
63 volatile DecimalPosition position_x = 0; //internal registers to store state positions
64 volatile DecimalPosition position_y = 0;
65 volatile DecimalPosition position_a = 0;
66 volatile DecimalPosition position_b = 0;
67
68 protected:
69 void run();
70};
71
79class KinematicsPolarToCartesian : public Plugin{
80 public:
81 KinematicsPolarToCartesian();
86 void begin(float64_t fixed_radius = 0); //optional radius parameter
91 void reset(); //TODO: resets the internal state
92 void solve_kinematics(); //TODO: solves the relationship between r-t and x-y.
93 // we do this outside run() so that it can be called during a state reset.
94 void enroll(RPC *rpc, const String& instance_name);
112
113 private:
114 DecimalPosition position_r = 0;
115 DecimalPosition position_a = 0;
116 DecimalPosition position_x = 0;
117 DecimalPosition position_y = 0;
118
119 protected:
120 void run();
121};
122
130class KinematicsFiveBarForward : public Plugin{
131 // Converts encoder (or motor) angles to XY coordinates for a five-bar parallel kinematics mechanism (e.g. Parallel SCARA)
132 // This was created for the digital pantograph, so we will generally refer to encoders rather than motors.
133 // Because this module works with absolute inputs and therefor will not accumulate error, we will use float32_t precision
134 // (rather than float64_t) to speed up calculations. Inputs and outputs remain float64_t.
135 // For clarity of equations We will use capital letters for certain variables within this function. Externally we
136 // maintain consistency with only using capital letters for constants.
137
138 public:
139 KinematicsFiveBarForward();
150 void begin(float32_t s, float32_t l1, float32_t l2, float32_t l3, float32_t l4, float32_t l5, float32_t a);
155 void enroll(RPC *rpc, const String& instance_name);
156
174
175 private:
176 DecimalPosition position_r = 0; //right angle, in radians
177 DecimalPosition position_l = 0; //left angle, in radians
178 DecimalPosition position_x = 0;
179 DecimalPosition position_y = 0;
180
181 float32_t S; // encoder separation
182 float32_t L1; // right encoder arm length
183 float32_t L2; // left encoder arm length
184 float32_t L3; // right pivot arm length
185 float32_t L4; // left pivot arm length
186 float32_t L5; // tool arm length
187 float32_t A6; // tool arm angle in rad
188 float32_t Xa; // X position of right encoder
189 float32_t Ya; // Y position of right encoder
190 float32_t Xb; // X position of left encoder
191 float32_t Yb; // Y position of left encoder
192
193 protected:
194 void run();
195};
196
197using KinematicsLever = KinematicsPolarToCartesian;
198
199#endif //kinematics_h
BlockPorts provide a unified interface for mapping inputs and outputs of different StepDance componen...
Definition core.hpp:152
BlockPort output_a
Output BlockPort for A motor motion. Map downstream components to this port.
Definition kinematics.hpp:51
BlockPort input_y
Input BlockPort for Y axis motion. Map upstream components to this port.
Definition kinematics.hpp:47
void begin()
Initializes the KinematicsCoreXY. This must be called before using the kinematics.
BlockPort output_b
Output BlockPort for B motor motion. Map downstream components to this port.
Definition kinematics.hpp:55
BlockPort input_x
Input BlockPort for X axis motion. Map upstream components to this port.
Definition kinematics.hpp:43
void begin(float32_t s, float32_t l1, float32_t l2, float32_t l3, float32_t l4, float32_t l5, float32_t a)
Initializes the KinematicsFiveBarForward with the specified mechanism parameters.
BlockPort output_x
Output BlockPort for X axis motion. Map downstream components to this port.
Definition kinematics.hpp:169
BlockPort input_r
Input BlockPort for the right encoder angle in radians. Map upstream components to this port.
Definition kinematics.hpp:161
BlockPort output_y
Output BlockPort for Y axis motion. Map downstream components to this port.
Definition kinematics.hpp:173
BlockPort input_l
Input BlockPort for the left encoder angle in radians. Map upstream components to this port.
Definition kinematics.hpp:165
KinematicsPolarToCartesian converts polar coordinates (radius and angle) to Cartesian coordinates (X ...
Definition kinematics.hpp:79
void begin(float64_t fixed_radius=0)
Initializes the KinematicsPolarToCartesian with an optional fixed radius. If a fixed radius is provid...
BlockPort output_x
Output BlockPort for X axis motion. Map downstream components to this port.
Definition kinematics.hpp:107
BlockPort input_radius
Input BlockPort for radius (r) in polar coordinates. Ignored if a fixed radius is set in begin()....
Definition kinematics.hpp:99
BlockPort input_angle
Input BlockPort for angle (theta) in polar coordinates. Map upstream components to this port.
Definition kinematics.hpp:103
BlockPort output_y
Output BlockPort for Y axis motion. Map downstream components to this port.
Definition kinematics.hpp:111
RPC class for handling remote procedure calls over serial streams.
Definition rpc.hpp:35