Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Python bindings #119

Open
wants to merge 39 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
3770c10
Cython wrapper for Time and TransformWithCovariance
AlexanderFabisch Jul 10, 2017
662f729
Don't copy data
AlexanderFabisch Jul 10, 2017
bf671eb
More vector types
AlexanderFabisch Jul 10, 2017
b390ae6
JointState
AlexanderFabisch Jul 10, 2017
27b1f32
Partial wrapper of rigid body state
AlexanderFabisch Jul 10, 2017
9761caf
Add todos
AlexanderFabisch Jul 10, 2017
86cf719
Add Matrix3d
AlexanderFabisch Jul 11, 2017
345f5b0
Expose more RBS members
AlexanderFabisch Jul 11, 2017
b885de9
Expose all members of RBS
AlexanderFabisch Jul 11, 2017
1f2fac3
Expose some functions of Joints
AlexanderFabisch Jul 11, 2017
0e8418d
Add element access for Joints
AlexanderFabisch Jul 12, 2017
c1846f9
Wrap Frame
AlexanderFabisch Jul 12, 2017
ca23b9e
LaserScan and IMUSensors
AlexanderFabisch Jul 12, 2017
8065c90
Implement some operators
AlexanderFabisch Jul 12, 2017
e7f6d89
Organize todos
AlexanderFabisch Jul 12, 2017
4c0734c
Add readme
AlexanderFabisch Jul 12, 2017
a63c4f9
Update README.md
AlexanderFabisch Jul 12, 2017
c02fea9
Update installation instructions
AlexanderFabisch Jul 26, 2017
12f5cf3
Add Vector3d.fromarray()
AlexanderFabisch Jul 27, 2017
dffde77
Fix Vector3d.fromarray()
AlexanderFabisch Jul 27, 2017
48ab2d3
Use correct type for timestamp
AlexanderFabisch Jul 27, 2017
1b70051
Add dependencies
AlexanderFabisch Jul 28, 2017
931ad08
Update installation instructions
AlexanderFabisch Aug 1, 2017
d167a43
Extract Cython declaration file
AlexanderFabisch Aug 1, 2017
9edf872
Install Cython declarations
AlexanderFabisch Aug 1, 2017
561e0f3
Make resize for members of Joints possible
AlexanderFabisch Aug 8, 2017
3b0388f
Expose Joints::time
AlexanderFabisch Aug 8, 2017
8bf5f2e
Enable setting of joint state vector elements
AlexanderFabisch Aug 8, 2017
922682a
Implement some __str__ functions
AlexanderFabisch Aug 8, 2017
22a0792
String representation of LaserScan
AlexanderFabisch Aug 8, 2017
bd17140
Cap output of LaserScan
AlexanderFabisch Aug 8, 2017
d8fb7a8
Define assign function for each type
AlexanderFabisch Sep 1, 2017
25fc118
Expose Pointcloud::time
AlexanderFabisch Sep 1, 2017
56fa683
started to create bindings for Angle
Aug 30, 2017
b18cfad
coding style and splitted tests into groups
Sep 6, 2017
55eb1db
finished Angle
Sep 6, 2017
0394373
Move declaration of Angle to .pxd
AlexanderFabisch Sep 11, 2017
c26dbbb
Fix Python 3 compatibility issues
AlexanderFabisch Oct 16, 2017
38dfd9b
Add base-types as a dep
AlexanderFabisch Jan 8, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions bindings/python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Python bindings for base-types

## Install

You can build this prototype with

python setup.py build_ext -i

For now, you have to add this folder to your PYTHONPATH environment variable:

export PYTHONPATH=$PYTHONPATH:<this folder>

You could also install the bindings to some location that is already in the
Python path:

python setup.py install --prefix <path>

The more convenient way is to use autoproj. You must add three lines to
your manifest:

package_sets:
...
- type: git
url: [email protected]:InFuse/infuse-package_set.git

layout:
...
- tools/infuselog2cpp
...

## Note

There are still some open issues, e.g.
* How can we handle compressed Frame objects (e.g. JPG, PNG)?
* How can we make vectors / matricies look and feel more like numpy arrays?
* You can find todos all over the files.
* ...
328 changes: 328 additions & 0 deletions bindings/python/_basetypes.pxd
Original file line number Diff line number Diff line change
@@ -0,0 +1,328 @@
from libcpp.string cimport string
from libcpp.vector cimport vector
from libcpp cimport bool
from libc.stdint cimport uint8_t, uint16_t, uint32_t, int64_t

