Discussion:
[Tutor] How to go about a simple object grabbing in python (given coordinates of arms and objects)
(too old to reply)
marc nicole
2024-06-22 21:54:21 UTC
Permalink
My code is just an attempt at the task, it is not exact as what relates to
the coordinates (e.g., doesn't account for the size of the object. I would
like to have a idea on the general approach to such problems (even a pseudo
code would do)

"Get the hands rapidly enough in the vicinity and then do some fine
coordinated motions to capture the object and then presumably move it."
seems to be a good approach indeed,
The grabbing with both hands code should be more precise.

Thanks for the help anyways!
Marc,
Could you specify what is wrong with what you are doing? you show us code
that uses an environment you point to that is largely outside of basic
Python.
There is no one way to get from point A to point B and various constraints
you have not mentioned can apply. How many joints does the assemblage have
and what are the limits and costs associated with each. Cam there be
barriers along a route, including to the side where they may brush part of
your equipment. Are other things moving (independently even) that may end
up blocking.
You seem to need both "hands" and presumably at the same time. So
solutions can take that into account. You need to define what is meant by
contacting the object to move and you don't want to approach it and hit
with some speed.
So, the problem may be in parts. Get the hands rapidly enough in the
vicinity and then do some fine coordinated motions to capture the object
and then presumably move it.
If you could point to what code is not doing what is expected, someone who
knows the details or is willing to learn, might help, If you want an
overall algorithm, there may be some people could share but they may not
easily translate into the package of sorts you are using.
But the web site you point us to may well already contain examples of
doing some aspects that you might learn from.
For me, this is too detailed to focus on as I struggle to figure out how
to move my hands to different parts of my keyboard while looking ...
And that may be one variant of an algorithm where instead of trying to
move all the way, you move art-way and LOOK where you are, then repeat.
Sent with Proton Mail secure email.
Hello to all of this magnificent community!
I have this problem I had already spent a few days on and still can't
figure out a proper solution.
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
tracker_service= session.service("ALTracker")
xyz_pos = tracker_service.getTargetPosition(motion.FRAME_TORSO)
http://doc.aldebaran.com/2-8/naoqi/motion/control-cartesian.html#motion-cartesian-effectors
Then I get to move the right arm towards nearby the object using the
effector = "RArm"
frame = motion.FRAME_TORSO
effector_offset =
almath.Transform(self.motion.getTransform(effector, frame, False))
effector_init_3d_position = almath.position3DFromTransform(
effector_offset)
target_3d_position = almath.Position3D(target_position)
move_3d = target_3d_position - effector_init_3d_position
moveTransform = almath.Transform.fromPosition(move_3d.x,
move_3d.y, move_3d.z)
target_transformer_list = list(moveTransform.toVector())
times = [2.0]
axis_mask_list = motion.AXIS_MASK_VEL
self.motion.transformInterpolations(effector, frame,
target_transformer_list, axis_mask_list, times).
http://doc.aldebaran.com/1-14/dev/python/examples/almath/index.html?highlight=offset
This question is specific to NAO environment but in general how to go
about this task? what is a most common algorithm used in this case? Do
I have to also get the side of the object in order to know where
exactly the arms should be placed?
_______________________________________________
https://mail.python.org/mailman/listinfo/tutor
marc nicole
2024-06-22 12:41:47 UTC
Permalink
Hello to all of this magnificent community!

I have this problem I had already spent a few days on and still can't
figure out a proper solution.

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:

tracker_service= session.service("ALTracker")
xyz_pos = tracker_service.getTargetPosition(motion.FRAME_TORSO)


src:
http://doc.aldebaran.com/2-8/naoqi/motion/control-cartesian.html#motion-cartesian-effectors


Then I get to move the right arm towards nearby the object using the
following code:

effector = "RArm"

frame = motion.FRAME_TORSO
effector_offset =
almath.Transform(self.motion.getTransform(effector, frame, False))
effector_init_3d_position = almath.position3DFromTransform(
effector_offset)

target_3d_position = almath.Position3D(target_position)
move_3d = target_3d_position - effector_init_3d_position
moveTransform = almath.Transform.fromPosition(move_3d.x,
move_3d.y, move_3d.z)
target_transformer_list = list(moveTransform.toVector())
times = [2.0]
axis_mask_list = motion.AXIS_MASK_VEL
self.motion.transformInterpolations(effector, frame,
target_transformer_list, axis_mask_list, times).

src: http://doc.aldebaran.com/1-14/dev/python/examples/almath/index.html?highlight=offset
This question is specific to NAO environment but in general how to go
about this task? what is a most common algorithm used in this case? Do
I have to also get the side of the object in order to know where
exactly the arms should be placed?
marc nicole
2024-06-24 09:23:30 UTC
Permalink
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.
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
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
http://www.flickr.com/photos/alangauldphotos
_______________________________________________
https://mail.python.org/mailman/listinfo/tutor
a***@gmail.com
2024-06-24 21:57:00 UTC
Permalink
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=***@python.org> On Behalf Of marc nicole via Python-list
Sent: Monday, June 24, 2024 5:24 AM
To: Alan Gauld <***@yahoo.co.uk>; python-***@python.org; ***@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.
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
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
http://www.flickr.com/photos/alangauldphotos
_______________________________________________
https://mail.python.org/mailman/listinfo/tutor
--
https://mail.python.org/mailman/listinfo/python-list
Loading...