Git Product home page Git Product logo

geometry's Introduction

Geometry

An Arduino library for representing where things are in relation to other things in 3D space.

What Does That Mean?

In lots of problems in robotics and computer vision we need to be able to describe the position and orientation (aka its pose) of something relative to some coordinate frame. With robot arms we may want to represent the pose of the end effector relative to the robot's base, in mobile robotics we may want to track the pose of the rover relative to its initial position. Whatever the case, we're often confronted with this kind of situation:

Transformation

The aim of this library is to allow us to represent the pose (and spatial velocity) of End Effector in relative Base even if we don't have a direct measurement between the two.

Representing rotation

Geometry supports all your favourite 3D rotation formats, as well as functions to convert them into rotation matrices and back again:

  • Rotation matrices
  • Quaternions
  • Euler angles (all 24 flavors of them)
  • Axis Angles (kind of)

The default representation is a rotation matrix, a 3x3 orthogonal matrix:

Rotation

Which can be converted to a quaternion like so:

Rotation R;
Quaternion q(R); // create a quaternion from a rotation matrix
q.to_rotation_matrix(); // and convert back again

Or euler angles like so:

EulerAngles euler(R); // create extrinsically rotated, XYZ rotation order euler angles from a rotation matrix
euler.to_rotation_matrix(); // and convert back again

If this note on extrinsic XYZ rotation order doesn't ring any bells, take a look at the EulerAngles example for a nice rundown of how tricky that format can be.

Geometry also implements a class for angular velocity which can also be thought of as the axis-angle representation for rotation, where the axis of the rotation is scaled by its magnitude. An angular velocity can be converted into a rotation matrix using the exponential function and back again using the logarithm:

AngularVelocity w(0.1, 0.2, 0.3);
Rotation R = exp(w);
AngularVelocity also_w = log(R);

Pose and Twist

A Pose combines a rotation with a translation to fully describe the location of a body in space. You can think of a Pose as a cartesian position concatenated onto a rotation matrix like so:

Pose

Poses can represent the location of a body in space or a transformation from one coordinate frame to another. For more information on that take a look at the HowToUse example. If you want to dive deeper, take a look at the PoseGraph example for a nice self-contained implementation of something that resembles ROS's TF package.

Analogous to rotation and angular velocity, the velocity counterpart of a pose is a Twist. Which combines an angular velocity llinear velocity to fully represent the velocity of a body in space. We can convert a twist to a pose and back again using the exponential and logarithm functions:

Twist V(0.1, 0.2, 0.3, 0.4, 0.5, 0.6);
Pose T = exp(V);
Twist also_V = log(T);

These conversions allow us to transform spatial velocities between different coordinate frames which allows for some pretty fancy kinematics algorithms. If you're interested in that, have a look at the InverseDynamics example.

geometry's People

Contributors

grassjelly avatar tomstewart89 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

geometry's Issues

to Euler Angles

If we have an indentity matrix and get the euler angles, theta is set to -90°.
The method does not cover the case if (*this)(2,0) is 0. In this case the method executes the last else case that should only executed if (*this)(2,0) is 1. The first if statement should be changed. ?!

`Matrix<3,2> Rotation::ToEulerAngles()
{
Matrix<3,2> ret;

if((*this)(2,0) != 0)
{
    ret(1,0) = -asin((*this)(2,0));
    ret(1,1) = M_PI - ret(1,0);

    ret(0,0) = atan2((*this)(2,1) / cos(ret(1,0)),(*this)(2,2) / cos(ret(1,0)));
    ret(0,1) = atan2((*this)(2,1) / cos(ret(1,1)),(*this)(2,2) / cos(ret(1,1)));

    ret(2,0) = atan2((*this)(1,0) / cos(ret(1,0)),(*this)(0,0) / cos(ret(1,0)));
    ret(2,1) = atan2((*this)(1,0) / cos(ret(1,1)),(*this)(0,0) / cos(ret(1,1)));
}
else
{
    ret(2,0) = ret(2,1) = 0;

    if((*this)(2,0) == -1)
    {
        ret(1,0) = ret(1,1) = M_PI_2;
        ret(0,0) = ret(0,1) = atan2((*this)(0,1),(*this)(0,2));
    }
    else
    {
        ret(1,0) = ret(1,1) = -M_PI_2;
        ret(0,0) = ret(0,1) = atan2(-(*this)(0,1),-(*this)(0,2));
    }
}

return ret;

}`

Missing license

Hi Tom,

Thanks for this great library. I'm currently tinkering with it and just wondering what's the license for the software?

Cheers!

Is it LHS or RHS coordinate system?

Hi Tom;

Would like to know if the frame coordinate you are using for the 3D geometry code is left- or right-handed? I know Microsft's DirectX 3D transformations are based on the LHS coordinate.

Rgds

