[Swansea Hackspace] code structure

Ceri Clatworthy ceri.clatworthy at gmail.com
Wed Feb 6 13:14:17 GMT 2019


Assuming you are sending commands serially,

then you could send something like this ...

*Motor A target nnnn, B target nnnn, C target nnn S 40*

Each motor would have its own Timer ISR controlling movement, direction
speed (*S*) etc.

Either they move at a set speed, arriving at a target point whenever,

or you do some math, so they arrive at the same time.

Bit like a 3D printer ???

On Tue, Feb 5, 2019 at 5:37 PM Justin Mitchell <justin at discordia.org.uk>
wrote:

> On Tue, 2019-02-05 at 14:56 +0000, Andy Davies wrote:
> > Hi
> >
> > Just wanted to check with you guys so see what would be the best way
> > to structure some code.
> >
> > I have four stepper motors controlled by a windows form via an
> > Arduino.
> >
> ...
> > Any suggestions as to how to structure the code will be most welcome.
>
>
> Personally, I would have the PC->Arduino instructions to be able to set
> target positions for the steppers, then have a synchronize/activate
> command, so that you don't have a time delay between one being updated
> and the next.
>
> in code structure, probably a bunch of globals with the target position
> numbers, have the main loop read the info from the pc and update the
> targets as commands come in, and a timer interrupt routine which moves
> the motors towards their target positions a little bit each time
> around.
>
> that would be my initial approach anyway
>
>
>
>
> _______________________________________________
> Hackspace mailing list
> Hackspace at swansea.hackspace.org.uk
> http://swansea.hackspace.org.uk/mailman/listinfo/hackspace
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://swansea.hackspace.org.uk/pipermail/hackspace/attachments/20190206/65d9dc74/attachment.html>


More information about the Hackspace mailing list