Skip to content

Commit b818171

Browse files
committed
kinemmatics w halcompile, hal_set_unready()
Prior to this commit, the comp files used to demonstrate creation of a kinematics module with halcompile instantiated an auxiliary component instance using hal_init(). This instance is not loadable with loadrt (its primary purpose is to provide pins for kinematics functions). However, without using a loadrt for the auxiliary component instance, confusing messages were reported at program exit. typ: userkinsdata: not loaded <commandline>:0: exit value: 255 <commandline>:0: rmmod failed, returned -1 <commandline>:0: unloadrt failed This commit uses a new function (hal_set_unready()) to allow the kinematics module to create pins that are added to the parent component without causing messages on exit. Update kinematics modules (userkins.comp,millturn.comp) to: 0) eliminate auxiliary component instance by using hal_set_unready() followed by reissue hal_ready() 1) incorporate a conventional function 'fdemo' that can be added (addf) to a thread for demonstration 2) rename 'dummy' pin to 'fpin' and test in the 'fdemo' function 3) rename var 'is_homed' to 'is_ready' for clarity as use depends on kinematics type
1 parent c2011bf commit b818171

4 files changed

Lines changed: 69 additions & 26 deletions

File tree

src/hal/components/millturn.comp

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ switchable kinematics in particular see the switchkins document
2828
chapter (docs/src/motion/switchkins.txt)
2929

