- Posts: 16
- Thank you received: 1
Lost Step Counter
- DieselJoe
- Offline
- New Member
-
Less
More
8 years 2 weeks ago - 8 years 2 weeks ago #118984
by DieselJoe
Replied by DieselJoe on topic Lost Step Counter
I think I made good progress during the last 12 hours...
I don't fully understand your code, but it was an inspiration.
I succeed making a code that seems to work.
Thank you a lot.
and the connections:
I don't fully understand your code, but it was an inspiration.
I succeed making a code that seems to work.
Thank you a lot.
Code:
#!/usr/bin/python
import hal, time
h = hal.component("miss_step")
h.newpin("mot_off_x", hal.HAL_FLOAT, hal.HAL_IN)
h.newpin("joint_x", hal.HAL_FLOAT, hal.HAL_IN)
h.newpin("lost_x", hal.HAL_FLOAT, hal.HAL_OUT)
h.ready()
previous_offset_x = 0.00
try:
while 1:
time.sleep(1)
# make difference between previous offset and current offset, print the deviation if > 0.01
if (h['mot_off_x']-previous_offset_x) >= 0.01 or (h['mot_off_x']-previous_offset_x) <= -0.01:
h['lost_x'] = h['mot_off_x']-previous_offset_x
previous_offset_x = h['mot_off_x']
# reset deviation display if joint has moved for more than 5mm
if h['joint_x'] >= 5:
h['lost_x'] = 0
except KeyboardInterrupt:
raise SystemExit
and the connections:
Code:
net my-motoroffsetx miss_step.mot_off_x <= axis.0.motor-offset
net my-lost_x pyvcp.x-lostSteps <= miss_step.lost_x
net my-joint_x miss_step.joint_x <= axis.0.joint-pos-cmd
Last edit: 8 years 2 weeks ago by DieselJoe.
Please Log in or Create an account to join the conversation.
- andypugh
- Offline
- Moderator
-
Less
More
- Posts: 19899
- Thank you received: 4655
8 years 2 weeks ago #118987
by andypugh
Replied by andypugh on topic Lost Step Counter
I don't understand why my code didn't just work for you, it worked when I tested it.
Perhaps the problem was that it was working perfectly and you had no problems? My version only pops-up the message when the homing offsets change.
Perhaps the problem was that it was working perfectly and you had no problems? My version only pops-up the message when the homing offsets change.
Please Log in or Create an account to join the conversation.
- DieselJoe
- Offline
- New Member
-
Less
More
- Posts: 16
- Thank you received: 1
8 years 2 weeks ago #118988
by DieselJoe
Replied by DieselJoe on topic Lost Step Counter
I believe that when I tried to use your code I was so much not understanding what I was doing, I may have introduced mistakes.
For instance, I didn't know the correct syntax for python. I referred to what I knew from "C", where "spaces" are not important.
And as was understanding a bit more , I made few experiences, and finally wanted to know what I was doing in my linuxcnc program...
Thank you again
For instance, I didn't know the correct syntax for python. I referred to what I knew from "C", where "spaces" are not important.
And as was understanding a bit more , I made few experiences, and finally wanted to know what I was doing in my linuxcnc program...
Thank you again
Please Log in or Create an account to join the conversation.
- DieselJoe
- Offline
- New Member
-
Less
More
- Posts: 16
- Thank you received: 1
8 years 1 week ago #119000
by DieselJoe
Replied by DieselJoe on topic Lost Step Counter
Please Log in or Create an account to join the conversation.
- MartyJ
- Offline
- Senior Member
-
Less
More
- Posts: 48
- Thank you received: 13
6 years 6 months ago - 6 years 6 months ago #164566
by MartyJ
Replied by MartyJ on topic Lost Step Counter
Hi all, I'm using AndyPugh's code from the first page of this thread unmodified except replacing "axis" with "joint".
I'm loading 4 counts of miss_step, it loads as a module and all four counts have created the pins:
etc for joints 0 through 3.
This works and I can see them in Halshow. But as soon as I add the following lines to my HAL, LinuxCNC won't launch.
The error I get on launch is:
Any ideas? Hoping to get this working to troubleshoot some issues I've been having. Thanks for any help!
(INI/HAl attached)
Warning: Spoiler!
Code:
#!/usr/bin/python
import hal, time
import sys
from Tkinter import *
import tkMessageBox
root = Tk()
root.withdraw()
h = hal.component("miss_step")
count = 1
for opt in sys.argv[1:]:
(dummy, count) = opt.split("=")
if dummy != "count":
count = 1
pins = []
for i in range(int(count)):
p1 = "joint.%i.pos-cmd" %i
p2 = "joint.%i.motor-pos-cmd" %i
d = 0
t = [p1, p2, d]
pins.append(t)
h.newpin(p1, hal.HAL_FLOAT, hal.HAL_IN)
h.newpin(p2, hal.HAL_FLOAT, hal.HAL_IN)
h.ready()
try:
flag = False
while 1:
time.sleep (1)
for t in pins:
if h[t[0]]-h[t[1]] != t[2]:
flag = True
t[2] = h[t[0]]-h[t[1]]
if flag == True:
flag = False
message = ""
for t in pins:
message = message + t[0] + " = %f\n"%t[2]
ret = tkMessageBox._show("Homing Position Differs",
message,
tkMessageBox.QUESTION, tkMessageBox.OK)
root.update()
except KeyboardInterrupt:
raise SystemExit
I'm loading 4 counts of miss_step, it loads as a module and all four counts have created the pins:
Code:
miss_step.joint.0.motor-pos-cmd
miss_step.joint.0.pos-cmd
etc for joints 0 through 3.
This works and I can see them in Halshow. But as soon as I add the following lines to my HAL, LinuxCNC won't launch.
Code:
net check0 miss_step.joint.0.pos-cmd joint.0.motor-pos-cmd
net Xpos miss_step.joint.0.motor-pos-cmd
The error I get on launch is:
Code:
...
Pin 'miss_step.joint.0.pos-cmd' does not exist
337
...
Any ideas? Hoping to get this working to troubleshoot some issues I've been having. Thanks for any help!
(INI/HAl attached)
Last edit: 6 years 6 months ago by MartyJ. Reason: code formatting
Please Log in or Create an account to join the conversation.
- DieselJoe
- Offline
- New Member
-
Less
More
- Posts: 16
- Thank you received: 1
6 years 6 months ago #164578
by DieselJoe
Replied by DieselJoe on topic Lost Step Counter
The hal links are in your "post GUI" ?
The following user(s) said Thank You: MartyJ
Please Log in or Create an account to join the conversation.
Time to create page: 1.853 seconds