Fun Wey

Transformation print method does not print Point

Line 256, the erroneous extra j parameter in p(i,j) causes Point p to print as {0, 0, 0} when printing a Transformation. Removing it resolves the issue:

Replace line 256
strm << ((i == 3)? 1 : obj.p(i,j));
with
strm << ((i == 3)? 1 : obj.p(i));

Issues with DUE

Hi!

When compiling for the DUE I get the following error:

In file included from e:\Andre\Downloads\conversion\conversion.ino:1:0:
E:\Andre\Documentos\Arduino\libraries\Geometry/Geometry.h:12:22: error: reference to 'Matrix' is ambiguous
class Point : public Matrix<3,1>

I changed the library files so that all Matrix occurences had a prepending BLA:: (like advised on BasicLinearAlgebra git) and the compilation error vanished.

Still didn't test to see if the calculations are correct with this change.

Compiling Geometry gives template errors with Matrix

I've found a compilation problem in my configuration while compiling the IntegrateGyroData example.

Board: ESP32 4MB
Geometry version 1.0.0
BasicLinearAlgebrea 1.2.0 -> 2.0.0
Arduino IDE 1.8.10
Example Code: IntegrateGyroData.ino

Under BasicLinearAlgebra version 1.2.0, I get no compilation errors. When I compile with 2.0.0, I get the following errors:

In file included from C:\Users\The_o\Documents\Arduino\libraries\Geometry/Geometry.h:5:0,

                 from C:\Users\The_o\Documents\Arduino\libraries\arduino_174989\examples\IntegrateGyroData\IntegrateGyroData.ino:1:

C:\Users\The_o\Documents\Arduino\libraries\BasicLinearAlgebra/BasicLinearAlgebra.h:292:102: error: redeclaration of 'Matrix<rows, cols, ElemT, Array<rows, cols, ElemT> > Matrix<rows, cols, ElemT, MemT>::Inverse(int*)' may not have default arguments [-fpermissive]

 Matrix<rows,cols,ElemT,Array<rows,cols,ElemT> > Matrix<rows,cols,ElemT,MemT>::Inverse(int *res = NULL)

                                                                                                      ^

Multiple libraries were found for "Geometry.h"
 Used: C:\Users\The_o\Documents\Arduino\libraries\Geometry
 Not used: C:\Users\The_o\Documents\Arduino\libraries\arduino_174989
Multiple libraries were found for "BasicLinearAlgebra.h"
 Used: C:\Users\The_o\Documents\Arduino\libraries\BasicLinearAlgebra
exit status 1
Error compiling for board ESP32 Dev Module.

BTW, I'm not sure if it's related to the "multiple libraries" issue at the bottom, so I left it in the output listing. It is selecting the correct library location.

This compiles just fine if I select BasicLinearAlgebra version 1.2 (which is how I'm working around this for now).

Inverse kinematics?

Hi, I'm new to robotics but would like to use the Geometry library to control my dynamixel ax12a servos. i'd like to calculate and set the pose to put the end effector in a particular x/y/z position (why is this called the end effector pose and not the nose pose?). I see there is documentation for how to describe a chain of servos, and an inverse dynamics example, but I think I need to do inverse kinematics rather than dynamics. However I'm not a mathematician and am at a bit of a loss to work out how to approach this. Any pointers much appreciated!

Code error in Geometry?

Is line 53 in Geometry.cpp supposed to say: theta = 1.0e-5 ??

I am trying to match up your code with the algorithm description in: https://www.cl.cam.ac.uk/techreports/UCAM-CL-TR-696.html

Also, you have a class called AngularVelocity, but I think the values are supposed to be gyro rates * integration time ? Otherwise, how do you account for the delta-T in order to integrate the angular rates?

compile error : expected template-name before '<' token

Hi,
I'm fairly new to Arduino Programming and my C++ is quite rusty ...
I found your awesome library and that's exactly what I need for my project.

I tried to install via the official Arduino library manager and it didn't work.
Then I tried to download the current versions from here (BLA & Geometry, unpacked both manually) and got the same error:

In file included from C:\Users<...>\Documents\Arduino\libraries\Geometry-master\examples\HowToUse\HowToUse.ino:1:0:
C:\Users<...>\Documents\Arduino\libraries\Geometry-master/Geometry.h:10:28: error: expected template-name before '<' token

class Point : public Matrix<3,1,float>

                        ^

C:\Users<...>\Documents\Arduino\libraries\Geometry-master/Geometry.h:10:28: error: expected '{' before '<' token
C:\Users<...>\Documents\Arduino\libraries\Geometry-master/Geometry.h:10:28: error: expected unqualified-id before '<' token

Sure I searched for the errors and found some stack overflow questions, but before I tinker around with the libs, I'll ask here. Maybe it's a more fundamenal error.

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.