HAL Component Help
- Bend
- Offline
- New Member
Less
More
- Posts: 9
- Thank you received: 0
08 Jun 2020 14:09 #170645
by Bend
HAL Component Help was created by Bend
I am using LinuxCNC to run a machine at my plant, we are using a HAL Component to run the tool changer on the machine. Unfortunately it is a fairly complex change sequence with numerous sensors and safety's in place making it difficult to design.
Personally, i am new to HAL Component programming and don't know what i can and cant do. (I have found that it wont let me do functions, or for loops).
Wondering if there is any way to do a function call that i have missed for a tool change component?
Personally, i am new to HAL Component programming and don't know what i can and cant do. (I have found that it wont let me do functions, or for loops).
Wondering if there is any way to do a function call that i have missed for a tool change component?
Please Log in or Create an account to join the conversation.
- tommylight
- Away
- Moderator
Less
More
- Posts: 19516
- Thank you received: 6544
08 Jun 2020 14:15 #170648
by tommylight
Replied by tommylight on topic HAL Component Help
That is not enough info to be able to help properly, but did you try the "carousel" component?
There is also classic ladder that might help, and remap.
Some pictures of the tool changer and a brief explanation of how things function or are supposed to, would be helpful.
There is also classic ladder that might help, and remap.
Some pictures of the tool changer and a brief explanation of how things function or are supposed to, would be helpful.
Please Log in or Create an account to join the conversation.
- cmorley
- Offline
- Moderator
Less
More
- Posts: 7780
- Thank you received: 2075
08 Jun 2020 14:20 #170650
by cmorley
Replied by cmorley on topic HAL Component Help
HAL components must cycle through each time period.
Your component can't run continuously until the tool change is finished.
This dictates writing them as state machines.
It checks what the current state is, calculates what it should be next, sets the pins to reflect that, then ends until the next time period.
Maybe you could describe the problem sequence here and we could try to suggest a solution.
Chris
Your component can't run continuously until the tool change is finished.
This dictates writing them as state machines.
It checks what the current state is, calculates what it should be next, sets the pins to reflect that, then ends until the next time period.
Maybe you could describe the problem sequence here and we could try to suggest a solution.
Chris
The following user(s) said Thank You: tommylight, Aciera
Please Log in or Create an account to join the conversation.
- Bend
- Offline
- New Member
Less
More
- Posts: 9
- Thank you received: 0
08 Jun 2020 20:00 #170679
by Bend
Replied by Bend on topic HAL Component Help
The main issue that i am running into is that there are multiple places that i want to execute the same code. i.e. during a homing process i want to check that the locking pin is retracted, but i also want to do that in the tool change sequence... I was hoping to be able to write some code something like this:
...
...
...
WaitForLockingPinDisengage()
...
...
...
WaitForLockingPinDisengage(){
if (!lockingPinRetracted || lockingPinExtended){
break;
}
}
The main reason is that the locking pin for instance requires that the hydraulic pump is on, thus the WaitForLockingPinDisengage is actually this:
WaitForLockingPinDisengage(){
if(!commandHydPump == 1 || hydPumpPress <= 50){
commandHydPump = 1;
break;
}
if (!lockingPinRetracted || lockingPinExtended){
break;
}
}
Except, we have about 40 sensors that we care about all of which need to be verified in multiple places.
Thoughts?
...
...
...
WaitForLockingPinDisengage()
...
...
...
WaitForLockingPinDisengage(){
if (!lockingPinRetracted || lockingPinExtended){
break;
}
}
The main reason is that the locking pin for instance requires that the hydraulic pump is on, thus the WaitForLockingPinDisengage is actually this:
WaitForLockingPinDisengage(){
if(!commandHydPump == 1 || hydPumpPress <= 50){
commandHydPump = 1;
break;
}
if (!lockingPinRetracted || lockingPinExtended){
break;
}
}
Except, we have about 40 sensors that we care about all of which need to be verified in multiple places.
Thoughts?
Please Log in or Create an account to join the conversation.
- cmorley
- Offline
- Moderator
Less
More
- Posts: 7780
- Thank you received: 2075
08 Jun 2020 20:15 #170683
by cmorley
Replied by cmorley on topic HAL Component Help
You can definitely use for loops in comp.
I am looking for an example of a function call.
carousel.comp defines a function but seems to never call it.
I am looking for an example of a function call.
carousel.comp defines a function but seems to never call it.
Please Log in or Create an account to join the conversation.
- tommylight
- Away
- Moderator
Less
More
- Posts: 19516
- Thank you received: 6544
08 Jun 2020 20:21 #170685
by tommylight
Replied by tommylight on topic HAL Component Help
There are plenty of components to achieve nearly anything in Linuxcnc, but as far as i can understand from your posts, the best way of handling this is writing a new component that would incorporate all the interlocks and checks required.
Here is an example of such a component for THC control on plasma cuttersThis requires the dev part of LinuxCNC installed
sudo apt-get install linuxcnc-uspace-dev
if using the userspace version of Linuxcnc, or RT-Preempt version, and subsequently
sudo halcompile --install name_of_component.comp
The setting the connections in hal file.
Here is an example of such a component for THC control on plasma cutters
component torchud "Torch Up Down";
description
"""
torch up down by voltage calculated from encoder velocity
""";
license "GPLv2 or greater";
option singleton yes;
// Input Pins
pin in bit enable "enable up/down";
pin in float encoder_in "connect to encoder.nn.velocity";
pin in float voltage_offset "to set 0 volts";
pin in float voltage_scale "to set correct voltage";
pin in float setpoint "setpoint voltage";
pin in float tolerance "deviation from setpoint before up/down";
pin in float arc_ok_min "min voltage to generate arc ok signal";
pin in float arc_ok_max "max voltage to genarate arc ok signal";
// Output Pins
pin out float arc_voltage "calculated arc voltage";
pin out bit move_up "arc voltage is too low";
pin out bit move_down "arc voltage is too high";
pin out bit arc_ok "signal that arc volatage is ok";
function _;
;;
#include "rtapi_math.h"
FUNCTION(_) {
arc_voltage = (encoder_in - voltage_offset) * voltage_scale;
if(arc_voltage < 0){arc_voltage = 0;}
if(enable && arc_voltage > arc_ok_min && arc_voltage < arc_ok_max){
arc_ok = 1;
}else{
arc_ok = 0;
}
if(enable && arc_voltage > setpoint + tolerance && arc_voltage > arc_ok_min && arc_voltage < arc_ok_max){
move_down = 1;
}else{
move_down = 0;
}
if(enable && arc_voltage < setpoint - tolerance && arc_voltage > arc_ok_min && arc_voltage < arc_ok_max){
move_up = 1;
}else{
move_up = 0;
}
}
sudo apt-get install linuxcnc-uspace-dev
if using the userspace version of Linuxcnc, or RT-Preempt version, and subsequently
sudo halcompile --install name_of_component.comp
The setting the connections in hal file.
Please Log in or Create an account to join the conversation.
- cmorley
- Offline
- Moderator
Less
More
- Posts: 7780
- Thank you received: 2075
08 Jun 2020 20:25 #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.
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.
- tommylight
- Away
- Moderator
Less
More
- Posts: 19516
- Thank you received: 6544
08 Jun 2020 20:42 #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.
Thank you and sorry for the confusion.
Please Log in or Create an account to join the conversation.
- rodw
- Offline
- Platinum Member
Less
More
- Posts: 10820
- Thank you received: 3564
08 Jun 2020 21:00 #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.
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.
Instead, you need to program a state machine which is essentially a switch statement on a status variable.
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.
- Todd Zuercher
- Offline
- Platinum Member
Less
More
- Posts: 4957
- Thank you received: 1441
08 Jun 2020 21:17 #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.
Time to create page: 0.076 seconds