Need a bit of help with a Raspberry PI 4 GPIO Glass scales control loop

More
21 Feb 2021 18:09 #199639 by yagias
Hi Mike

You´re very welcome.

Yes.. it´s one of those things. Started out fairly nice and became a mess along the way. Making a note to go and clean it up.

I have run the basic configuration without the scales which worked perfectly fine. But then again it was just about the most basic configuration you can get. Steppers in open loop.
I actually milled the bracket for the X axis in that configuration 

I haven´t tried introducing the PID loop without the scales. It actually never even occurred to me that i could.

Trying to close the loop is the big pita for me at this point.
Up until now all work has been on the X axis only.

Thank you for your input on this. I think I need to go back and restart the reading. I think my basic problem is a lack of understanding of the architecture so i guess it´s time to do it again.

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

More
21 Feb 2021 18:48 - 21 Feb 2021 21:37 #199641 by chris@cnc
hi,
now i am back home. I try to clean up little and hope it works.
We should get a runnig hal without encoder first. Second step connect encoder.
For test you try this hal. In your was something double.
Then comment all encoder lines + switch line 71 +72 back to open loop mode.
Check if your machine moving in correct way. If not adjust step scale best as possible.
For me its difficult to write this kind of hal. Because i use hostmot2 to and my config is different. I'm sure we can do it. corrections are welcome. I'm also just a beginner.
Finally we can do only step by step try and error.
Attachments:
Last edit: 21 Feb 2021 21:37 by chris@cnc.

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

More
21 Feb 2021 18:50 #199642 by Mike_Eitel
I would propose to make a sample-pncconf config with minimum axes. Learn in that how the pid is connected into the axis -> joint world. And don't forget the working glass encoders.
Then guys better than me on the closed loop question can easier help you.
m5c
Mike

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

More
22 Feb 2021 06:12 - 22 Feb 2021 06:12 #199677 by chris@cnc
PNCConfig does not work without a mesa card and stepconf can only configure a spindle encoder.

Sorry, but I have another mistake in line 19:
loadrt stepgen step_type = 0,0,0 ctrl_type = v, v, v # +++++++++ new
ctrl_type = v, v, v must ctrl_type = v, p, p with encoder in x. Y and Z were not set yet. And the PID
net x-enable => pid.x.enable
net xpos-cmd => pid.x.command
net xvel-cmd => pid.x.command-deriv
net xpos-fb => pid.x.feedback
net x-output => pid.x.output

net xpos-cmd <= joint.0.motor-pos-cmd
net xvel-cmd <= joint.0.vel-cmd
net x-output <= stepgen.0.velocity-cmd
without encoder
net xpos-fb <= stepgen.0.position-fb
net xpos-fb => joint.0.motor-pos-fb
with encoder
net xpos-fb <= encoder.0.position
net xpos-fb => joint.0.motor-pos-fb

net x-vel-fb <= encoder.0.velocity
net x-vel-fb => pid.z.feedback-deriv

so xpos-fp and xpos-cmp are connected to PID. x-output => pid.x.output I don't quite understand yet, but it should be like this according to Hakan's example
Last edit: 22 Feb 2021 06:12 by chris@cnc.

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

More
22 Feb 2021 07:18 #199682 by yagias
This looks great. Really looking forward to trying it out.

My vacation however is over so i'm at work now.
I'll give it a shot as soon as i get home and get back to you.

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

More
22 Feb 2021 17:43 - 22 Feb 2021 18:03 #199734 by yagias
Just wanted to get the initial result back to you.

So…
Running the initial config from you but with an update line 19 yields.
loadrt stepgen step_type=0,0,0 ctrl_type=v,p,p

Fails to load and an error from line 70.
net xpos-cmd joint.0.motor-pos-cmd => stepgen.0.position-cmd

Then in order to try it out i updated line 70 to use:
net xpos-cmd joint.0.motor-pos-cmd => stepgen.0.velocity-cmd

Then it loads but when i order a move in X it just continues to move until i get a joint 0 error.
Attachments:
Last edit: 22 Feb 2021 18:03 by yagias.

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

More
22 Feb 2021 18:22 #199745 by chris@cnc
yes, there is the missing point with pid
line 70 new two lines
x-output <= stepgen.0.velocity-cmd # velocity to PID
xpos-cmd <= joint.0.motor-pos-cmd # new calculatet back to xpos-cmd

xvel-cmd <= joint.0.vel-cmd #is missing to

to compare. finaly is this our target. we have to rename all hm2_7i76e.0 and z- words.
#*******************
#  AXIS Z
#*******************

setp   pid.z.Pgain     [JOINT_2]P
setp   pid.z.Igain     [JOINT_2]I
setp   pid.z.Dgain     [JOINT_2]D
setp   pid.z.bias      [JOINT_2]BIAS
setp   pid.z.FF0       [JOINT_2]FF0
setp   pid.z.FF1       [JOINT_2]FF1
setp   pid.z.FF2       [JOINT_2]FF2
setp   pid.z.deadband  [JOINT_2]DEADBAND
setp   pid.z.maxoutput [JOINT_2]MAX_OUTPUT
setp   pid.z.error-previous-target true
setp   pid.z.maxerror 0.0

