Help converting theta rho coordinates

Hello I built a polar sand art table very similar to this: too new to include link.

I have it running but the files are not playing correctly. The code in his github he links is not converting the theta, rho files correctly I don’t think. Here is the file that actually does the conversion: too new to include link.

I need to convert theta rho to number of linear steps for a stepper motor and number of rotational steps; and also add the correct delays.

I am hoping for help with understanding how the conversion is done. What does this mean?

microstep_size = 4
max_disp = 7300


coors = np.array([0, 0])
    for c in lines:
        c = c.split(" ")
        theta = float(c[0])
        r = float(c[1])

        if (theta != 0 or r != 0):
            theta = int(microstep_size * 3200 * theta / 6.28318531)
            r = int(max_disp * r)
            coors = np.vstack((coors, [theta, r]))

    min_value = coors[1:, 0].min()
    coors[1:, 0] -= min_value

    return coors

I believe that is where the conversion happens? why is the number 3200 here?

microstep_size * 3200 * theta

Is it a random choice? Any help would be awesome!!

I am not sure where you are pointing to. These filters help with spam, but you have to view a few posts to be able to link. If you put the address in a different format, I can edit it.

This is a post where I worked out converting theta, rho from sandify to XY angles. I picked an arbitrary unit if 6 per rotation just to make the numbers look sort of like radians:

Oh, shoot, that stuff I linked is for scara, and I am guessing yours is for actual angle and distance.

Thanks for the reply! I read a bunch of your posts to get me as far as I did, but I am stuck :frowning:

Here is the main like:

Here is the link to the python code where the conversions are done:

my table works the exact same way as the table I linked, with a rotational stepper motor and a linear stepper motor. I am able to calculate the number of steps for the radius with a switch on each end.

So I am assuming in the code the max_disp is supposed to be the number of steps my radius is but then it doesnt make sense to me. Here is a simple theta rho circle I exported using your sandify website:

[1.57080 1.00000]

And here is the converted file based on the github file I linked, after I changed my max_disp to be 50,000.:

[0 50000 -1.0 0.0001]

And here is the part of the code that uses those coordinates:

 MRot = threading.Thread(target=run_MRot, args=(step[0], step[2],))
 MLin = threading.Thread(target=run_MLin, args=(step[1], step[3],))

So indexes [0] & [1] are the number of steps and indexes [1] & [3] are the delays.

Does this makes any sens eto you because I am lost

My guess is this:

theta/6.28(2pi) is converting the theta value to number of full rotations. In theta,rho, a theta of 10 pi means 5 full rotations.

So then it is multiplying by 3200 my guess there is that the steppers are 200 steps / rotation. And there maybe is a 1:16 gear reduction. Then the drivers are set to 4 microsteps / full step.

2 Likes

I think you are exactly right. I have 1.8 deg stepper motors so 200 steps/rotation. The 1:16 gear reduction I am not totally sure, I have a 20 tooth pulley on the rotational motor which is connected to a 320 tooth (I believe) gear.

What does all that mean in regards to the math though? Because when I try to export and convert a simple 5 sided polygon with theta rho it doesn’t play right at all

Try this instead:

0 0
1.57080 1.000

The code snippet you dropped subtracts the minimum angle, so it always starts from zero.

Another very simple option is to do a script like this, which is basically erase, using 100 cycles:

0 0
628 1

Man you are being a life saver right now but I think some of this stuff is beyond me.

I tried changing the file and adding the ‘0 0’ but it outputs the same thing, only the 1 line: 0 50000 -1.0 0.001.

Here is a snippet where the delays are calculated:

def add_delays(steps):

    min_delay = 0.001

    delays = np.array([0, 0])
    for s in steps:
        if abs(s[0]) > abs(s[1]):
            Rot_delay = min_delay
            Lin_delay = round(abs(s[0]) * min_delay / abs(s[1]), 6) if s[1] != 0 else -1
        elif abs(s[1]) > abs(s[0]):
            Rot_delay = round(abs(s[1]) * min_delay / abs(s[0]), 6) if s[0] != 0 else -1
            Lin_delay = min_delay
        else:
            Rot_delay = min_delay
            Lin_delay = min_delay

        delays = np.vstack((delays, [Rot_delay, Lin_delay]))

    delays = delays[1:]
    steps_with_delays = np.concatenate((steps, delays), axis=1)

    return steps_with_delays

Does that part make sense? If I just simply change the min_delay = 0.001 to something like 0.000001 will that just speed up the whole drawing or will it change other things and make it draw the wrong shapes?

I tried processing the other script you suggested, [0 0 628 1] and it output the same thing: [0 50000 -1.0 0.001]

Also, what do you mean by this? Is that fine? Do I need to position the ball in the center before the file starts or will it do that?

This is where it is subtracting the min. I am on my phone right now, so I can’t poke too much more at this. I am not sure the motivation, but I suspect that is to keep wild starting positions from making the ball take off to get started, but I don’t know.

I also noticed that the first coord is always 0,0 and the processing code skips anything that has theta and rho equal to zero. So it makes sense that it wouldn’t be different by adding 0,0 to the front.

Okay thanks so much for all of the insight.

From anything you have seen is there anything that would be causing the drawings to be wrong?

in this line here: r = int(max_disp * r) would max_disp make sense to be equal to the number of steps for my table radius?

I think this is saying, “go to zero with a -1 delay (which doesn’t do anything)” and “go to 50,000 microsteps with a 0.001s delay between steps”. Which should be moving the radius out 50k microsteps.

I do think you need to start a pattern near zero. It seems to be assuming the radius, at least, starts at the center. I could be wrong, but that is what my tea leaves are telling me.

Yeah, that makes sense. The theta rho considers a rho of 1.0 to be at the max radius and zero in the center. So multiplying rho by the number of microsteps needed to get from zero to max radius would make sense to me.

Can you post a picture of the shape from sandify and what happens on the table? I may not be able to do the transform, but maybe I can guess.

Yes, I will look into everything you said and do that and post my result! Thank you so much for the help so far! I really really appreciate it

Here is a simple square from sandify:

And here is what my table draws: