# Copyright (c) 2020, FADA-CATEC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Complementary module with useful classes to support the usage of zlp libraries."""
from scipy.spatial import distance
import math
from geometry_msgs.msg import Point
from z_laser_msgs.msg import Figure
from z_laser_msgs.srv import CoordinateSystemRequest
[docs]class UserT(object):
"""This class provides a method to calculate the user points T1, T2, T3 from T0 and
the properties of the reference system.
Args:
x0 (float): x-position of the user T0 point
y0 (float): y-position of the user T0 point
resolution (float): resolution of the user reference system {T}
size_horiz (float): horizontal dimension of the refence system in real dimensions {P}
size_vert (float): vertical size of the refence system in real dimensions {P}
Attributes:
T (list): list of the calculated user {T} points
"""
[docs] def __init__(self, x0, y0, resolution, size_horiz, size_vert):
"""Initialize the UserT object."""
T0 = Point()
T1 = Point()
T2 = Point()
T3 = Point()
T0.x = x0
T0.y = y0
T1.x = T0.x + resolution*size_horiz/max(size_horiz,size_vert)
T1.y = T0.y
T2.x = T1.x
T2.y = T0.y + resolution*size_vert/max(size_horiz,size_vert)
T3.x = T0.x
T3.y = T2.y
self.T = [T0, T1, T2, T3]
[docs]class CoordinateSystemParameters(object):
"""This class is used as data object with the necessary parameters to define a coordinate system.
Attributes:
DEFAULT_SHOW_TIME (int): number of seconds for projecting reference system's projection elements
name (str): reference system name
distance (float): distance between the projection surface and the projector device
resolution (float): resolution of user reference system {T}
P (list): list with the x,y,z position of reference points from projector reference system {P}
T (list): list with the x,y,z position of user reference points from user reference system {T}
"""
DEFAULT_SHOW_TIME = 1
[docs] def __init__(self):
"""Initialize the CoordinateSystemParameters object."""
self.name = str()
self.distance = float()
self.resolution = float()
self.P = [Point(), Point(), Point(), Point()]
self.T = [Point(), Point(), Point(), Point()]
[docs] @staticmethod
def req_to_param(req):
"""Convert ROS request object to CoordinateSystemParameters object.
Args:
req (object): ROS request object with the parameters of a coordinate system
Returns:
object: same parameters of the coordinate system now in a CoordinateSystemParameters object
"""
params = CoordinateSystemParameters()
params.name = req.name
params.distance = req.distance
params.resolution = req.resolution
params.P = req.P
params.T[0] = req.T0
return params
[docs] @staticmethod
def param_to_req(params):
"""Convert CoordinateSystemParameters object to ROS request object.
Args:
params (object): CoordinateSystemParameters object with the parameters of a coordinate system
Returns:
object: same parameters of the coordinate system now in a ROS request object
"""
req = CoordinateSystemRequest()
req.name = params.name
req.distance = params.distance
req.resolution = params.resolution
req.P = params.P
req.T0 = params.T[0]
return req
[docs]class ProjectionElementParameters(object):
"""This class is used as data object with the necessary information to create a projection element.
Attributes:
figures_list (list): list with the projection elements' identificator names
figure_type (int): projection element id (see Figure.msg for more information)
projection_group (str): name of the projection group to which the projection element belongs
figure_name (str): name of the projection element to define
position (object): object with the x,y,z position of the projection element's characteristic point
size (list): list with the characteristic sizes of the projection element
angle (list): list with the characteristic angles of the projection element
text (str): text character string for text projection element
"""
figures_list = ["/polyline/",
"/circle/",
"/arc/",
"/oval/",
"/text/",
"/pointer/"]
[docs] def __init__(self):
"""Initialize the ProjectionElementParameters object."""
self.figure_type = int()
self.projection_group = str()
self.figure_name = str()
self.position = Point()
self.size = [float(),float()]
self.angle = [float(),float()]
self.text = str()