Skip to content

Commit

Permalink
Simpler python import command; new opengl python demo
Browse files Browse the repository at this point in the history
  • Loading branch information
jlblancoc committed Jul 3, 2023
1 parent 971c59a commit 4582187
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 16 deletions.
4 changes: 1 addition & 3 deletions python-examples/global_localization.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@
#
# ./global_localization.py ../share/mrpt/config_files/pf-localization/localization_demo.ini
#
from mrpt import pymrpt
from mrpt.pymrpt import mrpt
import os
import sys
import argparse
from time import sleep

mrpt = pymrpt.mrpt # namespace shortcut


# args
parser = argparse.ArgumentParser()
Expand Down
3 changes: 1 addition & 2 deletions python-examples/hwdriver-tao-imu-usb.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
# export PYTHONPATH=$HOME/code/mrpt/build-Release/:$PYTHONPATH
# ---------------------------------------------------------------------

from mrpt import pymrpt
mrpt = pymrpt.mrpt # namespace shortcut
from mrpt.pymrpt import mrpt

imu = mrpt.hwdrivers.CTaoboticsIMU()

Expand Down
3 changes: 1 addition & 2 deletions python-examples/lines-3d-geometry-example.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
# export PYTHONPATH=$HOME/code/mrpt/build-Release/:$PYTHONPATH
# ---------------------------------------------------------------------

from mrpt import pymrpt
mrpt = pymrpt.mrpt
from mrpt.pymrpt import mrpt

# Aliases:
TPoint3D = mrpt.math.TPoint3D_double_t
Expand Down
3 changes: 1 addition & 2 deletions python-examples/matrices.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
# More matrix classes available in the module mrpt.math.
# See: https://mrpt.github.io/pymrpt-docs/mrpt.pymrpt.mrpt.math.html

from mrpt import pymrpt
from mrpt.pymrpt import mrpt
import numpy as np
mrpt = pymrpt.mrpt

# Create a numpy matrix from a list:
m1_np = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
Expand Down
52 changes: 52 additions & 0 deletions python-examples/opengl-demo-gui.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env python3

# ---------------------------------------------------------------------
# Install python3-pymrpt, ros-$ROS_DISTRO-mrpt2, or test with a local build with:
# export PYTHONPATH=$HOME/code/mrpt/build-Release/:$PYTHONPATH
# ---------------------------------------------------------------------

from mrpt.pymrpt import mrpt
import time

# Create GUI:
win = mrpt.gui.CDisplayWindow3D('MRPT GUI demo', 800, 600)

# Get and lock 3D scene:
# Lock is required again each time the scene is modified, to prevent
# data race between the main and the rendering threads.
scene = win.get3DSceneAndLock()

# ctor args: xMin: float, xMax: float, yMin: float, yMax: float, z: float, frequency: float
glGrid = mrpt.opengl.CGridPlaneXY.Create(-10, 10, -10, 10, 0, 1)
scene.insert(glGrid)

glCorner = mrpt.opengl.stock_objects.CornerXYZ(2.0)
scene.insert(glCorner)

glCorner2: mrpt.opengl.CSetOfObjects = mrpt.opengl.stock_objects.CornerXYZ(1.0)
glCorner2.setLocation(4.0, 0.0, 0.0)
scene.insert(glCorner2)

glEllip = mrpt.opengl.CEllipsoidInverseDepth3D()
cov = mrpt.math.CMatrixFixed_double_3UL_3UL_t.Zero()
cov[0, 0] = 0.01
cov[1, 1] = 0.001
cov[2, 2] = 0.002
mean = mrpt.math.CMatrixFixed_double_3UL_1UL_t()
mean[0, 0] = 0.2 # inv_range
mean[1, 0] = 0.5 # yaw
mean[2, 0] = -0.6 # pitch
glEllip.setCovMatrixAndMean(cov, mean)
scene.insert(glEllip)


# end of scene lock:
win.unlockAccess3DScene()


