segmentise config error

segmentise config error

Postby ChrisK » Thu Nov 05, 2015 2:28 pm

I've been stuck on setting up segmentise for a bit now.
Once I input my gathered up bed co-ordinates and try and run segmentise I get
ValueError: math domain error

I have not entered any other custom values into my segmentise file, is there anything I have missed out?
Anyone have any ideas why this is going wrong?
Screen grab of error and my segmentise code in following posts
Last edited by ChrisK on Thu Nov 05, 2015 2:44 pm, edited 1 time in total.
ChrisK
 
Posts: 63
Joined: Mon Dec 30, 2013 6:14 pm

Re: segmentise config error

Postby ChrisK » Thu Nov 05, 2015 2:30 pm

Screenshot 2015-11-05 14.13.57.png
Screenshot 2015-11-05 14.13.57.png (30.45 KiB) Viewed 26741 times

And here is a screengrab
ChrisK
 
Posts: 63
Joined: Mon Dec 30, 2013 6:14 pm

Re: segmentise config error

Postby ChrisK » Thu Nov 05, 2015 2:30 pm

And my segmentise file
Code: Select all
#!/usr/bin/env python2
#THIS IS A ConceptFORGE PRODUCT.
#GPL LICENSE

#EXPERIMENTAL.  THIS CODE NEEDS IMPROVEMENT.

#ALL LENGTHS ARE IN mm

#A LIST OF MACHINE POSITIONS WHERE PAPER CAN
#BARELY SLIDE BETWEEN THE BED AND THE EXTRUDER.
#THIS NEEDS TO COVER THE AREA YOU WANT TO PRINT.
#THE MORE THE BETTER.
#EXPECT THE MACHINE TO NEED TO BE RECALIBRATED OFTEN AS
#THE SYSTEM GETS WORKED IN.
POINTS=[(145,140,60),#
        (110,145,110),#
        (100,140,129.6),#
        (100,173.9,70),#
        (129,200,80),#
        (173,100,100),#
        ]
#DISTANCE FROM SHOULDER SCREW TO SHOULDER SCREW
SIZE=250.0

#APPROXIMATE Z DISTANCE FROM SHOULDER ARM ATTACHMENT
#TO HUB ARM ATTACHMENT
BED_Z=70

#APPROXIMATE MAX ACTUATED LENGTH OF ARM
MAX_ARM_LENGTH=300

#HOW SMALL SHOULD THE LINE SEGMENTS BE BROKEN DOWN TO?
#SMALL=BETTER QUALITY
#LARGE=SMALLER FILE/FASTER
SEGMENT_SIZE=1.0


from scipy.optimize import leastsq
import numpy.linalg
import math, random, copy, sys

if len(sys.argv)<2:
    f=file(raw_input("Input File: "))
    f2=file(raw_input("Output File: "),"w")
else:
    f=file(sys.argv[1])
    if len(sys.argv) == 2 :
        f2=file(sys.argv[1].split(".")[0] + "-GUS.gcode", "w")      #Automatically name output file like "file.gcode-gus.gcode if no output name was typed"
    else:
        f2=file(sys.argv[2],"w")                                #Guizmo: added the "w" parameter.

        if len(sys.argv) == 4:   
            SEGMENT_SIZE = float(sys.argv[3])                #Let the user select segment size as a third argument

DEFAULT_VALUES=[BED_Z,BED_Z,BED_Z,MAX_ARM_LENGTH,MAX_ARM_LENGTH,MAX_ARM_LENGTH]

SHOULDER_Z1,SHOULDER_Z2,SHOULDER_Z3,MAX_LENGTH_1,MAX_LENGTH_2,MAX_LENGTH_3=DEFAULT_VALUES

#GET COORDINATES USING TRILATERATION
def getxyz(r1,r2,r3):
    d=SIZE*1.0
    i=SIZE/2.0
    j=SIZE*math.sqrt(3)/2.0
    x=(r1*r1-r2*r2+d*d)/(2*d)
    y=(r1*r1-r3*r3-x*x+(x-i)**2+j*j)/(2*j)
    z=math.sqrt(r1*r1-x*x-y*y)
    return x,y,z

#GET VALUES FOR EACH POINT TO SEE HOW CLOSE TO THE PLANE IT IS
def equations(p):
    SHOULDER_Z1,SHOULDER_Z2,SHOULDER_Z3,MAX_LENGTH_1,MAX_LENGTH_2,MAX_LENGTH_3=p
    m=[]
    for i in range(len(POINTS)):
        R1,R2,R3=MAX_LENGTH_1-POINTS[i][0],MAX_LENGTH_2-POINTS[i][1],MAX_LENGTH_3-POINTS[i][2]
        X,Y,Z=getxyz(R1,R2,R3)
        d=SIZE*1.0
        i=SIZE/2.0
        j=SIZE*math.sqrt(3)/2.0
        q=[[0,0,SHOULDER_Z1,1],
           [d,0,SHOULDER_Z2,1],
           [i,j,SHOULDER_Z3,1],
           [X,Y,Z,1]]
        det=numpy.linalg.det(q)
        m.append(det**2)
    return m