cdef extern from "base/Angle.hpp" namespace "base":
cdef cppclass Angle:
Angle()

double getDeg()
double getRad()
bool isApprox(Angle&, double)
bool isApprox(Angle&)

bool operator==(Angle&)
bool operator<(Angle&)
bool operator>(Angle&)
bool operator<=(Angle&)
bool operator>=(Angle&)

Angle operator+(Angle&)
Angle operator-(Angle&)
Angle operator*(Angle&)
Angle operator*(double)
Angle operator*(double, Angle)

Angle assign "operator="(Angle&)

Angle flipped()
Angle &flip()

#std::ostream& operator << (std::ostream& os, Angle angle); reimplemented
#Angle operator*(double, Angle) used Angle operator*(double, Angle) instead
#AngleSegment

cdef extern from "base/Angle.hpp" namespace "base::Angle":
double rad2Deg(double)
double deg2Rad(double)
double normalizeRad(double)
Angle fromRad(double)
Angle fromDeg(double)
Angle unknown()
Angle Min()
Angle Max()
Angle vectorToVector(Vector3d&, Vector3d&)
Angle vectorToVector(Vector3d&, Vector3d&, Vector3d&)


cdef extern from "base/Time.hpp" namespace "base":
cdef cppclass Time:
Time()

int64_t microseconds

Time& assign "operator="(Time&)

bool operator<(Time)
bool operator>(Time)
bool operator==(Time)
bool operator!=(Time)
bool operator>=(Time)
bool operator<=(Time)
Time operator-(Time)
Time operator+(Time)
Time operator/(int)
Time operator*(double)

bool isNull()
string toString(Resolution, string)


cdef extern from "base/Time.hpp" namespace "base::Time":
cdef enum Resolution:
Seconds
Milliseconds
Microseconds


cdef extern from "base/Time.hpp" namespace "base::Time":
Time now()


cdef extern from "base/Eigen.hpp" namespace "base":
cdef cppclass Vector2d:
Vector2d()
Vector2d(double, double)
Vector2d(Vector2d&)
double* data()
int rows()
Vector2d& assign "operator="(Vector2d&)
bool operator==(Vector2d&)
bool operator!=(Vector2d&)
double& get "operator()"(int row)
double x()
double y()
double norm()
double squaredNorm()

cdef cppclass Vector3d:
Vector3d()
Vector3d(double, double, double)
Vector3d(Vector3d&)
double* data()
int rows()
Vector3d& assign "operator="(Vector3d&)
bool operator==(Vector3d&)
bool operator!=(Vector3d&)
double& get "operator()"(int row)
double x()
double y()
double z()
double norm()
double squaredNorm()

cdef cppclass Vector4d:
Vector4d()
Vector4d(double, double, double, double)
Vector4d(Vector4d&)
double* data()
int rows()
Vector4d& assign "operator="(Vector4d&)
bool operator==(Vector4d&)
bool operator!=(Vector4d&)
double& get "operator()"(int row)
double x()
double y()
double z()
double norm()
double squaredNorm()

cdef cppclass Matrix3d:
Matrix3d()
double* data()
Matrix3d& assign "operator="(Matrix3d&)
bool operator==(Matrix3d&)
bool operator!=(Matrix3d&)
double& get "operator()"(int row, int col)
int rows()
int cols()

cdef cppclass Quaterniond:
Quaterniond()
Quaterniond(double, double, double, double)
Quaterniond& assign "operator="(Quaterniond&)
double w()
double x()
double y()
double z()


cdef extern from "base/TransformWithCovariance.hpp" namespace "base":
cdef cppclass TransformWithCovariance:
TransformWithCovariance()
TransformWithCovariance& assign "operator="(TransformWithCovariance&)
Vector3d translation
Quaterniond orientation


