Skip to content

Commit d6aa0c8

Browse files
authored
Merge pull request #4272 from BsAtHome/halgs_components-simple-2
hal: Update more easy-to-convert components to getter/setter
2 parents 3dfceeb + f1b579f commit d6aa0c8

39 files changed

Lines changed: 752 additions & 741 deletions

src/hal/components/anglejog.comp

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -36,28 +36,28 @@ pin is current-scale-out as it depends on the iscale-factor setting.
3636
Simulation Config: `configs/sim/axis/anglejog/anglejog.in`
3737
""";
3838

39-
pin in bit enable_in "enables motion (disables alteration of angle and scale)";
40-
pin in s32 counts_in "MPG (wheel) counts";
41-
pin in float angle_degrees_in "vector angle";
42-
pin in s32 iscale_factor = 10000 "integer scaling factor (>1)";
43-
pin in float scale_in "magnitude units/count (mag = counts * scale)";
44-
pin in float max_vel "vector max velocity magnitude";
45-
pin in float max_accel "vector max acceleration magnitude";
46-
pin in float accel_fraction_in = 1 "acceleration fraction input";
39+
pin in bool enable_in "enables motion (disables alteration of angle and scale)";
40+
pin in si32 counts_in "MPG (wheel) counts";
41+
pin in real angle_degrees_in "vector angle";
42+
pin in si32 iscale_factor = 10000 "integer scaling factor (>1)";
43+
pin in real scale_in "magnitude units/count (mag = counts * scale)";
44+
pin in real max_vel "vector max velocity magnitude";
45+
pin in real max_accel "vector max acceleration magnitude";
46+
pin in real accel_fraction_in = 1 "acceleration fraction input";
4747

48-
pin out bit enable_out "to: axis.M.jog-enable AND axis.N.jog-enable";
49-
pin out float current_scale "effective scale (informational)";
50-
pin out float current_scale_out "to: axis.M.jog-scale AND axis.N.jog-scale";
51-
pin out s32 coscounts "to: axis.M.jog-counts (cosine counts)";
52-
pin out s32 sincounts "to: axis.N.jog-counts (sine counts)";
53-
pin out float cos_accel_fraction "to: axis.M.jog-accel-fraction";
54-
pin out float sin_accel_fraction "to: axis.N.jog-accel-fraction";
48+
pin out bool enable_out "to: axis.M.jog-enable AND axis.N.jog-enable";
49+
pin out real current_scale "effective scale (informational)";
50+
pin out real current_scale_out "to: axis.M.jog-scale AND axis.N.jog-scale";
51+
pin out si32 coscounts "to: axis.M.jog-counts (cosine counts)";
52+
pin out si32 sincounts "to: axis.N.jog-counts (sine counts)";
53+
pin out real cos_accel_fraction "to: axis.M.jog-accel-fraction";
54+
pin out real sin_accel_fraction "to: axis.N.jog-accel-fraction";
5555

5656
// output monitor pins:
57-
pin out bit active "angle jog move in progress";
58-
pin out float current_angle_degrees "current angle";
59-
pin out float current_mag "current vector magnitude";
60-
pin out float current_vel "current vector speed";
57+
pin out bool active "angle jog move in progress";
58+
pin out real current_angle_degrees "current angle";
59+
pin out real current_mag "current vector magnitude";
60+
pin out real current_vel "current vector speed";
6161

6262
function _;
6363
license "GPL";
@@ -66,7 +66,7 @@ author "Dewey Garrett";
6666
#include <rtapi_math.h>
6767
#define TO_RAD M_PI/180
6868
// replicate simple_tp.h define for tiny magnitude delta:
69-
#define TINY_DP(max_accel,period) (max_accel*period*period*0.001)
69+
#define TINY_DP(_max_accel,_period) ((_max_accel)*(_period)*(_period)*0.001)
7070
#define MIN_ISCALE_FACTOR 10
7171
#define MAX_ISCALE_FACTOR 100000
7272

@@ -83,9 +83,9 @@ static int ifactor = 0;
8383
int newcounts;
8484

8585
if (once) {
86-
current_angle_degrees = angle_degrees_in;
87-
current_scale = scale_in;
88-
current_scale_out = scale_in/iscale_factor;
86+
current_angle_degrees_set(angle_degrees_in);
87+
current_scale_set(scale_in);
88+
current_scale_out_set(scale_in/iscale_factor);
8989
ifactor = iscale_factor;
9090
once = 0;
9191
}
@@ -100,13 +100,13 @@ static int ifactor = 0;
100100
delta_counts = newcounts - old_counts_in;
101101
old_enable_in = enable_in;
102102
old_counts_in = newcounts;
103-
enable_out = enable_in;
103+
enable_out_set(enable_in);
104104

105105
if (delta_counts!=0) {wait_for_count_change = 0;}
106106
if (enable_in) { tot_counts = tot_counts + delta_counts;}
107107
mag_cmd = tot_counts * current_scale_out;
108108

109-
active = 0;
109+
active_set(0);
110110
/* compute max change in velocity per servo period */
111111
max_dv = max_accel * fperiod;
112112
/* compute a tiny magnitude range, to be treated as zero */
@@ -123,12 +123,12 @@ static int ifactor = 0;
123123
vel_req = -max_dv +
124124
sqrt(2.0 * max_accel * mag_err + max_dv * max_dv);
125125
/* mark planner as active */
126-
active = 1;
126+
active_set(1);
127127
} else if (mag_err < -tiny_dp) {
128128
vel_req = max_dv -
129129
sqrt(-2.0 * max_accel * mag_err + max_dv * max_dv);
130130
/* mark planner as active */
131-
active = 1;
131+
active_set(1);
132132
} else {
133133
/* within 'tiny_dp' of desired mag, no need to move */
134134
vel_req = 0.0;
@@ -158,11 +158,11 @@ static int ifactor = 0;
158158
}
159159
}
160160
}
161-
current_angle_degrees = angle_degrees_in;
161+
current_angle_degrees_set(angle_degrees_in);
162162
if ( current_scale_out != scale_in
163163
|| new_ifactor) {
164-
current_scale = scale_in;
165-
current_scale_out = scale_in/ifactor;
164+
current_scale_set(scale_in);
165+
current_scale_out_set(scale_in/ifactor);
166166
tot_counts = current_mag/current_scale_out;
167167
}
168168
}
@@ -176,24 +176,24 @@ static int ifactor = 0;
176176
}
177177
/* ramp velocity toward request at accel limit */
178178
if (vel_req > current_vel + max_dv) {
179-
current_vel += max_dv;
179+
current_vel_set(current_vel + max_dv);
180180
} else if (vel_req < current_vel - max_dv) {
181-
current_vel -= max_dv;
181+
current_vel_set(current_vel - max_dv);
182182
} else {
183-
current_vel = vel_req;
183+
current_vel_set(vel_req);
184184
}
185185
/* check for still moving */
186186
if (current_vel != 0.0) {
187187
/* yes, mark planner active */
188-
active = 1;
188+
active_set(1);
189189
}
190190
/* integrate velocity to get new magnitude */
191-
current_mag += current_vel * fperiod;
191+
current_mag_set(current_mag + current_vel * fperiod);
192192
double cos_angle,sin_angle;
193193
cos_angle = cos(current_angle_degrees * TO_RAD);
194194
sin_angle = sin(current_angle_degrees * TO_RAD);
195-
coscounts = current_mag * cos_angle/current_scale_out;
196-
sincounts = current_mag * sin_angle/current_scale_out;
197-
cos_accel_fraction = accel_fraction_in * cos_angle;
198-
sin_accel_fraction = accel_fraction_in * sin_angle;
195+
coscounts_set(current_mag * cos_angle/current_scale_out);
196+
sincounts_set(current_mag * sin_angle/current_scale_out);
197+
cos_accel_fraction_set(accel_fraction_in * cos_angle);
198+
sin_accel_fraction_set(accel_fraction_in * sin_angle);
199199
}

src/hal/components/axistest.comp

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
component axistest """\
22
Used to allow testing of an axis. Used IN PnCconf.""";
3-
pin in bit jog-minus "Drive TRUE to jog the axis in its negative ('minus') direction.";
4-
pin in bit jog-plus "Drive TRUE to jog the axis in its positive direction.";
5-
pin in bit run "Drive TRUE to run the axis near its current position_fb with a trapezoidal velocity profile.";
6-
pin in float maxvel "Maximum velocity";
7-
pin in float amplitude "Approximate amplitude of positions to command during 'run'";
8-
pin in s32 dir "Direction from central point to test: 0 = both, 1 = positive, 2 = negative";
9-
pin out float position-cmd;
10-
pin in float position-fb;
11-
pin out bit running;
12-
pin out float run-target;
13-
pin out float run-start;
14-
pin out float run-low;
15-
pin out float run-high;
16-
pin in s32 pause = 0 "Pause time for each end of run in seconds";
17-
param rw float epsilon = .001;
3+
pin in bool jog-minus "Drive TRUE to jog the axis in its negative ('minus') direction.";
4+
pin in bool jog-plus "Drive TRUE to jog the axis in its positive direction.";
5+
pin in bool run "Drive TRUE to run the axis near its current position_fb with a trapezoidal velocity profile.";
6+
pin in real maxvel "Maximum velocity";
7+
pin in real amplitude "Approximate amplitude of positions to command during 'run'";
8+
pin in si32 dir "Direction from central point to test: 0 = both, 1 = positive, 2 = negative";
9+
pin in real position-fb;
10+
pin out real position-cmd;
11+
pin out bool running;
12+
pin out real run-target;
13+
pin out real run-start;
14+
pin out real run-low;
15+
pin out real run-high;
16+
pin in si32 pause = 0 "Pause time for each end of run in seconds";
17+
param rw real epsilon = .001;
1818
variable double timer;
19-
param r float elapsed "Current value of the internal timer";
19+
param r real elapsed "Current value of the internal timer";
2020
variable int timer_on;
2121
function update;
2222
license "GPL";
@@ -27,19 +27,19 @@ extern double fabs(double);
2727
if (timer_on) {
2828
timer += fperiod;
2929
}
30-
elapsed = timer;
30+
elapsed_set(timer);
3131
if(run) {
3232
if(!running) {
33-
running = 1;
34-
run_start = position_fb;
33+
running_set(1);
34+
run_start_set(position_fb);
3535

36-
if(dir == 2) run_high = run_start;
37-
else run_high = run_start + amplitude;
36+
if(dir == 2) run_high_set(run_start);
37+
else run_high_set(run_start + amplitude);
3838

39-
if(dir == 1) run_low = run_start;
40-
else run_low = run_start - amplitude;
39+
if(dir == 1) run_low_set(run_start);
40+
else run_low_set(run_start - amplitude);
4141

42-
position_cmd = run_low;
42+
position_cmd_set(run_low);
4343
}
4444

4545
if(fabs(position_fb - position_cmd) < epsilon) {
@@ -50,26 +50,26 @@ if(run) {
5050
} else if (timer >= pause) {
5151
timer_on = false;
5252
if(position_cmd == run_low) {
53-
position_cmd = run_high;
53+
position_cmd_set(run_high);
5454
} else {
55-
position_cmd = run_low;
55+
position_cmd_set(run_low);
5656
}
5757
}
5858
}
5959
}
6060
} else if(running) {
61-
position_cmd = run_start;
61+
position_cmd_set(run_start);
6262
if(fabs(position_fb - run_start) < epsilon) {
63-
running = 0;
63+
running_set(0);
6464
timer_on = false;
6565
}
6666
} else {
6767
if(jog_minus) {
68-
position_cmd = position_fb - 10;
68+
position_cmd_set(position_fb - 10);
6969
} else if(jog_plus) {
70-
position_cmd = position_fb + 10;
70+
position_cmd_set(position_fb + 10);
7171
} else {
72-
position_cmd = position_fb;
72+
position_cmd_set(position_fb);
7373
}
7474
}
7575

src/hal/components/biquad.comp

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -38,31 +38,31 @@ component biquad "Biquad IIR filter";
3838
description """Biquad IIR filter. Implements the following transfer function:
3939
H(z) = (n~0~ + n~1~z^-1^ + n~2~z^-2^) / (1 + d~1~z^-1^ + d~2~z^-2^)""";
4040

41-
pin in float in "Filter input.";
42-
pin out float out "Filter output.";
43-
pin in bit enable = 0 "Filter enable. When false, the *in* pin \
41+
pin in real in "Filter input.";
42+
pin out real out "Filter output.";
43+
pin in bool enable = 0 "Filter enable. When false, the *in* pin \
4444
is passed to the *out* pin without any filtering. \
4545
A *transition from false to true* causes filter \
4646
coefficients to be calculated according to the current \
4747
*type* and the describing pin and parameter settings";
48-
pin out bit valid = 0 "When false, indicates an error occurred when calculating \
48+
pin out bool valid = 0 "When false, indicates an error occurred when calculating \
4949
filter coefficients (require 2>**Q**>0.5 and *f0*>sampleRate/2)";
5050

51-
pin in u32 type_ = 0 "Filter type determines the type of filter \
51+
pin in ui32 type_ = 0 "Filter type determines the type of filter \
5252
coefficients calculated. When 0, coefficients must be loaded directly \
5353
from the *n0,n1,n2,d1* params. When 1, \
5454
a low pass filter is created specified by the *f0,Q* pins. \
5555
When 2, a notch filter is created specified by the *f0,Q* pins.";
56-
pin in float f0 = 250.0 "The corner frequency of the filter.";
57-
pin in float Q = 0.7071 "The Q of the filter.";
56+
pin in real f0 = 250.0 "The corner frequency of the filter.";
57+
pin in real Q = 0.7071 "The Q of the filter.";
5858

59-
param rw float d1 = 0.0 "1st-delayed denominator coef";
60-
param rw float d2 = 0.0 "2nd-delayed denominator coef";
61-
param rw float n0 = 1.0 "non-delayed numerator coef";
62-
param rw float n1 = 0.0 "1st-delayed numerator coef";
63-
param rw float n2 = 0.0 "2nd-delayed numerator coef";
64-
pin out float s1 = 0.0 "1st-delayed internal state (for debug only)";
65-
pin out float s2 = 0.0 "2nd-delayed internal state (for debug only)";
59+
param rw real d1 = 0.0 "1st-delayed denominator coef";
60+
param rw real d2 = 0.0 "2nd-delayed denominator coef";
61+
param rw real n0 = 1.0 "non-delayed numerator coef";
62+
param rw real n1 = 0.0 "1st-delayed numerator coef";
63+
param rw real n2 = 0.0 "2nd-delayed numerator coef";
64+
pin out real s1 = 0.0 "1st-delayed internal state (for debug only)";
65+
pin out real s2 = 0.0 "2nd-delayed internal state (for debug only)";
6666

6767
option data Internal;
6868
option extra_setup;
@@ -92,7 +92,7 @@ typedef enum {
9292

9393

9494
typedef struct {
95-
hal_bit_t lastEnable;
95+
rtapi_bool lastEnable;
9696
} Internal;
9797

9898

@@ -117,7 +117,7 @@ FUNCTION(_)
117117

118118
// If not direct coefficient loading.
119119
if(type_ != TYPE_DIRECT){
120-
valid = 0;
120+
valid_set(0);
121121

122122
sampleRate = 1.0 / (period * 1e-9);
123123

@@ -145,25 +145,26 @@ FUNCTION(_)
145145
break;
146146
}
147147

148-
n0 = b0 / a0;
149-
n1 = b1 / a0;
150-
n2 = b2 / a0;
151-
d1 = a1 / a0;
152-
d2 = a2 / a0;
153-
s1 = s2 = 0.0;
148+
n0_set(b0 / a0);
149+
n1_set(b1 / a0);
150+
n2_set(b2 / a0);
151+
d1_set(a1 / a0);
152+
d2_set(a2 / a0);
153+
s1_set(s2_set(0.0));
154154
}
155155

156-
valid = 1;
156+
valid_set(1);
157157
} while(0);
158158
}
159159

160160
if(!enable || !valid){
161-
out = in;
161+
out_set(in);
162162
}else{
163163
// Transposed direct form II.
164-
out = in * n0 + s1;
165-
s1 = in * n1 - out * d1 + s2;
166-
s2 = in * n2 - out * d2;
164+
rtapi_real in_ = in;
165+
out_set(in_ * n0 + s1);
166+
s1_set( in_ * n1 - out * d1 + s2);
167+
s2_set( in_ * n2 - out * d2);
167168
}
168169
}
169170

0 commit comments

Comments
 (0)