11# SPDX-License-Identifier: BSD-3-Clause
22# SPDX-FileCopyrightText: Czech Technical University in Prague
3-
4- from ctypes import c_bool , c_char_p , c_double , c_size_t , c_uint , c_uint32
3+ import ctypes
4+ from ctypes import c_bool , c_char_p , c_double , c_size_t , c_uint , c_uint32 , c_uint8
55from ctypes import cast , POINTER , Structure
66import sys
77
8+ import genpy
89import rospy
910from geometry_msgs .msg import Transform , TransformStamped
1011from sensor_msgs .msg import CameraInfo , RegionOfInterest
@@ -29,7 +30,7 @@ def __init__(self, secs=0, nsecs=0):
2930 if isinstance (secs , _RosTime ):
3031 c = secs
3132 super (RosTime , self ).__init__ (c .sec , c .nsec )
32- elif isinstance (secs , rospy .Time ):
33+ elif isinstance (secs , ( rospy .Time , genpy . rostime . Time ) ):
3334 c = secs
3435 super (RosTime , self ).__init__ (c .secs , c .nsecs )
3536 else :
@@ -55,7 +56,7 @@ class std_msgs_Header(Header):
5556 def __init__ (self , header = None , * args , ** kwargs ):
5657 if header is not None and isinstance (header , _std_msgs_Header ):
5758 super (std_msgs_Header , self ).__init__ (header .seq , RosTime (header .stamp ), _decode (header .frame_id ))
58- if header is not None and isinstance ( header , Header ) :
59+ if header is not None :
5960 super (std_msgs_Header , self ).__init__ (header .seq , RosTime (header .stamp ), header .frame_id )
6061 else :
6162 super (std_msgs_Header , self ).__init__ (* args , ** kwargs )
@@ -65,23 +66,24 @@ def from_param(cls, obj):
6566 c = _std_msgs_Header ()
6667 c .seq = obj .seq
6768 c .stamp = RosTime .from_param (obj .stamp )
68- c .frame_id = obj .frame_id .encode ("utf-8" )
69+ obj ._frame_id = obj .frame_id .encode ("utf-8" )
70+ c .frame_id = obj ._frame_id
6971 return c
7072
7173
7274class _sensor_msgs_RegionOfInterest (Structure ):
7375 _fields_ = [
74- ("x_offset" , c_uint ),
75- ("y_offset" , c_uint ),
76- ("height" , c_uint ),
77- ("width" , c_uint ),
78- ("do_rectify" , c_bool ),
76+ ("x_offset" , c_uint32 ),
77+ ("y_offset" , c_uint32 ),
78+ ("height" , c_uint32 ),
79+ ("width" , c_uint32 ),
80+ ("do_rectify" , c_uint8 ),
7981 ]
8082
8183
8284class sensor_msgs_RegionOfInterest (RegionOfInterest ):
8385 def __init__ (self , roi = None , * args , ** kwargs ):
84- if roi is not None and isinstance ( roi , ( _sensor_msgs_RegionOfInterest , RegionOfInterest )) :
86+ if roi is not None :
8587 super (sensor_msgs_RegionOfInterest , self ).__init__ (
8688 roi .x_offset , roi .y_offset , roi .height , roi .width , roi .do_rectify )
8789 else :
@@ -101,16 +103,16 @@ def from_param(cls, obj):
101103class _sensor_msgs_CameraInfo (Structure ):
102104 _fields_ = [
103105 ("header" , _std_msgs_Header ),
104- ("height" , c_uint ),
105- ("width" , c_uint ),
106+ ("height" , c_uint32 ),
107+ ("width" , c_uint32 ),
106108 ("distortion_model" , c_char_p ),
107109 ("D_count" , c_size_t ),
108110 ("D" , POINTER (c_double )),
109111 ("K" , c_double * 9 ),
110112 ("R" , c_double * 9 ),
111113 ("P" , c_double * 12 ),
112- ("binning_x" , c_uint ),
113- ("binning_y" , c_uint ),
114+ ("binning_x" , c_uint32 ),
115+ ("binning_y" , c_uint32 ),
114116 ("roi" , _sensor_msgs_RegionOfInterest ),
115117 ]
116118
@@ -119,17 +121,14 @@ class sensor_msgs_CameraInfo(CameraInfo):
119121 def __init__ (self , camInfo = None , * args , ** kwargs ):
120122 if camInfo is not None and isinstance (camInfo , _sensor_msgs_CameraInfo ):
121123 super (sensor_msgs_CameraInfo , self ).__init__ (
122- std_msgs_Header (camInfo .header ), camInfo .height , camInfo .width , _decode ( camInfo . distortion_model ) ,
123- list (cast (camInfo .D , POINTER (c_double ))), camInfo .K , camInfo .R , camInfo . P ,
124- camInfo .binning_x , camInfo .binning_y , sensor_msgs_RegionOfInterest (camInfo .roi ))
125- elif camInfo is not None and isinstance ( camInfo , CameraInfo ) :
124+ std_msgs_Header (header = camInfo .header ), camInfo .height , camInfo .width ,
125+ _decode ( camInfo . distortion_model ), list (cast (camInfo .D , POINTER (c_double ))), camInfo .K , camInfo .R ,
126+ camInfo .P , camInfo . binning_x , camInfo .binning_y , sensor_msgs_RegionOfInterest (roi = camInfo .roi ))
127+ elif camInfo is not None :
126128 super (sensor_msgs_CameraInfo , self ).__init__ (
127- std_msgs_Header (camInfo .header ), camInfo .height , camInfo .width , camInfo .distortion_model ,
129+ std_msgs_Header (header = camInfo .header ), camInfo .height , camInfo .width , camInfo .distortion_model ,
128130 camInfo .D , camInfo .K , camInfo .R , camInfo .P , camInfo .binning_x , camInfo .binning_y ,
129- sensor_msgs_RegionOfInterest (camInfo .roi ))
130- elif camInfo is not None and isinstance (camInfo , CameraInfo ):
131- for f in CameraInfo .__slots__ :
132- setattr (self , f , getattr (camInfo , f ))
131+ sensor_msgs_RegionOfInterest (roi = camInfo .roi ))
133132 else :
134133 super (sensor_msgs_CameraInfo , self ).__init__ (* args , ** kwargs )
135134
@@ -139,9 +138,11 @@ def from_param(cls, obj):
139138 c .header = std_msgs_Header .from_param (obj .header )
140139 c .height = obj .height
141140 c .width = obj .width
142- c .distortion_model = obj .distortion_model .encode ('utf-8' )
141+ obj ._distortion_model = obj .distortion_model .encode ('utf-8' )
142+ c .distortion_model = obj ._distortion_model
143143 c .D_count = len (obj .D )
144- c .D = cast ((c_double * len (obj .D ))(* obj .D ), POINTER (c_double ))
144+ obj ._D = cast ((c_double * len (obj .D ))(* obj .D ), POINTER (c_double ))
145+ c .D = obj ._D
145146 c .K = (c_double * 9 )(* obj .K )
146147 c .R = (c_double * 9 )(* obj .R )
147148 c .P = (c_double * 12 )(* obj .P )
@@ -169,8 +170,15 @@ def __init__(self, tf=None, *args, **kwargs):
169170 self .rotation .y = tf .rotation [1 ]
170171 self .rotation .z = tf .rotation [2 ]
171172 self .rotation .w = tf .rotation [3 ]
172- elif tf is not None and isinstance (tf , Transform ):
173- super (geometry_msgs_Transform , self ).__init__ (tf .translation , tf .rotation )
173+ elif tf is not None :
174+ super (geometry_msgs_Transform , self ).__init__ ()
175+ self .translation .x = tf .translation .x
176+ self .translation .y = tf .translation .y
177+ self .translation .z = tf .translation .z
178+ self .rotation .x = tf .rotation .x
179+ self .rotation .y = tf .rotation .y
180+ self .rotation .z = tf .rotation .z
181+ self .rotation .w = tf .rotation .w
174182 else :
175183 super (geometry_msgs_Transform , self ).__init__ (* args , ** kwargs )
176184
@@ -194,22 +202,23 @@ class geometry_msgs_TransformStamped(TransformStamped):
194202 def __init__ (self , tf = None , * args , ** kwargs ):
195203 if tf is not None and isinstance (tf , _geometry_msgs_TransformStamped ):
196204 super (geometry_msgs_TransformStamped , self ).__init__ ()
197- self .header = std_msgs_Header (tf .header )
205+ self .header = std_msgs_Header (header = tf .header )
198206 self .child_frame_id = _decode (tf .child_frame_id )
199- self .transform = geometry_msgs_Transform (tf .transform )
200- if tf is not None and isinstance ( tf , TransformStamped ) :
207+ self .transform = geometry_msgs_Transform (tf = tf .transform )
208+ elif tf is not None :
201209 super (geometry_msgs_TransformStamped , self ).__init__ ()
202- self .header = std_msgs_Header (tf .header )
210+ self .header = std_msgs_Header (header = tf .header )
203211 self .child_frame_id = tf .child_frame_id
204- self .transform = geometry_msgs_Transform (tf .transform )
212+ self .transform = geometry_msgs_Transform (tf = tf .transform )
205213 else :
206214 super (geometry_msgs_TransformStamped , self ).__init__ (* args , ** kwargs )
207215
208216 @classmethod
209217 def from_param (cls , obj ):
210218 c = _geometry_msgs_TransformStamped ()
211219 c .header = std_msgs_Header .from_param (obj .header )
212- c .child_frame_id = obj .child_frame_id .encode ('utf-8' )
220+ obj ._child_frame_id = obj .child_frame_id .encode ('utf-8' )
221+ c .child_frame_id = obj ._child_frame_id
213222 c .transform = geometry_msgs_Transform .from_param (obj .transform )
214223 return c
215224
0 commit comments