@@ -155,11 +155,56 @@ static void custom_write_homing_out_pins(int njoints)
155155
156156static int custom_1joint_state_machine(int joint_num)
157157{
158- // custom: always homed
159- H[joint_num].homing = 0;
160- H[joint_num].homed = 1;
161- H[joint_num].home_state = HOME_IDLE;
162- return 0;
158+ typedef enum {
159+ CUSTOM_IDLE = 0,
160+ CUSTOM_1 = 1,
161+ CUSTOM_2 = 2,
162+ CUSTOM_3 = 3,
163+ CUSTOM_4 = 4,
164+ CUSTOM_FINI = 5,
165+ } custom_home_state_t;
166+
167+ static custom_home_state_t chomestate[EMCMOT_MAX_JOINTS] = {0};
168+ custom_home_state_t nextcstate;
169+
170+ #define C_SHOW \
171+ rtapi_print("H[%d].homed=%d,homing=%d,home_state=%d chomestate[%d]=%d next=%d\n" \
172+ ,joint_num,H[joint_num].homed,H[joint_num].homing,H[joint_num].home_state \
173+ ,joint_num,chomestate[joint_num],nextcstate);
174+
175+ if ( H[joint_num].home_state == HOME_IDLE) return 0; // nothing to do
176+
177+ if ((H[joint_num].home_state == HOME_START) && (chomestate[joint_num] == CUSTOM_IDLE) ) {
178+ H[joint_num].homing = 1;
179+ H[joint_num].homed = 0;
180+ chomestate[joint_num] = CUSTOM_1; // set first non-idle custom_home_state
181+ }
182+ // For this example, just walk thru custom_home_states with prints.
183+ // Note: remains in the base home_state: HOME_START for all custom_home_states.
184+ // On completion, return to HOME_IDLE, CUSTOM_IDLE states.
185+ switch (chomestate[joint_num]) {
186+ case CUSTOM_1:
187+ // Each CUSTOM_* state should do something and/or check something
188+ // and set nexstcstate according to the design goals.
189+ // Halpin variables can be read and/or set for next write.
190+ nextcstate=CUSTOM_2; C_SHOW; chomestate[joint_num] = nextcstate; break;
191+ case CUSTOM_2: nextcstate=CUSTOM_3; C_SHOW; chomestate[joint_num] = nextcstate; break;
192+ case CUSTOM_3: nextcstate=CUSTOM_4; C_SHOW; chomestate[joint_num] = nextcstate; break;
193+ case CUSTOM_4: nextcstate=CUSTOM_FINI; C_SHOW; chomestate[joint_num] = nextcstate; break;
194+ case CUSTOM_FINI:
195+ H[joint_num].homing = 0;
196+ H[joint_num].homed = 1;
197+ H[joint_num].home_state = HOME_IDLE;
198+ nextcstate = CUSTOM_IDLE;
199+ C_SHOW;
200+ chomestate[joint_num] = nextcstate;
201+ return 0; // finished custom_home_states
202+ break;
203+ case CUSTOM_IDLE:
204+ default: rtapi_print("Unhandled custom_home_state: %d\n",chomestate[joint_num]);
205+ }
206+ return 1; // return 1 if busy
207+ #undef C_SHOW
163208} // custom_1joint_state_machine()
164209
165210// api functions below augment base_*() functions with custom code
0 commit comments