Marc,

Several people have supplied feedback on whether your request is a good fit for 
here. Ultimately it is up to the owner/moderator. In particular, your request 
to the Tutor List may not fit the purpose and be a bit complex  and to the main 
Python List also outside some common usage whether it is about a specific 
module or product you are using, or asking about algorithms in a very general 
way.

You question has evolved to being about algorithms, more than about Python as a 
basic language or even commonly used modules.

So, I suggest you simplify your model and then maybe bring it in-line with the 
module(s) you showed us you were using. Some of what you ask sounds like it 
would be extremely commonly done in things like robotics, or even just machines 
with moving parts.

Consider the somewhat related concept often seen of how you get from one place 
to another in parts of Manhattan where most of the streets run either in one 
direction or the orthogonal direction. How do you get from say East 14th Street 
at 1st Avenue to West 28th Street and 11th Avenue? This is a slight imitation 
of how to move a robotic arm that can mainly either go one way or another but 
not both at once. And, in the real world, parts of Manhattan are more complex 
with streets ending or renaming or running more diagonally or huge voids like 
Central Park.

The number of solutions is huge for walking, and smaller for driving as some 
streets are one way. But assuming you avoid wasteful paths (except when roads 
are closed for endless purposes) and you do not take a path through Brooklyn, 
Queens and The Bronx and back to Manhattan as in the NY Marathon that also 
touches another borough, the solutions mainly look like this:

Go as far horizontally as you need and then as far vertically.
Or, do vertical, then horizontal.
Or lots of combined versions such as climbing stairs by doing a block or three 
one way then some in the other and repeat.

The above is referred to as Manhattan Distance, as compared to other measures 
like Euclidean distance.

So back to your robot arm, you can see a set of simple solutions where you make 
a sort of triangle with the direct Euclidean arm being a hypoteneuse and the  X 
and Y movements are the other two sides. You can then break up your problem as 
heading one way and pausing and turning the other way and stopping just short 
of the object you want. If there are no obstacles, you can do that in either 
order. Or, you could alternate in smaller amounts and get to the same 
destination. 

Grabbing it would be something else I will not address except to say that 
depending on what is grabbing and how it is shaped, you may need to aim not for 
the object, but the appropriate distance and direction so that when you stop 
moving, the "grasper" can close on it, again, avoiding existing obstacles. And 
note, speed is a consideration as many things need to be approached slowly and 
gently.

Next, consider what it would mean if you could have a combined motion based on 
both operations allowed at the same time. Consider a robot that is on wheels 
that can move horizontally while also having a "lift" component that lifts the 
part with the graspers vertically. Both could be programmed to run in tandem at 
appropriate speeds so the graspers are traveling along the hypotenuse I mention 
and are going the shortest path. This might be faster and more economical in 
other ways but can be more complex. And, it may be the robot does not have 
power or computing ability to do both at the same time. Your design is beyond 
vague.

Both of the approaches above make a plan and carry it out. But in the real 
world, many algorithms must adjust and work somewhat probabilistically. One 
algorithm for say catching a moving object, especially one that can change 
speed and direction a bit, like a running dog or a kite flying in the wind, is 
to locate where the object seems to be now, perhaps just a direction and a 
guess at distance, and maybe with some observation make a guess at where it 
might be at some time in the future that is approximately when you might move 
the robot near there. Then, use a technique like above (or completely 
different) that perhaps aims to get you something like halfway there. Monitor 
along the way to update your position and the newest destination position (if 
it is moving) and re-evaluate and adjust for the next round and maybe evaluate 
again as you approach halfway or so, again. Eventually, if you are close, slow 
down and gradually try to come to a stop where you can grab. If the object 
reacts to your attempting to go after it, it can be complex. And, you may 
overshoot and sort of circle back.

Now, expand the problem more if needed. What does the robot look like. How many 
places can it bend? For example, can it have something like two or more elbows, 
perhaps one allowing twisting of up to 30 degrees and one moving forward and 
backward and another allowing movement side to side, up to some number of 
degrees. Are all these degrees of freedom absolute or are there constraints? 
For example, to turn beyond some number of combined degrees may not be allowed, 
and instead of turning 400 degrees clockwise, you simply move forward or back 
to a 40 degree angle from some baseline. Perhaps bending certain ways while 
carrying some kind of weight, can cause it to topple. There can be an amazing 
number of considerations that cannot be anticipated and depend on specific 
choices in making a robot. A longer arm, for example, requires fewer degrees of 
turn to move some known amount.

