HAL Component Help

More
6 years 4 months ago #170688 by cmorley
Replied by cmorley on topic HAL Component Help
I think he understands how to make a component (he said he is using a custom one), he is asking how to organize the code to work as he would like.
Maybe i'll try to make a component with function calls to see if it works.
The following user(s) said Thank You: tommylight

Please Log in or Create an account to join the conversation.

More
6 years 4 months ago #170691 by tommylight
Replied by tommylight on topic HAL Component Help
I thought so from his code, but was not sure.
Thank you and sorry for the confusion.

Please Log in or Create an account to join the conversation.

More
6 years 4 months ago #170694 by rodw
Replied by rodw on topic HAL Component Help
You can call functions but you can't call blocking functions which is what waitforlocking() seems to be.
Instead, you need to program a state machine which is essentially a switch statement on a status variable.
Code:
static int state = WAITING; switch(state){ case WAITING: if(locked) // ask for tool change state = LOCKED; break; case LOCKED: if(changed) state = CHANGED; break; }

The attached example shows an example state machine and also a function that calculates a moving average. (It would be easy to program this by using a loop but that blocks so there is a convoluted way to calculate this without a loop)

Remember, that the servo thread is essentially a timer interrupt service routine and you cannot block an interrupt becasue all components must be serviced in that 1 millisecond between invocations. Short, sharp and sweet is the way to do this.

Please Log in or Create an account to join the conversation.

More
6 years 4 months ago #170697 by Todd Zuercher
Replied by Todd Zuercher on topic HAL Component Help
Another option, if you are comfortable programming ladder logic, is to use Classicladder.

Please Log in or Create an account to join the conversation.

More
6 years 4 months ago #170721 by cmorley
Replied by cmorley on topic HAL Component Help
here is a fairly minimum component to show extra functions.
Though it seems you can't reference HAL pins in the functions
Code:
component test1; pin in s32 in; pin out bit out1; pin out bit out2; function _; license "GPL"; ;; // private functions int set(void){ return 1; } int unset(void){ return 0; } //main function FUNCTION(_) { if (in ==1){ out1 = set(); out2 = unset(); } if (in ==2){ out1 = unset(); out2 = set(); } }

Please Log in or Create an account to join the conversation.

More
6 years 4 months ago #170761 by cmorley
Replied by cmorley on topic HAL Component Help
Similar that passes HAL bit pin reference to the function:
Code:
component test1; pin in s32 in; pin out bit out1; pin out bit out2; function _; license "GPL"; ;; // general pin setting function void set(hal_bit_t *p){ *p = 1; } // general pin unsetting function void unset(hal_bit_t *p){ *p = 0; } //main function FUNCTION(_) { if (in < 0){ set(&out1); unset(&out2); }else if (in >0){ unset(&out2); set(&out2); }else{ unset(&out1); unset(&out2); } }

I'm hoping this helps you ...
The following user(s) said Thank You: Bend

Please Log in or Create an account to join the conversation.

Time to create page: 0.377 seconds
Powered by Kunena Forum