Lisp HUG Maillist Archive

LISP in robotics application

Hello all.

This is my first post though I've been following for several years. 
I have a question regarding running several servo motors at the same time from within LISP.

Basically I already have an interface between the actual servo motors and my LISP based program and with this I can command a servo to move to a specific position.

The command looks like:  (servo-move num pos)  where num is the number of the servo and pos is the relative position, both digits.

What I want to do is have more than one servo move at the same time.  Is this possible and how can it be programmed?

Thanks

Re: LISP in robotics application

Hi,

You didn't say it, but I gather that the servo-move function is blocking - it only returns after the motor has ceased to move, more or less. Is that right? Otherwise, you could just call servo-move multiple times and be done with it.

To perform multiple operations in parallel one often resorts to using threads, directly or behind some abstraction layer. The topic is vast and complex and I don't know where you are starting from. However, at a minimum you should make sure (e.g. by reading documentation) that the servo-move function can indeed be called by multiple execution threads or "processes" as they are often called in Lisp systems.

Cheers,
Alessio

On 1 April 2016 at 13:50, Robert Zeiler <rezeiler1970@gmail.com> wrote:
Hello all.

This is my first post though I've been following for several years. 
I have a question regarding running several servo motors at the same time from within LISP.

Basically I already have an interface between the actual servo motors and my LISP based program and with this I can command a servo to move to a specific position.

The command looks like:  (servo-move num pos)  where num is the number of the servo and pos is the relative position, both digits.

What I want to do is have more than one servo move at the same time.  Is this possible and how can it be programmed?

Thanks

Fwd: LISP in robotics application


---------- Forwarded message ----------
From: Alessio Stalla <alessiostalla@gmail.com>
Date: Fri, Apr 1, 2016 at 8:30 AM
Subject: Re: LISP in robotics application
To: Robert Zeiler <rezeiler1970@gmail.com>


You replied to me alone, if you reply to the mailing list we can continue there and other people can chime in ;)

On 1 April 2016 at 14:23, Robert Zeiler <rezeiler1970@gmail.com> wrote:
Thanks for the reply.

The function is not blocked and works fine for individual servos.  
To be more specific by example perhaps I can routinely use the following:

(servo-move 47 1500)
(servo-move 48 1350)

The first will move servo 47 to position 1500 and the second moves servo 48 to position 1350.
It works fine but in sequence.  In other words, servo 47 moves first and then 48.

I would like to move both servos at the same time to their respective positions.  

Also, I am a relative beginner at LISP.

On Fri, Apr 1, 2016 at 8:08 AM, Alessio Stalla <alessiostalla@gmail.com> wrote:
Hi,

You didn't say it, but I gather that the servo-move function is blocking - it only returns after the motor has ceased to move, more or less. Is that right? Otherwise, you could just call servo-move multiple times and be done with it.

To perform multiple operations in parallel one often resorts to using threads, directly or behind some abstraction layer. The topic is vast and complex and I don't know where you are starting from. However, at a minimum you should make sure (e.g. by reading documentation) that the servo-move function can indeed be called by multiple execution threads or "processes" as they are often called in Lisp systems.

Cheers,
Alessio

On 1 April 2016 at 13:50, Robert Zeiler <rezeiler1970@gmail.com> wrote:
Hello all.

This is my first post though I've been following for several years. 
I have a question regarding running several servo motors at the same time from within LISP.

Basically I already have an interface between the actual servo motors and my LISP based program and with this I can command a servo to move to a specific position.

The command looks like:  (servo-move num pos)  where num is the number of the servo and pos is the relative position, both digits.

What I want to do is have more than one servo move at the same time.  Is this possible and how can it be programmed?

Thanks




Re: LISP in robotics application

Robert,

Do you have the source code for the function the moves a single servo?

You might have to write a higher-level wrapper that takes a list of servo parameters then loops around each one, actuating one degree at a time or whatever the step unit is for your setup. As each servo reaches its target position, remove it from the list. Rinse repeat until the target list is empty because all servos are parked.

