<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
    <channel>
        <title>T-Bot: drawing diagonal lines</title>
        <description> I’ve made a T-Bot similar to this design. Using stepper motor driver L6470, I can control the movements e.g. up/down, left/right and diagonally using the equations shown here corexy, via the L6470 command MOVE(direction, number_of_steps) using MAX_SPEED(100 step/s).

If I move from (0, 0) to (400, 400), both stepper motors move at a constant speed, and reaches (400, 400). Great.

If I move from (0, 0) to (400, 100), then I need to reduce the speed of one of the stepper motors by 4 times (400 / 100 = 25 step/s). Fine.

However, if I move from (0, 0) to (400, 300), I reduce the speed of one of the stepper motors by 1.3 times (400 / 300 = 1.333 step/s). Slight issue here, MAX_SPEED only accepts integers and therefore the linear path it follows is not correct – one stepper motor will stop before the other, and a diagonal line is not drawn correctly.

Is there a way of resolving this issue?

Sample Python code looks like this,


# Maximum speed
STEP_PER_SECOND = 100

def doLine(dX, dY):
    # Coords
    dX = 400
    dY = 300

    # Coordinates to motor absolute position
    dY = -dY
    a_pos = dX + dY
    b_pos = dX - dY
    print(&quot;A_POS:&quot;, a_pos, &quot;B_POS:&quot;, b_pos)

    a_pos_temp = abs(a_pos)
    b_pos_temp = abs(b_pos)

    a_spd = STEP_PER_SECOND
    b_spd = STEP_PER_SECOND

    if (a_pos_temp &amp;gt; b_pos_temp):
        b_spd = round(abs(STEP_PER_SECOND * (b_pos_temp / a_pos_temp)))
    elif (a_pos_temp &amp;lt; b_pos_temp):
        a_spd = round(abs(STEP_PER_SECOND * (a_pos_temp / b_pos_temp)))
    print(&quot;A_SPD:&quot;, a_spd, &quot;B_SPD:&quot;, b_spd)

    MOTOR[0].setMaxSpeed(SE.steps_to_maxspeed(a_spd))
    MOTOR[1].setMaxSpeed(SE.steps_to_maxspeed(b_spd))
	
    # Move stepper MOTOR
    if (a_pos &amp;lt; 0):
        MOTOR[0].Move(SE.REV, -a_pos)
    else:
        MOTOR[0].Move(SE.FWD, a_pos)

    if (b_pos &amp;lt; 0):
        MOTOR[1].Move(SE.REV, -b_pos)
    else:
        MOTOR[1].Move(SE.FWD, b_pos)

    while (GPIO.input(SE.MTR0_BUSY) != 1) or (GPIO.input(SE.MTR3_BUSY) != 1):
        pass	