cdef extern from "base/JointState.hpp" namespace "base":
cdef cppclass JointState:
JointState()
JointState& assign "operator="(JointState&)
bool operator==(JointState&)
bool operator!=(JointState&)
double position
double speed
double effort
double raw
double acceleration
bool hasPosition()
bool hasSpeed()
bool hasEffort()
bool hasRaw()
bool hasAcceleration()
bool isPosition()
bool isSpeed()
bool isEffort()
bool isRaw()
bool isAcceleration()


cdef extern from "base/JointState.hpp" namespace "base::JointState":
JointState Position(double)
JointState Speed(double)
JointState Effort(double)
JointState Raw(double)
JointState Acceleration(double)


cdef extern from "base/NamedVector.hpp" namespace "base":
cdef cppclass NamedVector[T]:
vector[string] names
vector[T] elements

NamedVector& assign "operator="(NamedVector&)
void resize(int)
int size()
bool empty()
void clear()
bool hasNames()
T getElementByName(string)
int mapNameToIndex(string name)


cdef extern from "base/samples/Joints.hpp" namespace "base::samples":
cdef cppclass Joints(NamedVector[JointState]):
Joints()
Time time


cdef extern from "base/samples/RigidBodyState.hpp" namespace "base::samples":
cdef cppclass RigidBodyState:
RigidBodyState(bool)
RigidBodyState& assign "operator="(RigidBodyState&)
Time time
string sourceFrame
string targetFrame
Vector3d position
Matrix3d cov_position
Quaterniond orientation
Matrix3d cov_orientation
Vector3d velocity
Matrix3d cov_velocity
Vector3d angular_velocity
Matrix3d cov_angular_velocity


cdef extern from "base/samples/Frame.hpp" namespace "base::samples::frame":
cdef enum frame_mode_t:
MODE_UNDEFINED,
MODE_GRAYSCALE,
MODE_RGB,
MODE_UYVY,
MODE_BGR,
MODE_BGR32,
RAW_MODES,
MODE_BAYER,
MODE_BAYER_RGGB,
MODE_BAYER_GRBG,
MODE_BAYER_BGGR,
MODE_BAYER_GBRG,
COMPRESSED_MODES,
MODE_PJPG,
MODE_JPEG,
MODE_PNG

cdef enum frame_status_t:
STATUS_EMPTY,
STATUS_VALID,
STATUS_INVALID

cdef cppclass frame_size_t:
int width
int height

cdef cppclass Frame:
Frame()
Frame(int width, int height, int depth, frame_mode_t mode, int val, int sizeInBytes)
Frame(Frame other, bool bcopy)

Frame& assign "operator="(Frame&)

Time time
Time received_time
vector[uint8_t] image

frame_size_t size

uint32_t getChannelCount()
uint32_t getPixelSize()
uint32_t getRowSize()
uint32_t getNumberOfBytes()
uint32_t getPixelCount()
uint32_t getDataDepth()
uint16_t getWidth()
uint16_t getHeight()


cdef extern from "base/samples/Pointcloud.hpp" namespace "base::samples":
cdef cppclass Pointcloud:
Pointcloud()

Pointcloud& assign "operator="(Pointcloud&)

Time time
vector[Vector3d] points
vector[Vector4d] colors


cdef extern from "base/samples/LaserScan.hpp" namespace "base::samples":
cdef enum LASER_RANGE_ERRORS: # TODO pyx
TOO_FAR
TOO_NEAR
MEASUREMENT_ERROR
OTHER_RANGE_ERRORS
MAX_RANGE_ERROR

cdef cppclass LaserScan:
LaserScan()
LaserScan& assign "operator="(LaserScan&)

Time time
double start_angle
double angular_resolution
double speed
vector[uint32_t] ranges
uint32_t minRange
uint32_t maxRange
vector[float] remission

bool isValidBeam(unsigned int)
void reset()
bool isRangeValid(uint32_t)
#convertScanToPointCloud(vector[T], Affine3d, bool) TODO wrap Affine3d
#bool getPointFromScanBeamXForward(unsigned int i, Vector3d point) TODO
#bool getPointFromScanBeam(unsigned int i, Vector3d point) TODO


cdef extern from "base/samples/IMUSensors.hpp" namespace "base::samples":
cdef cppclass IMUSensors:
IMUSensors()
IMUSensors& assign "operator="(IMUSensors&)

Time time
Vector3d acc
Vector3d gyro
Vector3d mag

Loading