This means that for a while you'd have parallel servo operation but as they arrive at their end positions they'd drop out if you see what I mean.

Maybe that helped, maybe it didn't!

Sean.

On 1 April 2016 at 12:50, Robert Zeiler <rezeiler1970@gmail.com> wrote:
Hello all.

This is my first post though I've been following for several years. 
I have a question regarding running several servo motors at the same time from within LISP.

Basically I already have an interface between the actual servo motors and my LISP based program and with this I can command a servo to move to a specific position.

The command looks like:  (servo-move num pos)  where num is the number of the servo and pos is the relative position, both digits.

What I want to do is have more than one servo move at the same time.  Is this possible and how can it be programmed?

Thanks

Re: LISP in robotics application

Hello Robert,

For processes that block, and/or processes that you want to run independent of each other, multi-threading is indeed your mechanism.  I believe David McClain had made a library of handy functions public, of which reppy-channels was a particularly useful abstraction of multi-thread functionality.  Perhaps it would be good to re-publish the link to the library if it's still available.  Dave?

Ray Laning

On 4/1/2016 7:50 AM, Robert Zeiler wrote:
Hello all.

This is my first post though I've been following for several years. 
I have a question regarding running several servo motors at the same time from within LISP.

Basically I already have an interface between the actual servo motors and my LISP based program and with this I can command a servo to move to a specific position.

The command looks like:  (servo-move num pos)  where num is the number of the servo and pos is the relative position, both digits.

What I want to do is have more than one servo move at the same time.  Is this possible and how can it be programmed?

Thanks


Virus-free. www.avast..com

Re: LISP in robotics application



On 1 April 2016 at 14:23, Robert Zeiler <rezeiler1970@gmail.com> wrote:
Thanks for the reply.

The function is not blocked and works fine for individual servos.  
To be more specific by example perhaps I can routinely use the following:

(servo-move 47 1500)
(servo-move 48 1350)

The first will move servo 47 to position 1500 and the second moves servo 48 to position 1350.
It works fine but in sequence.  In other words, servo 47 moves first and then 48.

That means that the function is blocking. It only returns control to the calling thread when the move operation is completed, therefore that thread cannot be reused to perform other operations while servo-move is executing, be it calling servo-move or doing other things.
By contrast, a non-blocking function would return control almost immediately, leaving the motor moving in the background while the execution thread can happily continue executing other code.
 
I would like to move both servos at the same time to their respective positions.  

If servo-move can be called concurrently from multiple threads (what does its documentation say? What library is it part of?) then you can call it on multiple threads, for example using lparallel as proposed. But if you're new to Lisp, particularly if you haven't set up ASDF and Quicklisp yet, I suggest you to use just the concurrency primitives offered by LispWorks [1], which will be probably be lower-level but will teach you the concepts "the hard way". Later you'll learn how to write simpler, higher-level code using maybe some library like lparallel.

Splitting a call to servo-move in several smaller movements and interleaving those sequentially may also work, although I don't think it is fit for this particular application - moving physical things in the real world.
 
Also, I am a relative beginner at LISP.

These are issues that go beyond Lisp and are applicable to every programming language. So it is particularly difficult because you have first to grasp the general concepts, then understand how they can be expressed in Lisp.

[1] I seldom use LW myself and know it only superficially, but a quick search brought me here: http://www.lispworks.com/documentation/lw70/LW/html/lw-133.htm#pgfId-885976
 
On Fri, Apr 1, 2016 at 8:08 AM, Alessio Stalla <alessiostalla@gmail.com> wrote:
Hi,

You didn't say it, but I gather that the servo-move function is blocking - it only returns after the motor has ceased to move, more or less. Is that right? Otherwise, you could just call servo-move multiple times and be done with it.

To perform multiple operations in parallel one often resorts to using threads, directly or behind some abstraction layer. The topic is vast and complex and I don't know where you are starting from. However, at a minimum you should make sure (e.g. by reading documentation) that the servo-move function can indeed be called by multiple execution threads or "processes" as they are often called in Lisp systems.

