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
61 private:
62 volatile DecimalPosition position_x = 0; //internal registers to store state positions
63 volatile DecimalPosition position_y = 0;
64 volatile DecimalPosition position_a = 0;
65 volatile DecimalPosition position_b = 0;
66
67 protected:
68 void run();
69};
70
78class KinematicsPolarToCartesian : public Plugin{
79 public:
80 KinematicsPolarToCartesian();
85 void begin(float64_t fixed_radius = 0); //optional radius parameter
90 void reset(); //TODO: resets the internal state
91 void solve_kinematics(); //TODO: solves the relationship between r-t and x-y.
92 // we do this outside run() so that it can be called during a state reset.
93 void enroll(RPC *rpc, const String& instance_name);
111
112 private:
113 DecimalPosition position_r = 0;
114 DecimalPosition position_a = 0;
115 DecimalPosition position_x = 0;
116 DecimalPosition position_y = 0;
117
118 protected:
119 void run();
120};
121
129class KinematicsFiveBarForward : public Plugin{
130 // Converts encoder (or motor) angles to XY coordinates for a five-bar parallel kinematics mechanism (e.g. Parallel SCARA)
131 // This was created for the digital pantograph, so we will generally refer to encoders rather than motors.
132 // Because this module works with absolute inputs and therefor will not accumulate error, we will use float32_t precision
133 // (rather than float64_t) to speed up calculations. Inputs and outputs remain float64_t.
134 // For clarity of equations We will use capital letters for certain variables within this function. Externally we
135 // maintain consistency with only using capital letters for constants.
136
137 public:
138 KinematicsFiveBarForward();
149 void begin(float32_t s, float32_t l1, float32_t l2, float32_t l3, float32_t l4, float32_t l5, float32_t a);
154 void enroll(RPC *rpc, const String& instance_name);
155
173
174 private:
175 DecimalPosition position_r = 0; //right angle, in radians
176 DecimalPosition position_l = 0; //left angle, in radians
177 DecimalPosition position_x = 0;
178 DecimalPosition position_y = 0;
179
180 float32_t S; // encoder separation
181 float32_t L1; // right encoder arm length
182 float32_t L2; // left encoder arm length
183 float32_t L3; // right pivot arm length
184 float32_t L4; // left pivot arm length
185 float32_t L5; // tool arm length
186 float32_t A6; // tool arm angle in rad
187 float32_t Xa; // X position of right encoder
188 float32_t Ya; // Y position of right encoder
189 float32_t Xb; // X position of left encoder
190 float32_t Yb; // Y position of left encoder
191
192 protected:
193 void run();
194};
195
196using KinematicsLever = KinematicsPolarToCartesian;
197
198#endif //kinematics_h
BlockPorts provide a unified interface for mapping inputs and outputs of different StepDance componen...
Definition core.hpp:148
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:168
BlockPort input_r
Input BlockPort for the right encoder angle in radians. Map upstream components to this port.
Definition kinematics.hpp:160
BlockPort output_y
Output BlockPort for Y axis motion. Map downstream components to this port.
Definition kinematics.hpp:172
BlockPort input_l
Input BlockPort for the left encoder angle in radians. Map upstream components to this port.
Definition kinematics.hpp:164
KinematicsPolarToCartesian converts polar coordinates (radius and angle) to Cartesian coordinates (X ...
Definition kinematics.hpp:78
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:106
BlockPort input_radius
Input BlockPort for radius (r) in polar coordinates. Ignored if a fixed radius is set in begin()....
Definition kinematics.hpp:98
BlockPort input_angle
Input BlockPort for angle (theta) in polar coordinates. Map upstream components to this port.
Definition kinematics.hpp:102
BlockPort output_y
Output BlockPort for Y axis motion. Map downstream components to this port.
Definition kinematics.hpp:110
RPC class for handling remote procedure calls over serial streams.
Definition rpc.hpp:35