<div dir="ltr"><div class="gmail_default" style="font-family:comic sans ms,sans-serif">Assuming you are sending commands serially,</div><div class="gmail_default" style="font-family:comic sans ms,sans-serif"><br></div><div class="gmail_default" style="font-family:comic sans ms,sans-serif">then you could send something like this ...</div><div class="gmail_default" style="font-family:comic sans ms,sans-serif"><br></div><div class="gmail_default" style="font-family:comic sans ms,sans-serif"><b>Motor A target nnnn, B target nnnn, C target nnn S 40</b></div><div class="gmail_default" style="font-family:comic sans ms,sans-serif"><br></div><div class="gmail_default" style="font-family:comic sans ms,sans-serif">Each motor would have its own Timer ISR controlling movement, direction speed (<b>S</b>) etc.</div><div class="gmail_default" style="font-family:comic sans ms,sans-serif"><br></div><div class="gmail_default" style="font-family:comic sans ms,sans-serif">Either they move at a set speed, arriving at a target point whenever,</div><div class="gmail_default" style="font-family:comic sans ms,sans-serif"><br></div><div class="gmail_default" style="font-family:comic sans ms,sans-serif">or you do some math, so they arrive at the same time.</div><div class="gmail_default" style="font-family:comic sans ms,sans-serif"><br></div><div class="gmail_default" style="font-family:comic sans ms,sans-serif">Bit like a 3D printer ???</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Feb 5, 2019 at 5:37 PM Justin Mitchell <<a href="mailto:justin@discordia.org.uk">justin@discordia.org.uk</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Tue, 2019-02-05 at 14:56 +0000, Andy Davies wrote:<br>
> Hi<br>
>  <br>
> Just wanted to check with you guys so see what would be the best way<br>
> to structure some code.<br>
>  <br>
> I have four stepper motors controlled by a windows form via an<br>
> Arduino.<br>
> <br>
...<br>
> Any suggestions as to how to structure the code will be most welcome.<br>
<br>
<br>
Personally, I would have the PC->Arduino instructions to be able to set<br>
target positions for the steppers, then have a synchronize/activate<br>
command, so that you don't have a time delay between one being updated<br>
and the next.<br>
<br>
in code structure, probably a bunch of globals with the target position<br>
numbers, have the main loop read the info from the pc and update the<br>
targets as commands come in, and a timer interrupt routine which moves<br>
the motors towards their target positions a little bit each time<br>
around.<br>
<br>
that would be my initial approach anyway<br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
Hackspace mailing list<br>
<a href="mailto:Hackspace@swansea.hackspace.org.uk" target="_blank">Hackspace@swansea.hackspace.org.uk</a><br>
<a href="http://swansea.hackspace.org.uk/mailman/listinfo/hackspace" rel="noreferrer" target="_blank">http://swansea.hackspace.org.uk/mailman/listinfo/hackspace</a><br>
</blockquote></div>