Cheers,
Alessio

On 1 April 2016 at 13:50, Robert Zeiler <rezeiler1970@gmail.com> wrote:
Hello all.

This is my first post though I've been following for several years. 
I have a question regarding running several servo motors at the same time from within LISP.

Basically I already have an interface between the actual servo motors and my LISP based program and with this I can command a servo to move to a specific position.

The command looks like:  (servo-move num pos)  where num is the number of the servo and pos is the relative position, both digits.

What I want to do is have more than one servo move at the same time.  Is this possible and how can it be programmed?

Thanks



Re: LISP in robotics application

David McClain <dbm@refined-audiometrics.com> writes:

> I do indeed do this sort of thing quite often. There are any number of
> approaches that can be used. I constructed the Reppy Channel paradigm,
> following John Reppy’s Concurrent ML philosophy, as near as possible
> using only Lisp. But that is a higher order protocol than may be
> required for so simple a task as has been outlined with the servo
> motors. Reppy Channels attempt to encapsulate the notion of
> communicating threads as first class objects with functions that can
> operate on collections of them. But I strongly encourage anyone
> contemplating this approach to become familiar with the philosophy
> outlined by John in his textbook on Concurrent ML.
>
> The core Lispworks includes SMP threading already, and provides
> mailbox communications. From the sounds of things, this may be all
> that is required. Just be aware that SMP implies that things can
> change beneath you while you are running in a thread. Multiple threads
> may truly be running concurrently. And Martin has provided a wonderful
> collection of primitives to ensure fault-free memory sharing and
> communications.
>
> I also urge anyone embarking in this kind of programming to become
> aware of the work done by Pascal Bourguignon and his team in Europe.

You must be confusing me with somebody else, but I can't pinpoint
exactly who. 


> I have also abstracted the Butterfly system of process control and
> communications to something I call the BlueBird library, which unifies
> everything from simple function dispatch, to LW mailboxes, to Reppy
> Channels, to Butterfly processes (think distributed Erlang here), and
> more.
>
> In general, depending on your performance requirements, I have found
> that instantiating a stable of worker threads, to be dispatched on a
> (PAR form1 form2 form3 …) for parallel execution is superior. Why kill
> the horses after they have run the track?
>
> [G-d, I hate these email systems — auto-assigning the wrong return address all the time… ]

On such a project, I would worry early about the real-time constraints
in driving a robot servo-motors from lisp.  I'm not saying that it
wouldn't be possible or very interesting to write the high level
thinking and even motor system of the robot in lisp.  But I've got the
impression that you might still need dedicated micro-controller to
drive the servo-controler precisely and reactively, for precise and safe
movement of the robot effectors. Notably you probably will want to
implement safety reflexes at the level of the microcontrolers, near the
servos and sensors. (The higher level lisp system can then re-evaluate
the situation and decide how to proceed).

On the other hand, it's quite possible that the layers below lisp could
be as much or even more of a problem than lisp itself (garbage
collector, and multi-threading scheduling in lisp, process and memory
(swap!?) management in linux; I don't know if the real-time options of
linux allow for strong enough constraints to be able to drive several
robot servo-motor with the required constraints for safety).

In any case, my point here is that I would advise to run some benchmarks
and tests to validate the feasibility.

-- 
__Pascal Bourguignon__                 http://www.informatimago.com/
“The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.” -- Carl Bass CEO Autodesk

_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html


Re: LISP in robotics application

I have been reading your posts with great interest and plan to explore some of the suggestions.  As a point of clarification for questions raised in earler posts, the servos are controlled by a separate board called SD84 and is put out by Daventech. It works through the USB port on the computer that also is running LW and the robot software. There is an interface for the SD84 that exists within the robot software in LISP. The robot also has a microcontroller that handles most of the routines such as sensors, voltage monitoring and motor propulsion units. 

I hope that answers some of the questions but if not, please continue to ask and post.