3030
""";
31-
// The halcompile utility requires a pin definition but
32-
// the dummy pin is not accessible in kinematics functions.
33-
// Use the *_setup() function for actual pins and params.
34-
pin out bit dummy=1;
31+
// The fpin pin is not accessible in kinematics functions.
32+
// Use the *_setup() function for pins and params used by kinematics.
33+
pin out s32 fpin=0"pin to demonstrate use of a conventional (non-kinematics) function fdemo";
34+
function fdemo;
3535
license "GPL";
3636
author "David Mueller";
3737
;;
@@ -52,13 +52,24 @@ static struct haldata {
5252
hal_bit_t *kinstype_is_1;
5353
} *haldata;
5454

55+
FUNCTION(fdemo) {
56+
// This function can be added to a thread (addf) for
57+
// purposes not related to the kinematics functions.
58+
if (fpin == 0) {
59+
rtapi_print("fdemo function added to thread\n");
60+
}
61+
fpin++;
62+
}
63+
5564
static int millturn_setup(void) {
5665
#define HAL_PREFIX "millturn"
5766
int res=0;
58-
int comp_id;
59-
// this name must be different than the component name:
60-
comp_id = hal_init("millturndata");
67+
68+
// inherit comp_id from rtapi_main()
6169
if (comp_id < 0) goto error;
70+
// set unready to allow creation of pins
71+
if (hal_set_unready(comp_id)) goto error;
72+
6273
haldata = hal_malloc(sizeof(struct haldata));
6374
if (!haldata) goto error;
6475

@@ -133,7 +144,7 @@ static bool is_setup=0;
133144
// joint values in preview prior to homing
134145
} // kinematicsType()
135146

136-
static bool is_homed=0;
147+
static bool is_ready=0;
137148
int kinematicsForward(const double *j,
138149
EmcPose * pos,
139150
const KINEMATICS_FORWARD_FLAGS * fflags,
@@ -163,9 +174,9 @@ int kinematicsForward(const double *j,
163174
pos->v = 0;
164175
pos->w = 0;
165176

166-
if (*haldata->in && !is_homed && !gave_msg) {
177+
if (*haldata->in && !is_ready && !gave_msg) {
167178
rtapi_print_msg(RTAPI_MSG_ERR,
168-
"%s in pin not echoed until homed\n",
179+
"%s the 'in' pin not echoed until Inverse called\n",
169180
__FILE__);
170181
gave_msg=1;
171182
}
@@ -177,7 +188,7 @@ int kinematicsInverse(const EmcPose * pos,
177188
const KINEMATICS_INVERSE_FLAGS * iflags,
178189
KINEMATICS_FORWARD_FLAGS * fflags)
179190
{
180-
is_homed = 1; // Inverse is not called until homed
191+
is_ready = 1; // Inverse is not called until homed for KINEMATICS_BOTH
181192

182193
// Update the kinematic joints specified by the
183194
// [KINS]JOINTS setting (4 required for this template).

src/hal/components/userkins.comp

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,19 @@ kinematics for an xyz machine employing 3 joints
5050
'userkins' to 'mykins'
5151

5252
\\fBNOTES:\\fR
53-
1 A 'dummy' pin is required to satisfy the requirements of
54-
the halcompile utility but it is not accessible to
55-
kinematics functions.
53+
1 The \\fBfpin\\fR pin is included to satisfy the requirements of
54+
the halcompile utility but it is not accessible to kinematics
55+
functions.
5656

5757
2 Hal pins and parameters needed in kinematics functions
5858
(kinematicsForward(), kinematicsInverse()) must
59-
be setup in a function (userkins_setup()) invoked
59+
be setup in a function (\\fBuserkins_setup()\\fR) invoked
6060
by the initial motion module call to kinematicsType().
6161
""";
62-
// The halcompile utility requires a pin definition but
63-
// the dummy pin is not accessible in kinematics functions.
64-
// Use the *_setup() function for actual pins and params.
65-
pin out bit dummy=1;
62+
// The fpin pin is not accessible in kinematics functions.
63+
// Use the *_setup() function for pins and params used by kinematics.
64+
pin out s32 fpin=0"pin to demonstrate use of a conventional (non-kinematics) function fdemo";
65+
function fdemo;
6666
license "GPL";
6767
author "Dewey Garrett";
6868
;;
@@ -84,13 +84,24 @@ static struct haldata {
8484
// hal_s32_t signed 32bit integer
8585
// hal_float_t float (double precision)
8686

87+
FUNCTION(fdemo) {
88+
// This function can be added to a thread (addf) for
89+
// purposes not related to the kinematics functions.
90+
if (fpin == 0) {
91+
rtapi_print("fdemo function added to thread\n");
92+
}
93+
fpin++;
94+
}
95+
8796
static int userkins_setup(void) {
8897
#define HAL_PREFIX "userkins"
8998
int res=0;
90-
int comp_id;
91-
// this name must be different than the component name:
92-
comp_id = hal_init("userkinsdata");
99+
100+
// inherit comp_id from rtapi_main()
93101
if (comp_id < 0) goto error;
102+
// set unready to allow creation of pins
103+
if (hal_set_unready(comp_id)) goto error;
104+
94105
haldata = hal_malloc(sizeof(struct haldata));
95106
if (!haldata) goto error;
96107

@@ -129,7 +140,7 @@ static bool is_setup=0;
129140
// joint values in preview prior to homing
130141
} // kinematicsType()
131142

132-
static bool is_homed=0;
143+
static bool is_ready=0;
133144
int kinematicsForward(const double *j,
134145
EmcPose * pos,
135146
const KINEMATICS_FORWARD_FLAGS * fflags,
@@ -148,9 +159,9 @@ int kinematicsForward(const double *j,
148159
pos->v = 0;
149160
pos->w = 0;
150161

151-
if (*haldata->in && !is_homed && !gave_msg) {
162+
if (*haldata->in && !is_ready && !gave_msg) {
152163
rtapi_print_msg(RTAPI_MSG_ERR,
153-
"%s in pin not echoed until homed\n",
164+
"%s The 'in' pin not echoed until Inverse called\n",
154165
__FILE__);
155166
gave_msg=1;
156167
}
@@ -162,7 +173,7 @@ int kinematicsInverse(const EmcPose * pos,
162173
const KINEMATICS_INVERSE_FLAGS * iflags,
163174
KINEMATICS_FORWARD_FLAGS * fflags)
164175
{
165-
is_homed = 1; // Inverse is not called until homed
176+
is_ready = 1; // Inverse is not called until homed for KINEMATICS_BOTH
166177

167178
// Update the kinematic joints specified by the
168179
// [KINS]JOINTS setting (3 required for this template).

src/hal/hal.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,14 @@ extern void *hal_malloc(long int size);
217217
*/
218218
extern int hal_ready(int comp_id);
219219

220+
/** hal_set_unready() sets a component state to unready so
221+
additional pins can be added. A subsequent call to
222+
hal_ready() must be issued to make the component ready
223+
again. Kinematics modules created with halcompile use
224+
this function to add pins to a parent component.
225+
*/
226+
extern int hal_set_unready(int comp_id);
227+
220228
/** hal_unready() indicates that this component is ready. This allows
221229
halcmd 'loadusr -W hal_example' to wait until the userspace
222230
component 'hal_example' is ready before continuing.

src/hal/hal_lib.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,18 @@ int hal_set_constructor(int comp_id, constructor make) {
429429
}
430430
#endif
431431

432+
int hal_set_unready(int comp_id) {
433+
hal_comp_t *comp;
434+
rtapi_mutex_get(&(hal_data->mutex));
435+
comp = halpr_find_comp_by_id(comp_id);
436+
if (comp) { comp->ready = 0; }
437+
rtapi_mutex_give(&(hal_data->mutex));
438+
if (comp) {return 0;}
439+
rtapi_print_msg(RTAPI_MSG_ERR,
440+
"HAL: ERROR: hal_set_unready(): component %d not found\n", comp_id);
441+
return -EINVAL;
442+
}
443+
432444
int hal_ready(int comp_id) {
433445
int next;
434446
hal_comp_t *comp;
@@ -4191,6 +4203,7 @@ int hal_stream_num_underruns(hal_stream_t *stream) {
41914203

41924204
EXPORT_SYMBOL(hal_init);
41934205
EXPORT_SYMBOL(hal_ready);
4206+
EXPORT_SYMBOL(hal_set_unready);
41944207
EXPORT_SYMBOL(hal_exit);
41954208
EXPORT_SYMBOL(hal_malloc);
41964209
EXPORT_SYMBOL(hal_comp_name);

0 commit comments

Comments
 (0)