-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* pytest + formatting * Fixed CI * Added AC wrapper * change warning level if timeout * Added polygon * version 0.2.0 push * correct versioning * added ROS methods * fixed dependencies problem * Added word_to_num converter * Version bump to 0.2.2
- Loading branch information
Showing
11 changed files
with
383 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,10 @@ jobs: | |
python-version: [3.6, 3.7, 3.8] | ||
|
||
steps: | ||
- name: Setup ROS | ||
uses: ros-tooling/[email protected] | ||
with: | ||
required-ros-distributions: melodic | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v1 | ||
|
@@ -27,6 +31,7 @@ jobs: | |
run: | | ||
python -m pip install --upgrade pip | ||
pip install . | ||
pip install empy pyyaml rospkg | ||
# - name: Lint with flake8 | ||
# run: | | ||
# pip install flake8 | ||
|
@@ -36,5 +41,6 @@ jobs: | |
# flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics | ||
- name: Test with pytest | ||
run: | | ||
source /opt/ros/melodic/setup.bash | ||
pip install pytest | ||
python -m pytest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import numpy as np | ||
import alloy.math | ||
import alloy.ros | ||
|
||
from geometry_msgs.msg import( | ||
Pose, | ||
Point, | ||
Transform | ||
) | ||
|
||
__all__ = [ | ||
'do_transform_point' | ||
] | ||
|
||
def do_transform_point(transform: Transform, point: Point) -> Point: | ||
"""An implementation of the tf2_geometry_msgs interface to get around PyKDL. | ||
Transform a point with the given transform message. | ||
Parameters | ||
---------- | ||
transform : geometry_msgs/Transform | ||
Message that describes the transform | ||
point : geometry_msgs/Point | ||
The point to be transformed | ||
Returns | ||
------- | ||
geometry_msgs/Point | ||
Transformed point | ||
""" | ||
|
||
transform_mat = alloy.math.transformation_matrix_from_array(alloy.ros.transform_to_numpy(transform)) | ||
point_np = alloy.ros.point_to_numpy(point) | ||
point_np = np.append(point_np, 1).reshape((4,1)) | ||
trans_point = np.matmul(transform_mat, point_np) | ||
return alloy.ros.numpy_to_point(trans_point[0:3,0]) | ||
|
||
def do_transform_pose(transform: Transform, pose: Pose) -> Pose: | ||
"""An implementation of the tf2_geometry_msgs interface to get around PyKDL. | ||
Transform a pose with the given transform message. | ||
Parameters | ||
---------- | ||
transform : geometry_msgs/Transform | ||
Message that describes the transform | ||
pose : geometry_msgs/Pose | ||
The pose to be transformed | ||
Returns | ||
------- | ||
geometry_msgs/Pose | ||
Transformed pose. | ||
""" | ||
transform_mat = alloy.math.transformation_matrix_from_array(alloy.ros.transform_to_numpy(transform)) | ||
pose_mat = alloy.math.transformation_matrix_from_array(alloy.ros.pose_to_numpy(pose)) | ||
#combine two transformation matrix | ||
trans_pose_mat = np.matmul(transform_mat, pose_mat) | ||
|
||
return alloy.ros.numpy_to_pose(alloy.math.transformation_matrix_to_array(trans_pose_mat)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .nlp import convert_word_list_to_num_str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import enum | ||
import typing | ||
|
||
en_num_list = ['zero', 'one', 'two', 'three', | ||
'four', 'five', 'six', 'seven', 'eight', 'nine'] | ||
|
||
en_teen_list = ['eleven', 'twelve', 'thirteen', 'fourteen', | ||
'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen'] | ||
|
||
en_ten_list = ['ten', 'twenty', 'thirty', 'forty', | ||
'fifty', 'sixty', 'seventy', 'eighty', 'ninety'] | ||
|
||
|
||
@enum.unique | ||
class Position(enum.Enum): | ||
unknown = -1 | ||
ones = 0 | ||
tenths = 1 | ||
hundreds = 2 | ||
thousands = 3 | ||
millions = 4 | ||
|
||
|
||
def convert_word_list_to_num_str(local: typing.List[str]) -> str: | ||
"""Converts literal word list ("four two") into number string ("42"). | ||
It tries to seperate numbers like "four two two one" into "4221". It | ||
works up to 999,999. | ||
Parameters | ||
---------- | ||
local : Typing.list[str] | ||
List of number words | ||
Returns | ||
------- | ||
str | ||
return word list | ||
Raises | ||
------ | ||
ValueError | ||
If the word list is not formed correctly | ||
""" | ||
val_group = [] | ||
current_val = 0 | ||
buffer_val = -1 | ||
last_pos = Position.unknown | ||
|
||
for n in local: | ||
# if its in the ones group | ||
if n in en_num_list: | ||
# previous unknown | ||
if last_pos == Position.unknown: | ||
buffer_val = en_num_list.index(n) | ||
elif last_pos == Position.ones: | ||
# this means the previous stack/buffer is a different number group | ||
if buffer_val != -1: | ||
current_val += buffer_val | ||
val_group.append(current_val) | ||
current_val = 0 | ||
buffer_val = en_num_list.index(n) | ||
elif last_pos == Position.thousands: | ||
current_val = buffer_val | ||
buffer_val = en_num_list.index(n) | ||
else: | ||
buffer_val += en_num_list.index(n) | ||
last_pos = Position.ones | ||
|
||
elif n in en_teen_list: | ||
if last_pos == Position.unknown: | ||
buffer_val = en_teen_list.index(n) + 11 | ||
elif last_pos == Position.tenths: | ||
# this mean the previous stack/buffer is a different number group | ||
if buffer_val != -1: | ||
current_val += buffer_val | ||
val_group.append(current_val) | ||
current_val = 0 | ||
buffer_val = en_teen_list.index(n) + 11 | ||
else: | ||
buffer_val += en_teen_list.index(n) + 11 | ||
|
||
last_pos = Position.tenths | ||
|
||
elif n in en_ten_list: | ||
# previous unknown | ||
if last_pos == Position.unknown: | ||
buffer_val = (en_ten_list.index(n) + 1) * 10 | ||
elif last_pos.value <= Position.tenths.value: | ||
# this means the previous stack/buffer is a different number group | ||
if buffer_val != -1: | ||
current_val += buffer_val | ||
val_group.append(current_val) | ||
current_val = 0 | ||
buffer_val = (en_ten_list.index(n) + 1) * 10 | ||
else: | ||
buffer_val += (en_ten_list.index(n) + 1) * 10 | ||
|
||
last_pos = Position.tenths | ||
|
||
elif n == 'hundred': | ||
if last_pos == Position.unknown: | ||
raise ValueError("hundred without prefix") | ||
|
||
buffer_val = buffer_val * 100 | ||
last_pos = Position.hundreds | ||
|
||
elif n == 'thousand': | ||
if last_pos == Position.unknown: | ||
raise ValueError("thousands without prefix") | ||
|
||
buffer_val = buffer_val * 1000 | ||
last_pos = Position.thousands | ||
|
||
if buffer_val != -1: | ||
current_val += buffer_val | ||
val_group.append(current_val) | ||
elif current_val != 0: | ||
val_group.append(current_val) | ||
|
||
return "".join([str(n) for n in val_group]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.