14#include "src/system/ext/math8.h"
53 theta_rad(atan2(positionCartesian.y, positionCartesian.x)),
54 z_mm(positionCartesian.z)
60 Particle(
const float positionTheta_rad,
const float positionZ_mm) :
theta_rad(positionTheta_rad),
z_mm(positionZ_mm)
74 const float tangentialAcceleration =
75 accelerationCartesian_m.
y * fast_cos(
theta_rad) - accelerationCartesian_m.
x * fast_sin(
theta_rad);
108 const float deltaTime_s,
109 const bool shouldContrain =
true)
117 const float angularPositionIncrement =
118 lmpd_constrain<float>(
thetaSpeed_radS * deltaTime_s, -angularUnit, angularUnit);
119 const float verticalPositionIncrement =
120 lmpd_constrain<float>(
zSpeed_mS * deltaTime_s, -verticalUnit, verticalUnit) * 1000.0f;
123 z_mm += verticalPositionIncrement;
143 const float deltaTime_s,
144 const bool shouldContrain =
true)
const
201 void set_color(
const uint32_t color) { compressedColor = colors::get_compressed_16b_color(color); }
202 uint32_t get_color()
const {
return colors::get_decompressed_32b_color(compressedColor); }
216 static int16_t
led_index_at(
const float positionTheta_rad,
const float positionZ_mm)
218 float turnFraction = positionTheta_rad * (1.0f /
c_TWO_PI);
219 turnFraction -= fast_floor(turnFraction);
220 const float turn = fast_floor(-positionZ_mm * (1.0f /
rowHeight_mm) - turnFraction + 0.5f);
221 return static_cast<int16_t
>(fast_floor((turn + turnFraction) *
ledsPerTurn + 0.5f));
240 (accelerationCartesian_m.
x * fast_cos(angle_rad) + accelerationCartesian_m.
y * fast_sin(angle_rad)) -
274 static float fast_floor(
const float value)
276 const float truncated =
static_cast<float>(
static_cast<int32_t
>(value));
277 return (truncated > value) ? truncated - 1.0f : truncated;
281 static float fast_sin(
const float angle_rad)
283 float turns = angle_rad * (1.0f /
c_TWO_PI);
284 turns -= fast_floor(turns + 0.5f);
285 return 8.0f * turns - 16.0f * turns * fabsf(turns);
289 static float fast_cos(
const float angle_rad) {
return fast_sin(angle_rad +
c_HALF_PI); }
@ White
Definition: palettes.hpp:231
Contains basic interface types to implement custom user modes.
Definition: control_fixed_modes.hpp:14
static constexpr float angularSpeedGain
this gain compensate the angular acceleration for better display
Definition: particle.hpp:25
static constexpr float maxVerticalSpeed_mmS
max vertical speed in mm/S
Definition: particle.hpp:31
static constexpr uint16_t to_led_index(const float angle_rad, const float z)
convert a lamp coordinate to a led index
Definition: lamp_type.hpp:1332
static constexpr float to_helix_z(const int16_t n)
Convert a led index to an helix height coordinate.
Definition: lamp_type.hpp:1292
static constexpr float speedDampening
low speed dampening [0-0.99] at every steps (viscosity)
Definition: particle.hpp:28
static constexpr float linearSpeedGain
gain for the linear speeds
Definition: particle.hpp:26
static constexpr float rowHeight_mm
height gained by the helix in one turn
Definition: particle.hpp:34
static constexpr bool is_led_index_valid(const int16_t ledIndex)
True if the given strip index is a valid one.
Definition: lamp_type.hpp:1313
static constexpr float maxAngularSpeed_radS
max angular speed in radians/s
Definition: particle.hpp:30
static constexpr float cylinderRadius_m
radius of the cylinder, in meters
Definition: particle.hpp:24
static constexpr float ledsPerTurn
leds around the tube. Not an integer: rows are sheared
Definition: particle.hpp:33
static constexpr float cylinderRadius_mm
radius of the cylinder, in millimeters ratio between the speed gained around the tube and the physica...
Definition: particle.hpp:36
static constexpr float reboundCoeff
low rebound [0 - 1] on walls
Definition: particle.hpp:27
static constexpr float ledLength_mm
length of a led along the strip
Definition: particle.hpp:35
static constexpr float wrap_angle(const float angle_rad)
Wrap an angle in radians between 0 and 2*PI.
Definition: utils.h:115
static constexpr float c_TWO_PI
2*PI constant
Definition: constants.h:41
static constexpr float c_HALF_PI
PI/2 constant.
Definition: constants.h:42
Define a particle in 3D space. it has a position and speed.
Definition: particle.hpp:44
Particle(const utils::vec3d &positionCartesian)
Construct a Particle from a 3D cartesian position.
Definition: particle.hpp:52
void move_by(const utils::vec2d &offset_mm, const int16_t ledIndex)
Move this particle on the cylinder surface, to a led already computed from this offset.
Definition: particle.hpp:251
float theta_rad
position, in radians
Definition: particle.hpp:266
void apply_acceleration(const utils::vec3d &accelerationCartesian_m, const float deltaTime_s, const bool shouldContrain=true)
apply a cartesian acceleration to this particulate
Definition: particle.hpp:107
utils::vec2d compute_speed_increment(const utils::vec3d &accelerationCartesian_m, const float deltaTime_s) const
Compute the speed increment in the constraint lamp body.
Definition: particle.hpp:71
uint16_t to_lamp_index() const
Convert this particle coordinates to a constraint lamp index.
Definition: particle.hpp:205
int16_t _savedLampIndex
optimization
Definition: particle.hpp:270
utils::vec2d update_speed(const utils::vec3d &accelerationCartesian_m, const float deltaTime_s)
Dampen the speed and apply a cartesian acceleration to it, without moving the particle.
Definition: particle.hpp:87
int16_t to_lamp_index_no_bounds() const
Convert this particle coordinates to an unconstraint lamp index: the nearest led of the helix.
Definition: particle.hpp:207
Particle simulate_after_acceleration(const utils::vec3d &accelerationCartesian_m, const float deltaTime_s, const bool shouldContrain=true) const
Simulate this particle movement as a new particle.
Definition: particle.hpp:142
static int16_t led_index_at(const float positionTheta_rad, const float positionZ_mm)
Find the led nearest to a position, following the real helix of the strip. A led height depends on it...
Definition: particle.hpp:216
float thetaSpeed_radS
angular speed, in radian/seconds
Definition: particle.hpp:263
Particle(const Particle &other)=default
Copy constructor for a particle.
float zSpeed_mS
linear speed, in meter/seconds
Definition: particle.hpp:264
void constraint_into_lamp_body()
Contrain the particle movement to the cylinder, limiting the movement at the extremities.
Definition: particle.hpp:154
utils::vec2d get_surface_speed() const
Return the speed on the cylinder surface, in mm/s (around the tube, along the height)
Definition: particle.hpp:245
float z_mm
height, in millimeters.
Definition: particle.hpp:267
void dampen_speed(const float dampenFactor)
Bleed off some speed. Simulate a dampening factor (like friction loss)
Definition: particle.hpp:195
Particle()=default
Default particle init.
static float potential_at_led(const utils::vec3d &accelerationCartesian_m, const int16_t ledIndex)
Potential energy of a led under an acceleration, consistent with the acceleration of a particle.
Definition: particle.hpp:236
Particle(const float positionTheta_rad, const float positionZ_mm)
Construct a particle from an angle and height.
Definition: particle.hpp:60
int16_t led_index_at_offset(const utils::vec2d &offset_mm) const
Return the led under this particle, once moved by an offset on the cylinder surface (in mm).
Definition: particle.hpp:225
Main interface between the user and the hardware of the lamp.
Definition: lamp_type.hpp:120
static constexpr float lampHeight_mm
Computation of the lamp height.
Definition: lamp_type.hpp:447
static constexpr float maxWidthFloat
Width as a precise floating point number, equal to stripXCoordinates.
Definition: lamp_type.hpp:379
static constexpr float ledStripWidth_mm
real size of the led strip in use
Definition: lamp_type.hpp:433
static constexpr float ledPerTurns
Computation of the led count per turns.
Definition: lamp_type.hpp:445
static constexpr float ledSize_mm
Number of leds per one turn of led strip.
Definition: lamp_type.hpp:441
static constexpr float lampBodyRadius_mm
real radius of the lamp body
Definition: lamp_type.hpp:430
2d vector in any space
Definition: vector_math.h:15
float x
x coordinate in 2D
Definition: vector_math.h:16
float y
y coordinate in 2D
Definition: vector_math.h:17
3d vector in any space
Definition: vector_math.h:54
float z
z coordinate of a 3D vector
Definition: vector_math.h:55
Define the system hardware constants.
User defined constants, relative to specific lamp types.
Define vectors and rotation matrices, and the possibility to rotate vectors.