#GET OPTIMAL VALUES
SHOULDER_Z1,SHOULDER_Z2,SHOULDER_Z3,MAX_LENGTH_1,MAX_LENGTH_2,MAX_LENGTH_3=leastsq(equations, DEFAULT_VALUES)[0]



x1=-SIZE/2.0
y1=-SIZE*math.sqrt(3)/2.0/3.0
z1=-SHOULDER_Z1
x2=+SIZE/2.0
y2=-SIZE*math.sqrt(3)/2.0/3.0
z2=-SHOULDER_Z2
x3=0
y3=2*SIZE*math.sqrt(3)/2.0/3.0
z3=-SHOULDER_Z3
x0,y0,z0=getxyz(MAX_LENGTH_1,MAX_LENGTH_2,MAX_LENGTH_3)
coord={"X":x0+x1,"Y":y0+y1,"Z":z0+z1, "E":0, "F":0}


def getABC(position1):
    if "X" not in position1:
        return position1
    position=copy.deepcopy(position1)
    d=distance(coord,position)
    xs,ys,zs=coord["X"],coord["Y"],coord["Z"]
    x,y,z,f=position["X"],position["Y"],position["Z"],position["F"]
    a1=MAX_LENGTH_1-math.sqrt((xs-x1)**2+(ys-y1)**2+(zs-z1)**2)
    b1=MAX_LENGTH_2-math.sqrt((xs-x2)**2+(ys-y2)**2+(zs-z2)**2)
    c1=MAX_LENGTH_3-math.sqrt((xs-x3)**2+(ys-y3)**2+(zs-z3)**2)
    a2=MAX_LENGTH_1-math.sqrt((x-x1)**2+(y-y1)**2+(z-z1)**2)
    b2=MAX_LENGTH_2-math.sqrt((x-x2)**2+(y-y2)**2+(z-z2)**2)
    c2=MAX_LENGTH_3-math.sqrt((x-x3)**2+(y-y3)**2+(z-z3)**2)
    virtual_d=math.sqrt((a1-a2)**2+(b1-b2)**2+(c1-c2)**2)
    fnew=f
    if d!=0:
        fnew=f*virtual_d/d
    position['X']=a2
    position['Y']=b2
    position['Z']=c2
    position['F']=fnew
    return position

def distance(start, end):
    try:
        x1,y1,z1=start['X'],start['Y'],start['Z']
        x2,y2,z2=end['X'],end['Y'],end['Z']
        return math.sqrt((x1-x2)**2+(y1-y2)**2+(z1-z2)**2)
    except:
        return 0

def interpolate(start, end, i, n):
    x1,y1,z1,e1=start['X'],start['Y'],start['Z'],start['E']
    x2,y2,z2,e2=end['X'],end['Y'],end['Z'],end['E']
    middle={}
    for c in end:
        if c in end and c in start and c!="F":
            middle[c]=(i*end[c]+(n-i)*start[c])/n
        else:
            middle[c]=end[c]
    return middle

def segmentize(start,end,maxLength):
    l=distance(start,end)
    if l<=maxLength:
        return [end]
    else:
        output=[]
        n=int(math.ceil(l/maxLength))
        for i in range(1,n+1):
            output.append(interpolate(start,end,i,n))
        return output

print(getABC({"X":45,"Y":0,"Z":1,"F":123}))
print(getABC({"X":90,"Y":0,"Z":1,"F":123}))


prefixes="MGXYZESF"
commands="MG"

program=[]
move_count=0
for line in f:
    line=line.upper()
    line=line.strip()
    chunks=line.split(";")[0].split(" ")
    stuff={}
    for chunk in chunks:
        if len(chunk)>1:
            stuff[chunk[0]]=chunk[1:]
            try:
                stuff[chunk[0]]=int(stuff[chunk[0]])
            except:
                try:
                    stuff[chunk[0]]=float(stuff[chunk[0]])
                except:
                    pass
        if "X" in stuff or "Y" in stuff or "Z" in stuff:
            move_count+=1
            for c in coord:
                if c not in stuff:
                    stuff[c]=coord[c]           
    if move_count<=3 and len(stuff)>0:
        program+=[stuff]
    elif len(stuff)>0:
        segments=segmentize(coord,stuff,SEGMENT_SIZE)
        program+=segments
    for c in coord:
        if c in stuff:
            coord[c]=stuff[c]
f2.write("G92 X0 Y0 Z0 E0\nG1 X-1000 Y-1000 Z-1000\nG28\n")
for line in program:
    abcline=getABC(line)
    for letter in prefixes:
        if letter in abcline and letter in commands:
            f2.write(letter+str(abcline[letter])+" ")
        elif letter in abcline:
            f2.write(letter+str(round(abcline[letter],3))+" ")
    f2.write("\n")