</description>
        <link>https://reprap.org/forum/read.php?2,841815,841815#msg-841815</link>
        <lastBuildDate>Sat, 11 Apr 2026 08:35:39 -0400</lastBuildDate>
        <generator>Phorum 5.2.23</generator>
        <item>
            <guid>https://reprap.org/forum/read.php?2,841815,842864#msg-842864</guid>
            <title>Re: T-Bot: drawing diagonal lines</title>
            <link>https://reprap.org/forum/read.php?2,841815,842864#msg-842864</link>
            <description><![CDATA[ I just read my own comment and noticed it's the opposite way around: left shift doubles the value, right shift halfes it. 8-)]]></description>
            <dc:creator>o_lampe</dc:creator>
            <category>Developers</category>
            <pubDate>Sun, 30 Dec 2018 02:45:09 -0500</pubDate>
        </item>
        <item>
            <guid>https://reprap.org/forum/read.php?2,841815,842748#msg-842748</guid>
            <title>Re: T-Bot: drawing diagonal lines</title>
            <link>https://reprap.org/forum/read.php?2,841815,842748#msg-842748</link>
            <description><![CDATA[ Update,<br />
<br />
As I was unable to use the methods provided by the L6470 chip, to do what I wanted. I have now used Step Clock mode instead. I have written methods which allows me to rotate the stepper motors a step (i.e. 1.8 degrees); using Bresenham’s line algorithm to draw diagonal lines without having to decrease or increase speeds.<br />
<br />
Here’s a <a href="https://youtu.be/Ujj0VJzt61o" target="_blank"  rel="nofollow">little video</a>, which follows some basic coordinates.]]></description>
            <dc:creator>rraghvani</dc:creator>
            <category>Developers</category>
            <pubDate>Sat, 29 Dec 2018 06:05:09 -0500</pubDate>
        </item>
        <item>
            <guid>https://reprap.org/forum/read.php?2,841815,841831#msg-841831</guid>
            <title>Re: T-Bot: drawing diagonal lines</title>
            <link>https://reprap.org/forum/read.php?2,841815,841831#msg-841831</link>
            <description><![CDATA[ Integer math is funny, isn't it? Don't know, if I can explain...<br />
<br />
Usually you multiply the floating value by <i>right shifting</i> ( eg. &gt;&gt;8 ), <br />
then forget about the fractions and do the operation in integer.<br />
Later you <i>left shift</i> (&lt;&lt;8 ) the result to get your final value.<br />
<br />
Maybe you can read more qualified explanation about <u>Integer math</u> in the net.]]></description>
            <dc:creator>o_lampe</dc:creator>
            <category>Developers</category>
            <pubDate>Tue, 18 Dec 2018 23:20:37 -0500</pubDate>
        </item>
        <item>
            <guid>https://reprap.org/forum/read.php?2,841815,841815#msg-841815</guid>
            <title>T-Bot: drawing diagonal lines</title>
            <link>https://reprap.org/forum/read.php?2,841815,841815#msg-841815</link>
            <description><![CDATA[ I’ve made a T-Bot similar to this <a href="http://www.buildlog.net/blog/2017/10/the-midtbot-a-new-flavor-of-h-bot/" target="_blank"  rel="nofollow">design</a>. Using stepper motor driver <a href="https://www.st.com/en/motor-drivers/l6470.html" target="_blank"  rel="nofollow">L6470</a>, I can control the movements e.g. up/down, left/right and diagonally using the equations shown here <a href="https://corexy.com/theory.html" target="_blank"  rel="nofollow">corexy</a>, via the L6470 command MOVE(direction, number_of_steps) using MAX_SPEED(100 step/s).<br />
<br />
If I move from (0, 0) to (400, 400), both stepper motors move at a constant speed, and reaches (400, 400). Great.<br />
<br />
If I move from (0, 0) to (400, 100), then I need to reduce the speed of one of the stepper motors by 4 times (400 / 100 = 25 step/s). Fine.<br />
<br />
However, if I move from (0, 0) to (400, 300), I reduce the speed of one of the stepper motors by 1.3 times (400 / 300 = 1.333 step/s). Slight issue here, MAX_SPEED only accepts integers and therefore the linear path it follows is not correct – one stepper motor will stop before the other, and a diagonal line is not drawn correctly.<br />
<br />
Is there a way of resolving this issue?<br />
<br />
Sample Python code looks like this,<br />
<br />
<pre class="bbcode">
# Maximum speed
STEP_PER_SECOND = 100

def doLine(dX, dY):
    # Coords
    dX = 400
    dY = 300

    # Coordinates to motor absolute position
    dY = -dY
    a_pos = dX + dY
    b_pos = dX - dY
    print("A_POS:", a_pos, "B_POS:", b_pos)

    a_pos_temp = abs(a_pos)
    b_pos_temp = abs(b_pos)

    a_spd = STEP_PER_SECOND
    b_spd = STEP_PER_SECOND

    if (a_pos_temp &gt; b_pos_temp):
        b_spd = round(abs(STEP_PER_SECOND * (b_pos_temp / a_pos_temp)))
    elif (a_pos_temp &lt; b_pos_temp):
        a_spd = round(abs(STEP_PER_SECOND * (a_pos_temp / b_pos_temp)))
    print("A_SPD:", a_spd, "B_SPD:", b_spd)

    MOTOR[0].setMaxSpeed(SE.steps_to_maxspeed(a_spd))
    MOTOR[1].setMaxSpeed(SE.steps_to_maxspeed(b_spd))
	
    # Move stepper MOTOR
    if (a_pos &lt; 0):
        MOTOR[0].Move(SE.REV, -a_pos)
    else:
        MOTOR[0].Move(SE.FWD, a_pos)

    if (b_pos &lt; 0):
        MOTOR[1].Move(SE.REV, -b_pos)
    else:
        MOTOR[1].Move(SE.FWD, b_pos)

    while (GPIO.input(SE.MTR0_BUSY) != 1) or (GPIO.input(SE.MTR3_BUSY) != 1):
        pass	
</pre>]]></description>
            <dc:creator>rraghvani</dc:creator>
            <category>Developers</category>
            <pubDate>Tue, 18 Dec 2018 17:11:42 -0500</pubDate>
        </item>
    </channel>
</rss>
