Skip to content

Commit 002fedd

Browse files
committed
trsrn: set the kinematics pins up once, at load
Both modules build their pins on the first kinematicsType() call and test an is_setup flag that nothing ever sets, so every later call runs the setup again. The second run reassigns haldata to a fresh block and then fails to create the pins that block points at, all of them already taken, so the module is left reading through null references and the next forward or inverse call takes realtime with it. Motion asks twice when num_extrajoints is greater than zero, once in rtapi_app_main and once in init_comm_buffers, so that combination cannot be running today. Latching the flag would stop the repeat, but the setup does not belong in a function whose job is to answer a question. halcompile has a hook for this, used by homecomp for the same reason: EXTRA_SETUP() runs once from the generated setup, before the component is made ready. So the pins exist from the moment the module is loaded, kinematicsType() only answers, and the hal_set_unready() and hal_ready() calls the old placement needed are gone with it.
1 parent cffa81d commit 002fedd

2 files changed

Lines changed: 10 additions & 10 deletions

File tree

‎src/hal/components/xyzacb_trsrn.comp‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ FIXME
77
""";
88
pin out si32 dummy=0 "dummy pin to satisfy halcompile";
99
option period no;
10+
option extra_setup;
1011

1112
license "GPL";
1213
author "David Mueller";
@@ -43,13 +44,14 @@ static struct haldata {
4344
} *haldata;
4445

4546

46-
static int xyzacb_trsrn_setup(void) {
47+
EXTRA_SETUP() {
48+
(void)__comp_inst;
49+
(void)prefix;
50+
(void)extra_arg;
4751
#define HAL_PREFIX "xyzacb_trsrn_kins"
4852
int res=0;
4953
// inherit comp_id from rtapi_main()
5054
if (comp_id < 0) goto error;
51-
// set unready to allow creation of pins
52-
if (hal_set_unready(comp_id)) goto error;
5355

5456
haldata = hal_malloc(sizeof(struct haldata));
5557
if (!haldata) goto error;
@@ -76,7 +78,6 @@ static int xyzacb_trsrn_setup(void) {
7678
res += hal_pin_new_bool(comp_id, HAL_OUT, &haldata->kinstype_is_2, 0, "kinstype.is-2");
7779

7880
if (res) goto error;
79-
hal_ready(comp_id);
8081
rtapi_print("*** %s setup ok\n",__FILE__);
8182
return 0;
8283
error:
@@ -136,8 +137,6 @@ int kinematicsSwitch(int new_switchkins_type)
136137

137138
KINEMATICS_TYPE kinematicsType()
138139
{
139-
static bool is_setup=0;
140-
if (!is_setup) xyzacb_trsrn_setup();
141140
return KINEMATICS_BOTH; // set as required
142141
// Note: If kinematics are identity, using KINEMATICS_BOTH
143142
// may be used in order to allow a gui to display

‎src/hal/components/xyzbca_trsrn.comp‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ FIXME
77
""";
88
pin out si32 dummy=0 "dummy pin to satisfy halcompile";
99
option period no;
10+
option extra_setup;
1011

1112
license "GPL";
1213
author "David Mueller";
@@ -43,7 +44,10 @@ static struct haldata {
4344
} *haldata;
4445

4546

46-
static int xyzbca_trsrn_setup(void) {
47+
EXTRA_SETUP() {
48+
(void)__comp_inst;
49+
(void)prefix;
50+
(void)extra_arg;
4751
#define HAL_PREFIX "xyzbca_trsrn_kins"
4852
int res=0;
4953
// inbherit comp_id from rtapi_main()
@@ -76,7 +80,6 @@ static int xyzbca_trsrn_setup(void) {
7680
res += hal_pin_new_bool(comp_id, HAL_OUT, &haldata->kinstype_is_2, 0, "kinstype.is-2");
7781

7882
if (res) goto error;
79-
hal_ready(comp_id);
8083
rtapi_print("*** %s setup ok\n",__FILE__);
8184
return 0;
8285
error:
@@ -136,8 +139,6 @@ int kinematicsSwitch(int new_switchkins_type)
136139

137140
KINEMATICS_TYPE kinematicsType()
138141
{
139-
static bool is_setup=0;
140-
if (!is_setup) xyzbca_trsrn_setup();
141142
return KINEMATICS_BOTH; // set as required
142143
// Note: If kinematics are identity, using KINEMATICS_BOTH
143144
// may be used in order to allow a gui to display

0 commit comments

Comments
 (0)