f2.close()
print("done")

   
ChrisK
 
Posts: 63
Joined: Mon Dec 30, 2013 6:14 pm

Re: segmentise config error

Postby timrwilliams » Wed Nov 18, 2015 3:37 pm

@ChrisK - Sorry for slow response, I am a bit out of touch with GUS recently, tho' it looks as if you and others are making progress.
I hope you have solved your segmentise problem. If not - It looked to me that some of the cal values pushed the math out of bounds. My programming ability can't explain this, but I got your values to run by changing
(129,200,80). Is that value reproducible?
I hope you continue well.

Regards

Tim
timrwilliams
 
Posts: 87
Joined: Fri Feb 14, 2014 10:32 pm

Re: segmentise config error

Postby ChrisK » Thu Nov 19, 2015 9:36 am

Hello Tim, great to 'see' you again.
Thanks for your help I'll try and sit down today and swap out that measurement.
As for the handful of machine geometry readings is the bed z a vertical reading from the bed to the bolts that hold the hub arms onto the main arm with hot end touching the deck?
I'm guessing the others will be unchanged If the machine is printed from original plans.
I managed to get an Anubis hotend from some guy I met at the 3D printing meet up at hack space so my geometry is working well with no sudden collapses near the bed. Found I had my minimum set to -3000 which was causing problems of the machine zooming through the bed or out of print volume following a home command. Setting min values to 0 sorted everything
Apart from the calibration the only other issue is the Y arm occasionally seems to just skip a movement command. As it is the Y arm I'm going to head into the firmware and change some of the motion settings such as the acceleration which is still different to th x and y.
ChrisK
 
Posts: 63
Joined: Mon Dec 30, 2013 6:14 pm

Re: segmentise config error

Postby ekaggrat » Mon Mar 07, 2016 5:15 pm

how did you get your segmentize to work? i am also getting the same out of bound error

thanks
ekaggrat
 
Posts: 56
Joined: Tue Mar 04, 2014 3:24 am

Re: segmentise config error

Postby Nicholas Seward » Mon Mar 07, 2016 6:20 pm

Yes, segmentize is very brittle. It uses the method of least squares to solve for machine parameters. If it doesn't work try setting different zero values or pick default values closer to reality.
Nicholas Seward
 
Posts: 738
Joined: Mon Nov 25, 2013 10:41 pm

Re: segmentise config error

Postby ekaggrat » Tue Mar 08, 2016 12:39 am

what do you mean by different zero values

my points look like this

(170.00,143.20,220.00),
(169.90,203.20,148.90),
(199.90,213.20,119.00),
(209.90,203.00,119.00),
(229.90,203.00,110.40),
(229.90,168.90,140.40),
(209.90,146.60,170.40),
(199.90,128.00,200.40),
(180.40,138.00,210.40),
(172.00,138.00,240.40),
(152.40,158.00,230.40),
(142.60,168.00,230.40),
(124.60,188.00,230.40),
(124.60,208.00,196.80),
(124.60,218.00,189.00),
(124.60,228.00,184.50)

which values should i change?

thanks
ekaggrat
 
Posts: 56
Joined: Tue Mar 04, 2014 3:24 am

Re: segmentise config error

Postby Nicholas Seward » Tue Mar 08, 2016 2:52 am

Two things. 1) Start by using zero points that are <=50mm from the center. 2) Get good estimates for the following three items.

Code: Select all
#DISTANCE FROM SHOULDER SCREW TO SHOULDER SCREW
SIZE=250.0

#APPROXIMATE Z DISTANCE FROM SHOULDER ARM ATTACHMENT
#TO HUB ARM ATTACHMENT
BED_Z=70

#APPROXIMATE MAX ACTUATED LENGTH OF ARM
MAX_ARM_LENGTH=300


If all else fails... you can comment out this line...
Code: Select all
SHOULDER_Z1,SHOULDER_Z2,SHOULDER_Z3,MAX_LENGTH_1,MAX_LENGTH_2,MAX_LENGTH_3=leastsq(equations, DEFAULT_VALUES)[0]

If you do that then you need to set each of these values separately through careful measurements.
Nicholas Seward
 
Posts: 738
Joined: Mon Nov 25, 2013 10:41 pm

Re: segmentise config error

Postby ekaggrat » Tue Mar 08, 2016 6:02 am

actually what i am attempting is to use segmentize to get the valuses of max_arm_length and shoulder_length accurately so that i can then use those values in the marlin version meant for GUS..

i modified the python script to just take the points and spit out those values.


i will try taking the points again in the center .

thanks..
ekaggrat
 
Posts: 56
Joined: Tue Mar 04, 2014 3:24 am

Next

Return to GUS Simpson

Who is online

Users browsing this forum: No registered users and 2 guests

cron