Giter Club home page Giter Club logo

Comments (8)

whzup avatar whzup commented on May 28, 2024 1

Is there already someone working on this? I'd like to contribute to this project it looks really interesting. I'm new to GitHub and have some experience in Python and this seems like a nice possibility to improve my Python and writing skills!

from pyswarms.

ljvmiranda921 avatar ljvmiranda921 commented on May 28, 2024 1

Hey @whzup ! Welcome!

No one's working on this and sure this one's yours 👍 Be sure to fork the development branch and simply start the notebook inside the examples/ directory 😄

If you have any questions (the github process in general, on inverse kinematics, etc.), do not hesitate to ping us!

from pyswarms.

whzup avatar whzup commented on May 28, 2024

Thanks a lot!
I have a question regarding the function that is to be optimized. In the gist to your blog post on row 43 of roboticArm.py you use np.array([Etip[0,3],Etip[1,3],Etip[2,3]]) as the position function, why is it that the position is exactly the third column of the matrix? Also, I'm guessing that Etip is the transformation matrix for the end tip so that if you multiply it by a vector the position of the end tip would be the result, or am I wrong with that?

from pyswarms.

ljvmiranda921 avatar ljvmiranda921 commented on May 28, 2024

Hi @whzup !

Awesome questions! Made me review my robotics basics again. 😆 So, for a Denavit Hartenberg (D-H) transformation matrix, the values in the fourth column (we start indexing by 0) describes the translation from axis x to axis y (Check the last sentence in this link). That's why we are only taking those values.

Imagine your elbow joint as axis x and your wrist joint as axis y. If you want to know how your wrist joint translates with respect to your elbow joint, you compute the D-H matrix by doing a dot-product:

import numpy as np
transform_matrix_from_elbow_to_wrist = np.dot(elbow_joint, wrist_joint)

The result is a 4 x 4 matrix that we now know as the D-H transformation matrix. But what if we want to know how the end-tip of our index finger translates with respect to our elbow joint? Then, we successively compute the transformation matrix from elbow to wrist, then wrist to index finger tip. Same reason why there 's a succession of np.dots to obtain Etip.

I'm guessing that Etip is the transformation matrix for the end tip so that if you multiply it by a vector the position of the end tip would be the result, or am I wrong with that

In hindsight, I think that my variable name is misleading. You are right that the Etip is the transformation matrix from the zeroth-axis to the end-tip. Although I am not sure about multiplying a vector to find the end-tip position. Usually we just obtain the three values in the fourth column.

from pyswarms.

whzup avatar whzup commented on May 28, 2024

Thanks for the fast response. Really interesting to learn some things about robots on the fly 😋.
I have some other issues though:

  1. The pyswarms.singleGlobalBestPSO class creates an array of length n_particles with each element being an array of the six parameters. I think this deliberate but it kind of complicates the function for the transformation matrix. I more or less copied your version of the function.

  2. Is there a way to include a "target" in the pyswarms.singleGlobalBestPSO class such that I can just feed it the function and the target or do I have to manually add this in the optimization function? Alternatively, can the pyswarms.singleGlobalBestPSO class take a function with more than one argument as an input for the optimization? I have been looking around in the source code but it seemed to me that it only works with functions that only take one input.

For lack of a better alternative, here a pastebin of my code (copied into IDLE from the notebook)

Thanks for the help thus far. I very much appreciate such a welcoming atmosphere!

from pyswarms.

ljvmiranda921 avatar ljvmiranda921 commented on May 28, 2024

Hey @whzup ! Hope you are enjoying!

  1. Is there a way to minimize this complexity? I made it deliberate before so that we can explicitly see the matrix itself, but I think we can leave that one out, no problem. We can just state in the notebook that there is a transformation matrix but we'll just take the following parameters.

So what I'm thinking is like this (feel free to deviate as you please):

[input_swarm]   --> get_endtip_pos() --> get_distance(target) --> [fitness]

In terms of matrix shapes (you can check them using np.shape):

(n_particles, 6) --> in: (n_particles, 6), out: (n_particles, 3) --> in: (n_particles, 3) target=(3, ), out: (n_particles, ) --> (n_particles,)
  • Inside the get_endtip_pos(), instead of computing the whole transformation matrix, we can just compute for the three translation elements in the fourth column (a * np.cos(theta), a * np.sin(theta), d). This saves us from indexing needlessly. Although I think it's important that the input dimensions should still be 6.
  1. For target, I think for now this should be defined in the objective function itself. I realized that there may be cases where the objective function must be parameterized. Maybe next time we can update pyswarms to take on **kwargs in the objective function when computing.

Oh, you should definitely check out replt.it. It enables you to execute pasted code, and even install pyswarms (and other PyPI libraries) in the process! 👍

Feel free to message if you have questions!

from pyswarms.

bradahoward avatar bradahoward commented on May 28, 2024

Being able to parameterize the objective function is really useful to me. I got this to work using **kwargs and was about ready to submit a PR when i saw this discussion. Do you guys mind if submit one?

from pyswarms.

ljvmiranda921 avatar ljvmiranda921 commented on May 28, 2024

Hi @bradahoward ! Yes please feel free to open a PR. But I'd recommend you to open an Issue first so can keep a history of all things happening in this project 👍

While you're at it, I'm wondering if it's better to use *args than **kwargs. Would you mind investigating that as well and check which one works in a usability standpoint?

from pyswarms.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.