A axis and spindle together
- grandixximo
- Topic Author
- Offline
- Premium Member
Less
More
- Posts: 132
- Thank you received: 5
07 Oct 2013 13:17 - 07 Oct 2013 13:19 #39610
by grandixximo
A axis and spindle together was created by grandixximo
Hi everyone, i'm trying to get a spindle to work as axis A and as the spindle out of the same two pins for step and dir, i already did this with the parport, i'm trying now with the MESA 5i25 card
What i did before was creating a pwmgen and a stepgen, then send them into an or gate, and the output was sent directly to the pin for the spindle steps.
For the direction there where some gates involved so that i could manipulate the direction to follow either the spindle or the axis direction, by looking at weather the spindle was on or off. this worked pretty well i just had to zero and home again everytime i was going to use A as an axis.
But now i can't hijack the connection between the pwmgen and the pins, or stepgen and the pins, so i'm kinda stuck..
i have tough to try and use a stepgen, and switching mode from vel mode to position mode
this way moving A works fine, but when i turn the spindle on, the feed back position will start counting as the spindle turns, and when i stop the spindle, and switch back to position mode, the spindle will go back to wathever the commanded position was, i'd like it to just stay where it is, i'll home the axis before i use anyway.
also this way the spindle cannot turn for too long or i'll have following errors.
Is there a way that this can be avoided.
Maybe i'm just connecting stuff the wrong way.
I'd just like for the feedback to be disabled, at least while i'm working in velocity mode with the axis.
I've think about disabling the axis.enabled with comp untill the count is resetted back so that fb is same as cmd position, but that will take way too long if the spindle was on for 20 minutes or so, i'm not sure it will even count while the axis is disabled
is there a way to make the cmd position follow the vel mode?
or a reset of the axis when i do the switch?
is there any other solution to use a spindle as a fourth axis and as a spindle out of the same pins?
What i did before was creating a pwmgen and a stepgen, then send them into an or gate, and the output was sent directly to the pin for the spindle steps.
For the direction there where some gates involved so that i could manipulate the direction to follow either the spindle or the axis direction, by looking at weather the spindle was on or off. this worked pretty well i just had to zero and home again everytime i was going to use A as an axis.
But now i can't hijack the connection between the pwmgen and the pins, or stepgen and the pins, so i'm kinda stuck..
i have tough to try and use a stepgen, and switching mode from vel mode to position mode
this way moving A works fine, but when i turn the spindle on, the feed back position will start counting as the spindle turns, and when i stop the spindle, and switch back to position mode, the spindle will go back to wathever the commanded position was, i'd like it to just stay where it is, i'll home the axis before i use anyway.
also this way the spindle cannot turn for too long or i'll have following errors.
Is there a way that this can be avoided.
Maybe i'm just connecting stuff the wrong way.
I'd just like for the feedback to be disabled, at least while i'm working in velocity mode with the axis.
I've think about disabling the axis.enabled with comp untill the count is resetted back so that fb is same as cmd position, but that will take way too long if the spindle was on for 20 minutes or so, i'm not sure it will even count while the axis is disabled
is there a way to make the cmd position follow the vel mode?
or a reset of the axis when i do the switch?
is there any other solution to use a spindle as a fourth axis and as a spindle out of the same pins?
Last edit: 07 Oct 2013 13:19 by grandixximo.
Please Log in or Create an account to join the conversation.
- andypugh
- Offline
- Moderator
Less
More
- Posts: 23310
- Thank you received: 4858
07 Oct 2013 20:04 #39616
by andypugh
As you have noticed, you can't intercept the signals after the stepgen, so you will have to use the same stepgen for both modes.
Luckily the Hostmot2 stepgen has a pin called "control type" and you can switch that between modes in HAL.
So, it is _almost_ as simple as connecting motion.spindle-speed-out to hm2_5i25.0.stepgen.3.velocity-cmd and axis.3.motor-pos-cmd to hm2_5i25.0.stepgen.3.position-cmd.
The problem, as you have noticed, is that if you have been running as a spindle for a while, then either the A-axis will give a following error, or when you switch back to A-axis mode the stepgen will want to "unwind" all the previous rotations.
I think that the solution is to use a pair of "offset" functions between the axis-pos-cmd pin and the stepgen-cmd pin, and between the stepgen-fb pin and the axis-fb pin (wired in different directions). www.linuxcnc.org/docs/html/man/man9/offset.9.html
They both need to use the same "offset" value. But it is no good if this value changes while in position mode. So, the "offset" value needs to be latched with a "sample-hold" function:
Unfortunately the sample-hold function in HAL is inconveniently s32 datatype, not floating-point. So the trick is to wire a mux2 to behave like a sample-hold: This just means wiring the output so that it goes back to one of the inputs. www.linuxcnc.org/docs/html/man/man9/mux2.9.html
While mux2.0.sel = 0 the output will update to follow mux2.0.in0. When the sel=1 the output will follow in1, which is wired back to input, so holds the value.
I can try to write a sample config if you can't figure it out from the above, but I would need access to a LinuxCNC machine to have any confidence in getting it right.
Now, one interesting wrinkle in the above system is that the effective "zero" position of the A axis will move. when you switch between modes. The way round this is to feed the sample-hold with a
"rounded down" version of the position. One way to do this is to divide by a "full turn", convert to integer, then convert back to float and multiply up again.
There is probably a case to be made for a modulo/remainder HAL component.
Though, if you are going to write a custom HAL component it might as well handle the both-ways feedback and the sample-hold part too...
Replied by andypugh on topic A axis and spindle together
Hi everyone, i'm trying to get a spindle to work as axis A and as the spindle out of the same two pins for step and dir, i already did this with the parport, i'm trying now with the MESA 5i25 card
As you have noticed, you can't intercept the signals after the stepgen, so you will have to use the same stepgen for both modes.
Luckily the Hostmot2 stepgen has a pin called "control type" and you can switch that between modes in HAL.
So, it is _almost_ as simple as connecting motion.spindle-speed-out to hm2_5i25.0.stepgen.3.velocity-cmd and axis.3.motor-pos-cmd to hm2_5i25.0.stepgen.3.position-cmd.
The problem, as you have noticed, is that if you have been running as a spindle for a while, then either the A-axis will give a following error, or when you switch back to A-axis mode the stepgen will want to "unwind" all the previous rotations.
I think that the solution is to use a pair of "offset" functions between the axis-pos-cmd pin and the stepgen-cmd pin, and between the stepgen-fb pin and the axis-fb pin (wired in different directions). www.linuxcnc.org/docs/html/man/man9/offset.9.html
They both need to use the same "offset" value. But it is no good if this value changes while in position mode. So, the "offset" value needs to be latched with a "sample-hold" function:
Unfortunately the sample-hold function in HAL is inconveniently s32 datatype, not floating-point. So the trick is to wire a mux2 to behave like a sample-hold: This just means wiring the output so that it goes back to one of the inputs. www.linuxcnc.org/docs/html/man/man9/mux2.9.html
While mux2.0.sel = 0 the output will update to follow mux2.0.in0. When the sel=1 the output will follow in1, which is wired back to input, so holds the value.
I can try to write a sample config if you can't figure it out from the above, but I would need access to a LinuxCNC machine to have any confidence in getting it right.
Now, one interesting wrinkle in the above system is that the effective "zero" position of the A axis will move. when you switch between modes. The way round this is to feed the sample-hold with a
"rounded down" version of the position. One way to do this is to divide by a "full turn", convert to integer, then convert back to float and multiply up again.
There is probably a case to be made for a modulo/remainder HAL component.
component modulo "returns the modulus and the rounded versions of the input";
pin in float in;
pin in float divisor;
pin out float modulus;
pin out float rounded;
function _;
license "GPL"
;;
modulus = in % divisor;
rounded = in - modulus;
Though, if you are going to write a custom HAL component it might as well handle the both-ways feedback and the sample-hold part too...
Please Log in or Create an account to join the conversation.
- cncbasher
- Offline
- Moderator
Less
More
- Posts: 1766
- Thank you received: 292
07 Oct 2013 21:34 #39618
by cncbasher
Replied by cncbasher on topic A axis and spindle together
i would also be interested in this , so i'm following the thread
Please Log in or Create an account to join the conversation.
- grandixximo
- Topic Author
- Offline
- Premium Member
Less
More
- Posts: 132
- Thank you received: 5
08 Oct 2013 09:15 - 08 Oct 2013 16:07 #39635
by grandixximo
Replied by grandixximo on topic A axis and spindle together
can't really wrap my head around what you wrote.
two things I don't get, one should the offsets be connected like this?
net a-pos-fb axis.3.motor-pos-fb <= offset.1.out
net a-fb-to-offset hm2_5i25.0.stepgen.03.position-fb => offset.1.in
net a-cmd-to-offset axis.3.motor-pos-cmd => offset.0.in
net a-pos-cmd hm2_5i25.0.stepgen.03.position-cmd <= offset.0.out
net a-enable axis.3.amp-enable-out => hm2_5i25.0.stepgen.03.enable
or offset.1.out need to be swapped with offset.0.out ???
then you write about the offset value, but where do i get the value ????
net offset-value mux2.0.out offset.0.offset offset.1.offset mux2.0.in0
I wrote this line which would be the loop to make the mux hold the value
but the mux2.0.in1 which is the offset value, what should it be connected to?
Edit:
I don't think the offset value should be same for feed back and for commanded position.
With the Hal connected in the easy way you described at first, with the switch of step gen type from velocity to position.
Let's say A is moved from 0 to 10 in position mode, feedback also will go to 10, then switch to velocity mode and spin the spindle till it's to 100. now feedback it's 100 but the commanded position it's still 10, this makes the mesa card unwind the motor back to 10 when you go back to position mode.
So to fix this I would need to add 90 to the axis commanded position, for it to reach 100, so the mesa card won't wind back, because commanded position is same to the feedback from the mesa.
But while the spindle is spinning I also need to subtract gradually till I get to 90 from the mesa card feedback so that my axis position feedback is always 10 like I have commanded, and I won't occur in following errors.
Maybe I'm just too naive and I'm missing where to get the value to regulate the commanded position and the feed back position, I tried to use the feedback as the value, but it's not working.
Anyway, I have tough really hard about this and the only logical solution to me is while in velocity mode get the value of how much the mesa feedback is changing, then add this value to the axis commanded position and send it to the mesa commanded position, at the same time this value is subtracted from the mesa feedback, and sent to the axis feedback.
and this value should be held while the spindle is in position mode, if I'm not missing anything this should work, at least it does in my mind.
I think it's different than what you were talking about, and I hope I'm not totally wrong, also I hope you can find a way to implement it in Hal, because I can't think of a way to do it with the Hal components I know.
two things I don't get, one should the offsets be connected like this?
net a-pos-fb axis.3.motor-pos-fb <= offset.1.out
net a-fb-to-offset hm2_5i25.0.stepgen.03.position-fb => offset.1.in
net a-cmd-to-offset axis.3.motor-pos-cmd => offset.0.in
net a-pos-cmd hm2_5i25.0.stepgen.03.position-cmd <= offset.0.out
net a-enable axis.3.amp-enable-out => hm2_5i25.0.stepgen.03.enable
or offset.1.out need to be swapped with offset.0.out ???
then you write about the offset value, but where do i get the value ????
net offset-value mux2.0.out offset.0.offset offset.1.offset mux2.0.in0
I wrote this line which would be the loop to make the mux hold the value
but the mux2.0.in1 which is the offset value, what should it be connected to?
Edit:
I don't think the offset value should be same for feed back and for commanded position.
With the Hal connected in the easy way you described at first, with the switch of step gen type from velocity to position.
Let's say A is moved from 0 to 10 in position mode, feedback also will go to 10, then switch to velocity mode and spin the spindle till it's to 100. now feedback it's 100 but the commanded position it's still 10, this makes the mesa card unwind the motor back to 10 when you go back to position mode.
So to fix this I would need to add 90 to the axis commanded position, for it to reach 100, so the mesa card won't wind back, because commanded position is same to the feedback from the mesa.
But while the spindle is spinning I also need to subtract gradually till I get to 90 from the mesa card feedback so that my axis position feedback is always 10 like I have commanded, and I won't occur in following errors.
Maybe I'm just too naive and I'm missing where to get the value to regulate the commanded position and the feed back position, I tried to use the feedback as the value, but it's not working.
Anyway, I have tough really hard about this and the only logical solution to me is while in velocity mode get the value of how much the mesa feedback is changing, then add this value to the axis commanded position and send it to the mesa commanded position, at the same time this value is subtracted from the mesa feedback, and sent to the axis feedback.
and this value should be held while the spindle is in position mode, if I'm not missing anything this should work, at least it does in my mind.
I think it's different than what you were talking about, and I hope I'm not totally wrong, also I hope you can find a way to implement it in Hal, because I can't think of a way to do it with the Hal components I know.
Last edit: 08 Oct 2013 16:07 by grandixximo.
Please Log in or Create an account to join the conversation.
- andypugh
- Offline
- Moderator
Less
More
- Posts: 23310
- Thank you received: 4858
08 Oct 2013 16:32 #39643
by andypugh
It probably needs to be the difference between A-axis command and Stepgen feedback while in spindle mode, and be frozen at the last value in A-axis mode.
To calculate a difference you need to use the Sum2 function (which is an adder) but with the "gain" pin of one of the inputs set to -1.
Replied by andypugh on topic A axis and spindle together
That is what I was expecting, yes.two things I don't get, one should the offsets be connected like this?
net a-pos-fb axis.3.motor-pos-fb <= offset.1.out net a-fb-to-offset hm2_5i25.0.stepgen.03.position-fb => offset.1.in net a-cmd-to-offset axis.3.motor-pos-cmd => offset.0.in net a-pos-cmd hm2_5i25.0.stepgen.03.position-cmd <= offset.0.out
In the simplest version, I was thinking that it should be the stepgen feedback position. But thinking some more, that is probably not be right (as you noticed)then you write about the offset value, but where do i get the value ????
It probably needs to be the difference between A-axis command and Stepgen feedback while in spindle mode, and be frozen at the last value in A-axis mode.
To calculate a difference you need to use the Sum2 function (which is an adder) but with the "gain" pin of one of the inputs set to -1.
Please Log in or Create an account to join the conversation.
- grandixximo
- Topic Author
- Offline
- Premium Member
Less
More
- Posts: 132
- Thank you received: 5
08 Oct 2013 16:52 #39646
by grandixximo
Replied by grandixximo on topic A axis and spindle together
I'm glad at least you seem to agree withy theory. I did try the sum2 with -1 gain.
But i think o screwed with the invert component when i used it to invert the value to remove it from the feedbak.
In a couple of hours ill try again with two sum2 I think it'll work. I really hope it does...
But i think o screwed with the invert component when i used it to invert the value to remove it from the feedbak.
In a couple of hours ill try again with two sum2 I think it'll work. I really hope it does...
Please Log in or Create an account to join the conversation.
- grandixximo
- Topic Author
- Offline
- Premium Member
Less
More
- Posts: 132
- Thank you received: 5
08 Oct 2013 18:30 #39651
by grandixximo
Replied by grandixximo on topic A axis and spindle together
It works indeed, i just needed a push in the right direction thanks
and the mux.0.sel is connected right now to a comp equal pin reversed with not, that check when the spindle is ramped to 0, as long as my ramp is slightly slower than the axis it should work fine.
during the first test the spindle went at high rpm suddenly when i moved the axis, i think i didn't wait for the spindle to come to a complete stop.
so must wait for the spindle to come to a complete stop before doing the switch, as long as i respect that it's working.
the A feedback displayed on axis interface changes a little while spinning the spindle due to following error, but when spindle is stopped it ges back to the value it was.
net a-pos-fb axis.3.motor-pos-fb <= offset.1.fb-out
net a-fb-to-offset hm2_5i25.0.stepgen.03.position-fb => offset.1.fb-in => sum2.0.in0
net a-cmd-to-offset axis.3.motor-pos-cmd => offset.0.in => sum2.0.in1
net a-pos-cmd hm2_5i25.0.stepgen.03.position-cmd <= offset.0.out
net a-enable axis.3.amp-enable-out => hm2_5i25.0.stepgen.03.enable
net offset-value mux2.0.out offset.0.offset offset.1.offset mux2.0.in0
setp sum2.0.gain1 -1
net offset-value2 mux2.0.in1 <= sum2.0.out
and the mux.0.sel is connected right now to a comp equal pin reversed with not, that check when the spindle is ramped to 0, as long as my ramp is slightly slower than the axis it should work fine.
during the first test the spindle went at high rpm suddenly when i moved the axis, i think i didn't wait for the spindle to come to a complete stop.
so must wait for the spindle to come to a complete stop before doing the switch, as long as i respect that it's working.
the A feedback displayed on axis interface changes a little while spinning the spindle due to following error, but when spindle is stopped it ges back to the value it was.
Please Log in or Create an account to join the conversation.
Time to create page: 0.059 seconds