print('Close the window to quit the program')

while win.isOpen():

win.repaint()
time.sleep(50e-3)
4 changes: 1 addition & 3 deletions python-examples/rbpf_slam.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@
# ./rbpf_slam.py -c ../share/mrpt/config_files/rbpf-slam/gridmapping_optimal_sampling.ini ../share/mrpt/datasets/2006-01ENE-21-SENA_Telecom\ Faculty_one_loop_only.rawlog
#

from mrpt import pymrpt
from mrpt.pymrpt import mrpt
import argparse

mrpt = pymrpt.mrpt

# args
parser = argparse.ArgumentParser()
parser.add_argument('rawlog', help='Rawlog file.')
Expand Down
4 changes: 2 additions & 2 deletions python-examples/ros-poses-convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
# This example shows how to convert back and forth between MRPT poses
# and ROS 1 or ROS 2 (both are compatible with this same code) Pose

from mrpt import pymrpt, ros_bridge
from mrpt.pymrpt import mrpt
from mrpt import ros_bridge
from math import radians
from geometry_msgs.msg import Pose, PoseWithCovariance

mrpt = pymrpt.mrpt

# Example 1: 2D pose
# --------------------------
Expand Down
3 changes: 1 addition & 2 deletions python-examples/se3-poses-example.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
# export PYTHONPATH=$HOME/code/mrpt/build-Release/:$PYTHONPATH
# ---------------------------------------------------------------------

from mrpt.pymrpt import mrpt
from math import radians
from mrpt import pymrpt
mrpt = pymrpt.mrpt

p1 = mrpt.poses.CPose3D.FromXYZYawPitchRoll(
1.0, 2.0, 0, radians(90), radians(0), radians(0))
Expand Down
24 changes: 24 additions & 0 deletions python/patch-stubs-002.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
diff --git a/python/stubs-out/mrpt/pymrpt/mrpt/opengl/__init__.pyi b/python/stubs-out/mrpt/pymrpt/mrpt/opengl/__init__.pyi
index 8abd014c7..d29cf054a 100644
--- a/python/stubs-out/mrpt/pymrpt/mrpt/opengl/__init__.pyi
+++ b/python/stubs-out/mrpt/pymrpt/mrpt/opengl/__init__.pyi
@@ -1,5 +1,7 @@
from typing import Any, ClassVar, Dict, List, Optional, Tuple

+from . import stock_objects
+
from typing import overload
import mrpt.pymrpt.mrpt.containers
import mrpt.pymrpt.mrpt.img
diff --git a/python/stubs-out/mrpt/pymrpt/mrpt/poses/__init__.pyi b/python/stubs-out/mrpt/pymrpt/mrpt/poses/__init__.pyi
index 09ba314ee..6d716eb80 100644
--- a/python/stubs-out/mrpt/pymrpt/mrpt/poses/__init__.pyi
+++ b/python/stubs-out/mrpt/pymrpt/mrpt/poses/__init__.pyi
@@ -1,5 +1,7 @@
from typing import Any, ClassVar, Dict, Tuple

+from . import Lie
+
from typing import overload
import mrpt.pymrpt.mrpt
import mrpt.pymrpt.mrpt.bayes
2 changes: 2 additions & 0 deletions python/stubs-out/mrpt/pymrpt/mrpt/opengl/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from typing import Any, ClassVar, Dict, List, Optional, Tuple

from . import stock_objects

from typing import overload
import mrpt.pymrpt.mrpt.containers
import mrpt.pymrpt.mrpt.img
Expand Down
2 changes: 2 additions & 0 deletions python/stubs-out/mrpt/pymrpt/mrpt/poses/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from typing import Any, ClassVar, Dict, Tuple

from . import Lie

from typing import overload
import mrpt.pymrpt.mrpt
import mrpt.pymrpt.mrpt.bayes
Expand Down

0 comments on commit 4582187

Please sign in to comment.