As before, there are an amazing number of ways to do such things in any 
language as we are discussing "algorithms."  If the goal is finding A WAY, any 
simpler ones will do. If it is to find an optimum way, we have tons you need to 
learn and consider. If this was a contest and a contestant on the other side of 
the object was supposed to start at the same time as you, and the first to grab 
the object wins, ...

And, if this has machine learning components, which python is in some ways well 
suited to, you may design a robot that moves clumsily and almost randomly, at 
first, and then "learns" from such experiments and gradually figures out better 
and maybe even better ways until it just does well at reaching and grasping for 
any similar enough problems and maybe even somewhat different ones. I suspect 
that is more than you need but in real-world robotics, may be part of how to 
make more sophisticated and even general-purpose robots.

But if you want to talk more about python in doing parts of this, there are 
several things to consider. Base python has data structures you can use to 
store and manipulate many things you may need to keep track of, or if planning 
a whole routine in advance, things like lists to hold the steps you can then 
hand over to function. Add-on modules like numpy can be very helpful in 
extending python for some purposes, as an example. There are probably many 
functions that already do things like given two points, calculate the slope and 
distance of a direct line between them, or compare two or more approaches and 
return what is best in some way and so on. There ways of running things in 
parallel while sharing some data while making sure to avoid them interfering 
with each other. You can set timers to wake up and recalculate and much more. 
Then there are all kinds of modules that help you with parts. There is a good 
chance that whatever you showed us is just one of many such modules people have 
shared or sold for purposes similar enough to your robot problem. 

But if your main goal is to do this mainly with the kind of functionality you 
pointed at, since likely none of us have read the documentation, nor care to 
without getting paid a lot, it means you should be reading a lot and looking 
carefully at examples that may apply AND finding resources more about that than 
asking people about "python" and especially asking python people how one does 
things in robotics. Mose specific questions such as how to calculate a distance 
using python, will likely get helpful responses, and brief but complete 
examples of code that you want debugged, may also be responded to. But asking 
for complex algorithms in the abstract probably will result in silence or ever 
more elaborate debates till a moderator suggest a halt! LOL!

Python, like many languages, is a fairly general purpose language that can do 
many things well, and some less well, and some mainly by standing on it's head 
while including software built in other languages. Your project may happen to 
be in python, but more likely most of it should be using functions built-in to 
whatever add-ons you are using if it is designed to do what you want. Your goal 
is not to create it all from scratch, I would think. You may end up using just 
a little base python to glue things together.

Good Luck.


-----Original Message-----
From: Python-list <python-list-bounces+avi.e.gross=gmail....@python.org> On 
Behalf Of marc nicole via Python-list
Sent: Monday, June 24, 2024 5:24 AM
To: Alan Gauld <alan.ga...@yahoo.co.uk>; python-list@python.org; 
tu...@python.org
Subject: Re: [Tutor] How to go about a simple object grabbing in python (given 
coordinates of arms and objects)

What are the parameters to account for in this type of algorithm? are there
some checks to perform the arm moves ? for example angle moves or cartesian
moves based on some distance thresholds? Any idea about the
pseudo-algorithm is welcome.

Thanks.

Le dim. 23 juin 2024 à 10:33, Alan Gauld via Tutor <tu...@python.org> a
écrit :

> On 22/06/2024 13:41, marc nicole wrote:
>
> > So, given the x,y,z coordinates of a target object and the offset x,y,z
> of
> > arms of a robot, what is a good algorithm to perform to grab the object
> > between the hands (either from both sides or from below all using both
> > hands).
> >
> > Specifically, my problem is applied to a NAO robot environment where I
> > retrieve a target object coordinates using the following code:
>
> This is almost entirely outside the Python domain and all within
> your 3rd party environment. Do they have a user forum or mailing
> list? You will probably get better results asking there?
>
> Another possibility is that you are using a Python wrapper around
> a C (or other language) library and there might be FAQs, fora or
> lists supporting that. If so you should be able to translate
> their examples to your Python code?
>
> In terms of generic solutions the only thing I can suggest that
> might help is to research collision detection algorithms.
> Wikipedia is likely a good starting point.
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> http://www.flickr.com/photos/alangauldphotos
>
>
>
> _______________________________________________
> Tutor maillist  -  tu...@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
-- 
https://mail.python.org/mailman/listinfo/python-list

-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to