net z-index-enable  <=> pid.z.index-enable
net z-enable        =>  pid.z.enable
net z-pos-cmd       =>  pid.z.command
net z-vel-cmd       =>  pid.z.command-deriv
net z-pos-fb        =>  pid.z.feedback
net z-output        =>  pid.z.output

# Step Gen signals/setup

setp   hm2_7i76e.0.stepgen.02.dirsetup        [JOINT_2]DIRSETUP
setp   hm2_7i76e.0.stepgen.02.dirhold         [JOINT_2]DIRHOLD
setp   hm2_7i76e.0.stepgen.02.steplen         [JOINT_2]STEPLEN
setp   hm2_7i76e.0.stepgen.02.stepspace       [JOINT_2]STEPSPACE
setp   hm2_7i76e.0.stepgen.02.position-scale  [JOINT_2]STEP_SCALE
setp   hm2_7i76e.0.stepgen.02.step_type        0
setp   hm2_7i76e.0.stepgen.02.control-type     1
setp   hm2_7i76e.0.stepgen.02.maxaccel         [JOINT_2]STEPGEN_MAXACCEL
setp   hm2_7i76e.0.stepgen.02.maxvel           [JOINT_2]STEPGEN_MAXVEL

# --- Z axis encoder feedback signals/setup

setp    hm2_7i76e.0.encoder.02.counter-mode 0
setp    hm2_7i76e.0.encoder.02.filter 1
setp    hm2_7i76e.0.encoder.02.index-invert 0
setp    hm2_7i76e.0.encoder.02.index-mask 0
setp    hm2_7i76e.0.encoder.02.index-mask-invert 0
setp    hm2_7i76e.0.encoder.02.scale 1000

# ---closedloop stepper signals---

net z-pos-cmd    <= joint.2.motor-pos-cmd
net z-vel-cmd    <= joint.2.vel-cmd
net z-output     <= hm2_7i76e.0.stepgen.02.velocity-cmd
net z-pos-fb     <= hm2_7i76e.0.encoder.02.position
net z-pos-fb     => joint.2.motor-pos-fb
net z-enable     <= joint.2.amp-enable-out
net z-enable     => hm2_7i76e.0.stepgen.02.enable

net z-vel-fb     <= hm2_7i76e.0.encoder.02.velocity
net z-vel-fb     => pid.z.feedback-deriv

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

More
22 Feb 2021 18:37 #199749 by yagias
Trying it out.
Sorry about the delay. Was buried in a manual :)

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

More
22 Feb 2021 18:57 - 22 Feb 2021 19:10 #199753 by yagias
ok. currently i added the three lines starting from line 70:
And it now looks like this.

Result:
Now nothing moves :)

Haven't begun aligning to hakans example yet.



# JOINT_0
setp stepgen.0.position-scale [JOINT_0]SCALE
setp stepgen.0.steplen 1
setp stepgen.0.stepspace 0
setp stepgen.0.dirhold 15200 #If motor not turn increase time
setp stepgen.0.dirsetup 15200
setp stepgen.0.maxaccel [JOINT_0]STEPGEN_MAXACCEL
#net xpos-cmd joint.0.motor-pos-cmd => stepgen.0.velocity-cmd

net x-output <= stepgen.0.velocity-cmd # velocity to PID
net xpos-cmd <= joint.0.motor-pos-cmd # new calculatet back to xpos-cmd
net xvel-cmd <= joint.0.vel-cmd

net xpos-fb <= stepgen.0.position-fb #Without encoder feedback from stepgen
net xpos-fb => joint.0.motor-pos-fb #Without encoder feedback to joint data


net xstep <= stepgen.0.step
net xdir <= stepgen.0.dir
net xenable joint.0.amp-enable-out => stepgen.0.enable

# Encoder Stuff.
#


net xa encoder.0.phase-A <= hal_pi_gpio.pin-11-in
net xb encoder.0.phase-B <= hal_pi_gpio.pin-12-in

net xvel-cmd <= joint.0.vel-cmd
net xvel-fb <= encoder.0.velocity
net xvel-fb => pid.x.feedback-deriv # not sure what is it
#net xpos-fb <= encoder.0.position # Encoderdata feedback
net xpos-fb => joint.0.motor-pos-fb # feedback to joint data

addf encoder.update-counters base-thread
addf encoder.capture-position servo-thread
setp encoder.0.position-scale 200
net rawPhaseA hal_pi_gpio.pin-16-in debounce.0.0.in # check wiring
net rawPhaseB hal_pi_gpio.pin-18-in debounce.0.1.in #
Attachments:
Last edit: 22 Feb 2021 19:10 by yagias.

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

More
22 Feb 2021 19:24 - 22 Feb 2021 19:50 #199755 by chris@cnc
well done.
this line is double
net xpos-fb => joint.0.motor-pos-fb # feedback to joint data
if you switch to open loop you schould comment this line to

Next step check in open loop your movement. Maybe we can trust the encoder data and travel 200mm end of your table.
Compare encoder position with stepgen.0.position-fb postion.
Adjust SCALE = -320 in ini File to min difference.
last step switch encoder on and cross finger
Last edit: 22 Feb 2021 19:50 by chris@cnc.
The following user(s) said Thank You: yagias

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

Time to create page: 0.232 seconds
Powered by Kunena Forum