File sstep_ctrl.c¶
FileList > src > sstep_ctrl.c
Go to the source code of this file
#include "sstep.h"#include <stddef.h>#include "sstep_internal.h"
Classes¶
| Type | Name |
|---|---|
| struct | align_ctx |
| struct | align_pub |
Public Static Functions¶
| Type | Name |
|---|---|
| int | check_config (const struct sstep_config * cfg) Validate a configuration field by field and as a whole. |
| int | check_stall (const struct sstep_config * cfg) Validate the stall detection fields (ignored when stall_time_ms is 0). |
| void | control (struct sstep_ctx * m) Current control, power stage and PWM write of one fast loop period. |
| int | derive (struct sstep_ctx * m) Derive gains, scaling and limits from the (validated) configuration. |
| int | derive_stall (struct sstep_ctx * m) Derive the stall detection constants (after the other gains). |
| int64_t | div_round (int64_t num, int64_t den) round(num / den) for den > 0, half away from zero. |
| sstep_real_t | gain_apply_i32 (const struct sstep_gain * g, int32_t v) g * v for a 32-bit integer v (slow loop, 64-bit product), as a saturated signal. |
| bool | is_active (enum sstep_state s) Outputs are on. |
| bool | is_moving (const struct sstep_ctx * m) A command is executing. |
| bool | is_pow2 (uint32_t v) v is a power of two (v > 0). |
| uint8_t | log2_u32 (uint32_t v) log2 of a power of two. |
| bool | mul_ok (uint64_t a, uint64_t b, uint64_t * out) out = a * b; false when the product reaches 2^62. |
| int64_t | pow2_i64 (uint32_t n) 2^n for n = 0 . |
| void | publish (struct sstep_ctx * m, const struct sstep_setpoint * sp) Hand a setpoint to the fast loop (slow loop context). |
| int | ratio (uint64_t n1, uint64_t n2, uint64_t d1, uint64_t d2, struct sstep_gain * g) g = (n1 n2) / (d1 d2) with overflow checks (configuration only). |
| sstep_angle_t | raw_angle (const struct sstep_ctx * m, int64_t pos) Electrical angle of a position [Q16 microsteps]: microstep = 2^30 / M. |
| int | set_currents (struct sstep_ctx * m, uint32_t run_ma, uint32_t hold_ma) Validate and store the run and hold currents. |
| int | set_limits (struct sstep_ctx * m, uint32_t v_max, uint32_t accel, uint32_t decel) Validate and store the motion limits (engineering units -> Q16 per period). |
| void | shutdown (struct sstep_ctx * m, uint16_t faults) Switch the outputs off and enter the fault state (any context). |
Macros¶
| Type | Name |
|---|---|
| define | Q16_LIMIT ((int64\_t)0x40000000)Velocities and accelerations in Q16 per period stay below 2^30. |
| define | RATIO_LIMIT ((uint64\_t)1U << 62U)Operand limit of the gain ratios (sstep_gain_from_ratio64). |
| define | TWO_PI_DEN 113U |
| define | TWO_PI_NUM 710U2 pi = 710 / 113 (error 8.5e-8). |
| define | VALUE_MAX 10000000ULargest engineering value accepted in the motor and stage configuration. |
| define | VBUS_PU_MAX [**SSTEP\_ACC\_SCALE\_MAX**](group__sstep__math.md#define-sstep_acc_scale_max)Bus voltage limit of the fast loop: 2 pu - 2^-15. |
Public Static Functions Documentation¶
function check_config¶
Validate a configuration field by field and as a whole.
function check_stall¶
Validate the stall detection fields (ignored when stall_time_ms is 0).
function control¶
Current control, power stage and PWM write of one fast loop period.
function derive¶
Derive gains, scaling and limits from the (validated) configuration.
function derive_stall¶
Derive the stall detection constants (after the other gains).
function div_round¶
round(num / den) for den > 0, half away from zero.
function gain_apply_i32¶
g * v for a 32-bit integer v (slow loop, 64-bit product), as a saturated signal.
function is_active¶
Outputs are on.
function is_moving¶
A command is executing.
In hold mode the velocity is always zero: a move ends with v = 0 on the target and a stop becomes hold only at v = 0.
function is_pow2¶
v is a power of two (v > 0).
function log2_u32¶
log2 of a power of two.
function mul_ok¶
out = a * b; false when the product reaches 2^62.
function pow2_i64¶
2^n for n = 0 .
. 62, built with an unsigned shift (MISRA C:2012 Rule 10.1).
function publish¶
Hand a setpoint to the fast loop (slow loop context).
The fast loop never reads the buffer being written: sp_pending is cleared first (single core).
function ratio¶
g = (n1 n2) / (d1 d2) with overflow checks (configuration only).
Every factor is a product of at most two validated values (< 10^7 each), so it fits.
function raw_angle¶
Electrical angle of a position [Q16 microsteps]: microstep = 2^30 / M.
function set_currents¶
Validate and store the run and hold currents.
function set_limits¶
Validate and store the motion limits (engineering units -> Q16 per period).
function shutdown¶
Switch the outputs off and enter the fault state (any context).
Macro Definition Documentation¶
define Q16_LIMIT¶
Velocities and accelerations in Q16 per period stay below 2^30.
define RATIO_LIMIT¶
Operand limit of the gain ratios (sstep_gain_from_ratio64).
define TWO_PI_DEN¶
define TWO_PI_NUM¶
2 pi = 710 / 113 (error 8.5e-8).
define VALUE_MAX¶
Largest engineering value accepted in the motor and stage configuration.
define VBUS_PU_MAX¶
Bus voltage limit of the fast loop: 2 pu - 2^-15.
The documentation for this class was generated from the following file src/sstep_ctrl.c