- LinuxCNC
- General LinuxCNC Questions
- Need a bit of help with a Raspberry PI 4 GPIO Glass scales control loop
Need a bit of help with a Raspberry PI 4 GPIO Glass scales control loop
- yagias
- Offline
- Junior Member
Less
More
- Posts: 21
- Thank you received: 0
19 Feb 2021 15:10 #199445
by yagias
Need a bit of help with a Raspberry PI 4 GPIO Glass scales control loop was created by yagias
Hello
This being my first post and the fact that I’m yet another newbie at Linuxcnc i do hope you’ll bear with me.
The scenario is as follows.
- Sieg X2 mini mill converted with ballscrews etc.
- Raspberry Pi 4 running direct using hal_pi_gpio
- 5 micron glass scales are mounted. (well one of them is)
I have the basic setup working e.g. X,Y,Z movement and i have the first glass scale encoder feeding back into Linuxcnc with correct scaling Encoder.0 . (as well as a rotary encoder controlling feed override in gmoccapy Encoder.1)
Now… I spent days trying to figure out how to implement the PID control loop between the X axis and the glass scale with no success. It may very well be me but as i said i cannot for the life of me figure it out and am in need of a bit of help.
If one of you experienced guys could point out to me what i need to add to hal and ini and what components to connect to what I’d be downright happy .
__________________________________________________________________________________
Having gone over quite a few forum posts regarding the raspberry pi I’ll go ahead and answer a couple of questions right away.
Yes I know it’ll be slow (step and encoder read speed). But it’s fast enough for my purposes.
This is a small not very rigid machine and reading the glass scales keeps up just fine at the maximum speed I’m ever going to run it at.
Yes I’m aware that this would likely be easier if I just bought a Mesa card.
So much so that i went ahead and bought one. I did however get caught up in this Raspberry thing where I’d really like to see it run without it. And i can’t help but feel i’m really close.
Best
/Yagias
This being my first post and the fact that I’m yet another newbie at Linuxcnc i do hope you’ll bear with me.
The scenario is as follows.
- Sieg X2 mini mill converted with ballscrews etc.
- Raspberry Pi 4 running direct using hal_pi_gpio
- 5 micron glass scales are mounted. (well one of them is)
I have the basic setup working e.g. X,Y,Z movement and i have the first glass scale encoder feeding back into Linuxcnc with correct scaling Encoder.0 . (as well as a rotary encoder controlling feed override in gmoccapy Encoder.1)
Now… I spent days trying to figure out how to implement the PID control loop between the X axis and the glass scale with no success. It may very well be me but as i said i cannot for the life of me figure it out and am in need of a bit of help.
If one of you experienced guys could point out to me what i need to add to hal and ini and what components to connect to what I’d be downright happy .
__________________________________________________________________________________
Having gone over quite a few forum posts regarding the raspberry pi I’ll go ahead and answer a couple of questions right away.
Yes I know it’ll be slow (step and encoder read speed). But it’s fast enough for my purposes.
This is a small not very rigid machine and reading the glass scales keeps up just fine at the maximum speed I’m ever going to run it at.
Yes I’m aware that this would likely be easier if I just bought a Mesa card.
So much so that i went ahead and bought one. I did however get caught up in this Raspberry thing where I’d really like to see it run without it. And i can’t help but feel i’m really close.
Best
/Yagias
Attachments:
Please Log in or Create an account to join the conversation.
- Henk
- Offline
- Platinum Member
Less
More
- Posts: 395
- Thank you received: 80
19 Feb 2021 17:29 #199461
by Henk
Replied by Henk on topic Need a bit of help with a Raspberry PI 4 GPIO Glass scales control loop
Is the pi GPIO actually fast enough to count a glass scale, even at 5um? I have no idea, just wondering.
Anyway. I'm no expert on step and for setups but it seems that your Stepgens are currently running in position control mode. For closed loop with feedback from a linear scale you need the Stepgens set up in velocity control mode and the pid to do the position control.
Alternatively, you can just use the linear scale to monitor the position and signal if there are indications of lost steps...
Anyway. I'm no expert on step and for setups but it seems that your Stepgens are currently running in position control mode. For closed loop with feedback from a linear scale you need the Stepgens set up in velocity control mode and the pid to do the position control.
Alternatively, you can just use the linear scale to monitor the position and signal if there are indications of lost steps...
Please Log in or Create an account to join the conversation.
- PCW
- Offline
- Moderator
Less
More
- Posts: 17950
- Thank you received: 4817
19 Feb 2021 17:36 - 19 Feb 2021 17:36 #199463
by PCW
Right, for closed loop step/dir with encoder feedback at a minimum you need:
Stepgens set into velocity mode
PIDs position command and position feedback connected to motion and encoder positions respectively
PID output connected to stepgen velocity command
Replied by PCW on topic Need a bit of help with a Raspberry PI 4 GPIO Glass scales control loop
Is the pi GPIO actually fast enough to count a glass scale, even at 5um? I have no idea, just wondering.
Anyway. I'm no expert on step and for setups but it seems that your Stepgens are currently running in position control mode. For closed loop with feedback from a linear scale you need the Stepgens set up in velocity control mode and the pid to do the position control.
Alternatively, you can just use the linear scale to monitor the position and signal if there are indications of lost steps...
Right, for closed loop step/dir with encoder feedback at a minimum you need:
Stepgens set into velocity mode
PIDs position command and position feedback connected to motion and encoder positions respectively
PID output connected to stepgen velocity command
Last edit: 19 Feb 2021 17:36 by PCW.
Please Log in or Create an account to join the conversation.
- yagias
- Offline
- Junior Member
Less
More
- Posts: 21
- Thank you received: 0
19 Feb 2021 17:51 - 19 Feb 2021 17:52 #199464
by yagias
Replied by yagias on topic Need a bit of help with a Raspberry PI 4 GPIO Glass scales control loop
Hi Henrik
Thank you for you’r reply.
I was in doubt as I’ve read posts stating exactly what you’re saying about having to run velocity mode in order to “close the loop” but on the other hand i also read a post from Andy where he suggest to run it in position mode.
Personally i have no idea so i’ll go with whatever works even if that means changing everything
Regarding counting speed. At this point I’ve had it up to 1,2 Meters a minute which if my math is right equates to 8 Khz without losing counts and i won’t be running anything near that when cutting anyways so for the purpose it’s perfectly fine.
(On a side note the driver implementation of the hal_pi_gpio seems to be the biggest issue. From what I’ve found the raw read capability is actually quite high. 8Khz OS default but in the Mhz. range if a bit of hacking is involved.)
Thank you for you’r reply.
I was in doubt as I’ve read posts stating exactly what you’re saying about having to run velocity mode in order to “close the loop” but on the other hand i also read a post from Andy where he suggest to run it in position mode.
Personally i have no idea so i’ll go with whatever works even if that means changing everything
Regarding counting speed. At this point I’ve had it up to 1,2 Meters a minute which if my math is right equates to 8 Khz without losing counts and i won’t be running anything near that when cutting anyways so for the purpose it’s perfectly fine.
(On a side note the driver implementation of the hal_pi_gpio seems to be the biggest issue. From what I’ve found the raw read capability is actually quite high. 8Khz OS default but in the Mhz. range if a bit of hacking is involved.)
Last edit: 19 Feb 2021 17:52 by yagias.
Please Log in or Create an account to join the conversation.
- yagias
- Offline
- Junior Member
Less
More
- Posts: 21
- Thank you received: 0
19 Feb 2021 17:55 #199465
by yagias
Replied by yagias on topic Need a bit of help with a Raspberry PI 4 GPIO Glass scales control loop
Thank’s PCW
Seems I’ll be changing to velocity before I’ll be doing anything else
I’ll get back to you.
BTW: What a fabulous forum! Near instant feedback.
Thank you both.
Seems I’ll be changing to velocity before I’ll be doing anything else
I’ll get back to you.
BTW: What a fabulous forum! Near instant feedback.
Thank you both.
Please Log in or Create an account to join the conversation.
- yagias
- Offline
- Junior Member
Less
More
- Posts: 21
- Thank you received: 0
20 Feb 2021 18:20 #199549
by yagias
Replied by yagias on topic Need a bit of help with a Raspberry PI 4 GPIO Glass scales control loop
So… The frustrations are rising on my end.
Spent yet another day with nothing to show for it. And to make matters worse my vacation is coming to an end.
Now apologize if i break a forum rule that i’m unaware of but here goes.
In the interest of moving forwards i’m wondering if anyone here will take on the task of producing a working closed loop X axis with the PID section and feedback from the encoder from the configuration files i attached earlier? (Yes I’ll do the testing and the PID tuning on my end)
I’ll pay you a hundred USD over Paypal if we get this working.
(Not subject to resulting accuracy or speed)
Spent yet another day with nothing to show for it. And to make matters worse my vacation is coming to an end.
Now apologize if i break a forum rule that i’m unaware of but here goes.
In the interest of moving forwards i’m wondering if anyone here will take on the task of producing a working closed loop X axis with the PID section and feedback from the encoder from the configuration files i attached earlier? (Yes I’ll do the testing and the PID tuning on my end)
I’ll pay you a hundred USD over Paypal if we get this working.
(Not subject to resulting accuracy or speed)
Please Log in or Create an account to join the conversation.
- chris@cnc
- Offline
- Platinum Member
Less
More
- Posts: 529
- Thank you received: 139
20 Feb 2021 20:04 #199553
by chris@cnc
Replied by chris@cnc on topic Need a bit of help with a Raspberry PI 4 GPIO Glass scales control loop
hello yagias,
don't be sad. some things take time. We should now look step by step where it stops. can you check in hal show where the signals are accepted and can you even see an encoder in halshow and what is its name?
your signals go as follows:
1. net xa encoder.0.phase-A <= hal_pi_gpio.pin-11-in
net xb encoder.0.phase-B <= hal_pi_gpio.pin-12-in
2. in the line:
net x-vel-cmd <= joint.0.vel-cmd
net x-vel-fb <= encoder.0.velocity
net x-vel-fb => pid.x.feedback-deriv
the position feedback is missing here
net x-pos-fb <= encoder.0.position
the data are counted by phase a + b in encoder.0.position and then transferred to x-pos-fb and x-vel-feb. Then the circle should already be closed.
If you move your scale by hand you can see something in this pins
encoder.0.phase-A
xa
encoder.0.phase-B
xb
encoder.0.position
x-pos-fb
without hardware it is difficult to write a hal. you can do it!
don't be sad. some things take time. We should now look step by step where it stops. can you check in hal show where the signals are accepted and can you even see an encoder in halshow and what is its name?
your signals go as follows:
1. net xa encoder.0.phase-A <= hal_pi_gpio.pin-11-in
net xb encoder.0.phase-B <= hal_pi_gpio.pin-12-in
2. in the line:
net x-vel-cmd <= joint.0.vel-cmd
net x-vel-fb <= encoder.0.velocity
net x-vel-fb => pid.x.feedback-deriv
the position feedback is missing here
net x-pos-fb <= encoder.0.position
the data are counted by phase a + b in encoder.0.position and then transferred to x-pos-fb and x-vel-feb. Then the circle should already be closed.
If you move your scale by hand you can see something in this pins
encoder.0.phase-A
xa
encoder.0.phase-B
xb
encoder.0.position
x-pos-fb
without hardware it is difficult to write a hal. you can do it!
Please Log in or Create an account to join the conversation.
- yagias
- Offline
- Junior Member
Less
More
- Posts: 21
- Thank you received: 0
21 Feb 2021 07:14 #199581
by yagias
Replied by yagias on topic Need a bit of help with a Raspberry PI 4 GPIO Glass scales control loop
Hi Chris
Nice to “meet” you.
And thank you for responding and dealing with my frustrations on top. I’m usually the one touting patience but as you’re well aware this has gotten to me
“without hardware it is difficult to write a hal”
Yes… I’m aware. I mean i have the hardware and i’m struggling to say the least.
“Can you check in hal show where the signals are accepted and can you even see an encoder in halshow and what is its name?”
Yes i have the encoder in halshow and i get counts and position from it.
The encoder for the X axis is named encoder.0
“The data are counted by phase a + b in encoder.0.position and then transferred to x-pos-fb and x-vel-feb. Then the circle should already be closed.”
Closing the circle is by my best guess the problem at this point so i’ll go and check that now as well as the other bits and pieces and get back to you shortly.
Nice to “meet” you.
And thank you for responding and dealing with my frustrations on top. I’m usually the one touting patience but as you’re well aware this has gotten to me
“without hardware it is difficult to write a hal”
Yes… I’m aware. I mean i have the hardware and i’m struggling to say the least.
“Can you check in hal show where the signals are accepted and can you even see an encoder in halshow and what is its name?”
Yes i have the encoder in halshow and i get counts and position from it.
The encoder for the X axis is named encoder.0
“The data are counted by phase a + b in encoder.0.position and then transferred to x-pos-fb and x-vel-feb. Then the circle should already be closed.”
Closing the circle is by my best guess the problem at this point so i’ll go and check that now as well as the other bits and pieces and get back to you shortly.
Please Log in or Create an account to join the conversation.
- yagias
- Offline
- Junior Member
Less
More
- Posts: 21
- Thank you received: 0
21 Feb 2021 09:06 - 21 Feb 2021 09:07 #199583
by yagias
Replied by yagias on topic Need a bit of help with a Raspberry PI 4 GPIO Glass scales control loop
While testing i noticed that I had a couple of typos in the hal file.
x-vel-cmd, x-vel-fb, x-vel-fb which should have been xvel-cmd, xvel-fb, xvel-fb
These are now corrected.
I also added PID values to INI and references to them from HAL.
I verified that encoder.0.position updates and seems correct when moving the axis with a “hand crank”
Next i corrected net xpos-fb stepgen.0.position-fb => joint.0.motor-pos-fb
to net xpos-fb <= encoder.0.position
As you suggested and tested again.
The result is that i can move the axis within the Ferror allowance and then i get a “joint 0 following error”
Also i noticed that the DRO in the GUI isn’t updating.
Thanks again for chiming in.
Do you need any other data? Or any other suggestions ?
Plus i attached updated HAL and INI files.
hal_pi_gpio
Component Pins:
Owner Type DIR Value Name
18 bit OUT FALSE hal_pi_gpio.pin-11-in ==> xa
18 bit OUT FALSE hal_pi_gpio.pin-12-in ==> xb
Encoder
Component Pins:
Owner Type DIR Value Name
30 bit IN FALSE encoder.0.phase-A <== xa
20 bit IN FALSE encoder.0.phase-B <== xb
30 float OUT 0 encoder.0.position ==> xpos-fb
Joint
Component Pins:
Owner Type DIR Value Name
13 float OUT 0.68 joint.0.motor-pos-cmd ==> xpos-cmd
13 float IN 0 joint.0.motor-pos-fb
#
Signals:
Type Value Name (Linked to)
float 0 xvel-cmd <== joint.0.vel-cmd
float 0.001164155 xvel-fb <== encoder.0.velocity
==> pid.x.feedback-deriv
float 0.76 xpos-fb <== encoder.0.position
float 0.68 xpos-cmd <== joint.0.motor-pos-cmd
==> stepgen.0.position-cmd
x-vel-cmd, x-vel-fb, x-vel-fb which should have been xvel-cmd, xvel-fb, xvel-fb
These are now corrected.
I also added PID values to INI and references to them from HAL.
I verified that encoder.0.position updates and seems correct when moving the axis with a “hand crank”
Next i corrected net xpos-fb stepgen.0.position-fb => joint.0.motor-pos-fb
to net xpos-fb <= encoder.0.position
As you suggested and tested again.
The result is that i can move the axis within the Ferror allowance and then i get a “joint 0 following error”
Also i noticed that the DRO in the GUI isn’t updating.
Thanks again for chiming in.
Do you need any other data? Or any other suggestions ?
Plus i attached updated HAL and INI files.
hal_pi_gpio
Component Pins:
Owner Type DIR Value Name
18 bit OUT FALSE hal_pi_gpio.pin-11-in ==> xa
18 bit OUT FALSE hal_pi_gpio.pin-12-in ==> xb
Encoder
Component Pins:
Owner Type DIR Value Name
30 bit IN FALSE encoder.0.phase-A <== xa
20 bit IN FALSE encoder.0.phase-B <== xb
30 float OUT 0 encoder.0.position ==> xpos-fb
Joint
Component Pins:
Owner Type DIR Value Name
13 float OUT 0.68 joint.0.motor-pos-cmd ==> xpos-cmd
13 float IN 0 joint.0.motor-pos-fb
#
Signals:
Type Value Name (Linked to)
float 0 xvel-cmd <== joint.0.vel-cmd
float 0.001164155 xvel-fb <== encoder.0.velocity
==> pid.x.feedback-deriv
float 0.76 xpos-fb <== encoder.0.position
float 0.68 xpos-cmd <== joint.0.motor-pos-cmd
==> stepgen.0.position-cmd
Attachments:
Last edit: 21 Feb 2021 09:07 by yagias.
Please Log in or Create an account to join the conversation.
- chris@cnc
- Offline
- Platinum Member
Less
More
- Posts: 529
- Thank you received: 139
21 Feb 2021 09:45 - 21 Feb 2021 09:47 #199587
by chris@cnc
Replied by chris@cnc on topic Need a bit of help with a Raspberry PI 4 GPIO Glass scales control loop
well, it seems hardware is working
i found your encoder data was not send back to joint.0.motor-pos-fb
net xpos-fp => joint.0.motor-pos-fb # feedback to joint data
i made some comment in hal. try this if now dro in gui update and x-achse work. if yes same way Y axis
i am back in 6 h...
i found your encoder data was not send back to joint.0.motor-pos-fb
net xpos-fp => joint.0.motor-pos-fb # feedback to joint data
i made some comment in hal. try this if now dro in gui update and x-achse work. if yes same way Y axis
i am back in 6 h...
Last edit: 21 Feb 2021 09:47 by chris@cnc.
Please Log in or Create an account to join the conversation.
- LinuxCNC
- General LinuxCNC Questions
- Need a bit of help with a Raspberry PI 4 GPIO Glass scales control loop
Time to create page: 0.084 seconds