I have several books on LISP and have been involved with the language for several years, learning as I go.  I do have several "threads" in the current robot software for such things as speech recognition/understanding, emotions etc.  I have to understand and figure out how the thread concept would work for running/commanding servos.  Any help would be appreciated. 

Robert

On Fri, Apr 1, 2016 at 7:50 PM, David McClain <dbm@refined-audiometrics.com> wrote:

Sorry... I meant Pascal Costanza

Dr. David McClain
dbm@refined-audiometrics.com
Tel: (+1) 520-529-2437

Sent from my iPad

> On Apr 1, 2016, at 13:23, Pascal J. Bourguignon <pjb@informatimago.com> wrote:
>
>
> David McClain <dbm@refined-audiometrics.com> writes:
>
>> I do indeed do this sort of thing quite often. There are any number of
>> approaches that can be used. I constructed the Reppy Channel paradigm,
>> following John Reppy’s Concurrent ML philosophy, as near as possible
>> using only Lisp. But that is a higher order protocol than may be
>> required for so simple a task as has been outlined with the servo
>> motors. Reppy Channels attempt to encapsulate the notion of
>> communicating threads as first class objects with functions that can
>> operate on collections of them. But I strongly encourage anyone
>> contemplating this approach to become familiar with the philosophy
>> outlined by John in his textbook on Concurrent ML.
>>
>> The core Lispworks includes SMP threading already, and provides
>> mailbox communications. From the sounds of things, this may be all
>> that is required. Just be aware that SMP implies that things can
>> change beneath you while you are running in a thread. Multiple threads
>> may truly be running concurrently. And Martin has provided a wonderful
>> collection of primitives to ensure fault-free memory sharing and
>> communications.
>>
>> I also urge anyone embarking in this kind of programming to become
>> aware of the work done by Pascal Bourguignon and his team in Europe.
>
> You must be confusing me with somebody else, but I can't pinpoint
> exactly who.
>
>
>> I have also abstracted the Butterfly system of process control and
>> communications to something I call the BlueBird library, which unifies
>> everything from simple function dispatch, to LW mailboxes, to Reppy
>> Channels, to Butterfly processes (think distributed Erlang here), and
>> more.
>>
>> In general, depending on your performance requirements, I have found
>> that instantiating a stable of worker threads, to be dispatched on a
>> (PAR form1 form2 form3 …) for parallel execution is superior. Why kill
>> the horses after they have run the track?
>>
>> [G-d, I hate these email systems — auto-assigning the wrong return address all the time… ]
>
> On such a project, I would worry early about the real-time constraints
> in driving a robot servo-motors from lisp.  I'm not saying that it
> wouldn't be possible or very interesting to write the high level
> thinking and even motor system of the robot in lisp.  But I've got the
> impression that you might still need dedicated micro-controller to
> drive the servo-controler precisely and reactively, for precise and safe
> movement of the robot effectors. Notably you probably will want to
> implement safety reflexes at the level of the microcontrolers, near the
> servos and sensors. (The higher level lisp system can then re-evaluate
> the situation and decide how to proceed).
>
> On the other hand, it's quite possible that the layers below lisp could
> be as much or even more of a problem than lisp itself (garbage
> collector, and multi-threading scheduling in lisp, process and memory
> (swap!?) management in linux; I don't know if the real-time options of
> linux allow for strong enough constraints to be able to drive several
> robot servo-motor with the required constraints for safety).
>
> In any case, my point here is that I would advise to run some benchmarks
> and tests to validate the feasibility.
>
> --
> __Pascal Bourguignon__                 http://www.informatimago.com/
> “The factory of the future will have only two employees, a man and a
> dog. The man will be there to feed the dog. The dog will be there to
> keep the man from touching the equipment.” -- Carl Bass CEO Autodesk
>
> _______________________________________________
> Lisp Hug - the mailing list for LispWorks users
> lisp-hug@lispworks.com
> http://www.lispworks.com/support/lisp-hug.html
>
>


_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html


Updated at: 2020-12-10 08:32 UTC