View Javadoc

1   package cz.cuni.amis.pogamut.usar2004.communication.messages.usarinfomessages;
2   
3   import java.util.*;
4   import javax.vecmath.*;
5   import cz.cuni.amis.pogamut.base.communication.worldview.event.*;
6   import cz.cuni.amis.pogamut.base.communication.worldview.object.*;
7   import cz.cuni.amis.pogamut.base.communication.translator.event.*;
8   import cz.cuni.amis.pogamut.base3d.worldview.object.*;
9   import cz.cuni.amis.pogamut.usar2004.communication.messages.*;
10  import cz.cuni.amis.pogamut.usar2004.communication.messages.datatypes.*;
11  
12  /**
13   *
14   * Geometry message reports the robot's Geometry information. Please note that
15   * the robot Geometry message parameters depend on the type of robot that you
16   * are driving. For example, a robot of type “GroundVehicle” will not have the
17   * same Geometry message as a robot of type “AerialVehicle.”
18   *
19   * Corresponding GameBots message is GEO.
20   *
21   * NOTE: An effecter can implement more than one opcode and the CONF message
22   * returns the configuration information for all effecters on the robotic
23   * platform. Therefore the segment with the name value pair indicates a new
24   * effecter and the opcode name value pair indicates the opcode the effecter
25   * specified in by name implements.
26   *
27   *
28   * NOTE: For revolute joints, if the MinRange parameter is greater than the
29   * MaxRange parameter, the joint does not have any constraints.
30   */
31  public class GeometryMessage extends GBEvent implements IWorldEvent, IWorldChangeEvent
32  {
33      public GeometryMessage(String Type, String Name, double WheelBase, double WheelRadius, double WheelSeparation, Point3d COG, Vector3d Dimensions)
34      {
35          this.Type = Type;
36          this.Name = Name;
37          this.WheelBase = WheelBase;
38          this.WheelRadius = WheelRadius;
39          this.WheelSeparation = WheelSeparation;
40          this.CenterOfGravity = COG;
41          this.Dimensions = Dimensions;
42      }
43      /**
44       * Example how the message looks like - used during parser tests.
45       */
46      public static final String PROTOTYPE = "GEO {Type text} {Name text} {WheelBase 0} {WheelRadius 0} {WheelSeparation 0} {CenterOfGravity 0,0,0} {Dimensions 0,0,0}";
47      /////// Properties BEGIN
48      protected String Type = null;
49  
50      /**
51       * Type describes the vehicle type. It will be one of the following values:
52       * "GroundVehicle”, “LeggedRobot”, “NauticVehicle”, or “AerialVehicle” of
53       * "Camera" or some kind of sensor or effecter or "MisPkg".
54       *
55       * @return Returns type of the geometry message.
56       */
57      public String getType()
58      {
59          return Type;
60      }
61      //Ground Vehicle - Type, Name Dimensions, COG, WheelRadius, WheelSeparation, WheelBase
62      protected String Name = null;
63  
64      /**
65       * Name of the subject that this geometry message concerns.
66       *
67       * @return Returns the name of the Geometry item.
68       */
69      public String getName()
70      {
71          return Name;
72      }
73      protected Vector3d Dimensions = null;
74  
75      /**
76       * Dimension (x,y,z) ‘x’ defines the robot’s length, ‘y’ defines the robot’s
77       * width, and ‘z’ describes the robot’s height. Please note that these
78       * values are in meters.
79       *
80       * @return Returns Dimension of the robot.
81       */
82      public Vector3d getDimensions()
83      {
84          return Dimensions;
85      }
86      protected Point3d CenterOfGravity = null;
87  
88      /**
89       * COG(x,y,z) ‘x’, ‘y’, and ‘z’ identify the position of the center of
90       * gravity, in meters, calculated from the chassis origin.
91       *
92       * @return Returns center of gravity of the robot
93       */
94      public Point3d getCenterOfGravity()
95      {
96          return CenterOfGravity;
97      }
98      protected double WheelRadius = 0;
99  
100     /**
101      * The value is the radius of the robot’s wheels, in meters
102      *
103      * @return Returns wheel radius of the robot.
104      */
105     public double getWheelRadius()
106     {
107         return WheelRadius;
108     }
109     protected double WheelSeparation = 0;
110 
111     /**
112      * The value is the wheel separation, in meters. The wheel separation
113      * defines the distance between two wheels along the length (x axis) of the
114      * robot’s chassis.
115      *
116      * @return Returns wheel separation of the robot.
117      */
118     public double getWheelSeparation()
119     {
120         return WheelSeparation;
121     }
122     protected double WheelBase = 0;
123 
124     /**
125      * The value is the wheel base, in meters. The wheel base defines the
126      * distance between two wheels along the width (y axis) of the robot’s
127      * chassis
128      *
129      * @return Retursn wheel base of the robot.
130      */
131     public double getWheelBase()
132     {
133         return WheelBase;
134     }
135     //Legged Robot - (still to be expanded) - Type, Name, Dimensions, COG
136     //Nautic Vehicle - (still to be expanded) - Type, Name, Dimensions, COG
137     //Aerial Vehicle - (still to be expanded) - Type, Name, Dimensions, COG
138     //Sensor/effecter - Type Name/Location/Orientation/Mount...
139     //Specifies how the sensor is mounted on the robot
140     protected List<SensorMount> SenEffGeo = new ArrayList<SensorMount>();
141 
142     /**
143      * Camera, Sensor and effecter mounts are composed from Name, Location,
144      * Orientaion and Mount name.
145      *
146      * Example: GEO {Type Camera} {Name Camera Location 0.0820,0.0002,0.0613
147      * Orientation 0.0000,-0.0000,0.0000 Mount CameraTilt}
148      *
149      * @return Returns a collection of sensor mounts.
150      */
151     public List<SensorMount> getSenEffGeo()
152     {
153         return SenEffGeo;
154     }
155     //Mission Package - Type, Name, Link..., ParentLink..., Location..., Orientation...
156     protected List<Integer> Links = new ArrayList<Integer>();
157 
158     /**
159      * For a mission package, the geometry message is expressed in the following
160      * format to tell us how the mission package and its elements are
161      * ‘installed’ together to the robot.
162      *
163      * Example: GEO {Type MisPkg} {Name CameraPanTilt} {Link 1} {ParentLink -1}
164      * {Location 0.1239,0.0000,-0.2036} {Orientation 3.1415,0.0000,0.0000} {Link
165      * 2} {ParentLink 1} {Location 0.0000,0.0000,0.0599} {Orientation
166      * 1.5707,0.0000,0.0000}
167      *
168      * @return Returns List of links.
169      */
170     public List<Integer> getLinks()
171     {
172         return Links;
173     }
174     protected List<Integer> ParentLinks = new ArrayList<Integer>();
175 
176     /**
177      * For a mission package, the geometry message is expressed in the following
178      * format to tell us how the mission package and its elements are
179      * ‘installed’ together to the robot.
180      *
181      * Example: GEO {Type MisPkg} {Name CameraPanTilt} {Link 1} {ParentLink -1}
182      * {Location 0.1239,0.0000,-0.2036} {Orientation 3.1415,0.0000,0.0000} {Link
183      * 2} {ParentLink 1} {Location 0.0000,0.0000,0.0599} {Orientation
184      * 1.5707,0.0000,0.0000}
185      *
186      * @return Returns list of parent links.
187      */
188     public List<Integer> getParentLinks()
189     {
190         return ParentLinks;
191     }
192     protected List<Location> Locations = new ArrayList<Location>();
193 
194     /**
195      * For a mission package, the geometry message is expressed in the following
196      * format to tell us how the mission package and its elements are
197      * ‘installed’ together to the robot.
198      *
199      * Example: GEO {Type MisPkg} {Name CameraPanTilt} {Link 1} {ParentLink -1}
200      * {Location 0.1239,0.0000,-0.2036} {Orientation 3.1415,0.0000,0.0000} {Link
201      * 2} {ParentLink 1} {Location 0.0000,0.0000,0.0599} {Orientation
202      * 1.5707,0.0000,0.0000}
203      *
204      * @return Return list of Locations.
205      */
206     public List<Location> getLocations()
207     {
208         return Locations;
209     }
210     protected List<Rotation> Orientations = new ArrayList<Rotation>();
211 
212     /**
213      * For a mission package, the geometry message is expressed in the following
214      * format to tell us how the mission package and its elements are
215      * ‘installed’ together to the robot.
216      *
217      * Example: GEO {Type MisPkg} {Name CameraPanTilt} {Link 1} {ParentLink -1}
218      * {Location 0.1239,0.0000,-0.2036} {Orientation 3.1415,0.0000,0.0000} {Link
219      * 2} {ParentLink 1} {Location 0.0000,0.0000,0.0599} {Orientation
220      * 1.5707,0.0000,0.0000}
221      *
222      * @return Returns list of Orientations.
223      */
224     public List<Rotation> getOrientations()
225     {
226         return Orientations;
227     }
228 
229     /**
230      * Cloning constructor.
231      */
232     public GeometryMessage(GeometryMessage original)
233     {
234         this.Type = original.Type;
235         this.CenterOfGravity = original.CenterOfGravity;
236         this.Dimensions = original.Dimensions;
237         this.Links.addAll(original.Links);
238         this.Locations.addAll(original.Locations);
239         this.Name = original.Name;
240         this.Orientations.addAll(original.Orientations);
241         this.ParentLinks.addAll(original.ParentLinks);
242         this.SenEffGeo.addAll(original.SenEffGeo);
243         this.WheelBase = original.WheelBase;
244         this.WheelRadius = original.WheelRadius;
245         this.WheelSeparation = original.WheelSeparation;
246     }
247 
248     /**
249      * Used by Yylex to create empty message then to fill it's protected fields
250      * (Yylex is in the same package).
251      */
252     public GeometryMessage()
253     {
254     }
255     /**
256      * Here we save the original object for which this object is an update.
257      */
258     private IWorldObject orig = null;
259 
260     @Override
261     public String toString()
262     {
263 
264         StringBuilder buf = new StringBuilder();
265         buf.append(super.toString() + " | "
266                 + "Type = "
267                 + String.valueOf(Type) + " | "
268                 + "Name = "
269                 + String.valueOf(Name) + " | "
270                 + "WheelBase = "
271                 + String.valueOf(WheelBase) + " | "
272                 + "WheelRadius = "
273                 + String.valueOf(WheelRadius) + " | "
274                 + "WheelSeparation = "
275                 + String.valueOf(WheelSeparation) + " | ");
276         if(Dimensions != null)
277         {
278             buf.append("Dimensions = ").append(String.valueOf(Dimensions)).append(" | ");
279         }
280 
281 
282         if(CenterOfGravity != null)
283         {
284             StringBuilder append = buf.append("CenterOfGravity = ").append(String.valueOf(CenterOfGravity)).append(" | ");
285         }
286         if(!Links.isEmpty())
287         {
288             for(Integer i : Links)
289             {
290                 buf.append("Link = ").append(i.toString()).append(" ");
291             }
292             buf.append(" | ");
293         }
294 
295         if(!Locations.isEmpty())
296         {
297             for(Location i : Locations)
298             {
299                 buf.append("Location = ").append(i.x).append(",").append(i.y).append(",").append(i.z).append(" ");
300             }
301             buf.append(" | ");
302         }
303 
304         if(!ParentLinks.isEmpty())
305         {
306             for(Integer i : ParentLinks)
307             {
308                 buf.append("ParentLink = ").append(i.toString()).append(" ");
309             }
310             buf.append(" | ");
311         }
312 
313         if(!Orientations.isEmpty())
314         {
315             for(Rotation i : Orientations)
316             {
317                 buf.append("Orientation = ").append(i.yaw).append(",").append(i.roll).append(",").append(i.pitch).append(" ");
318             }
319             buf.append(" | ");
320         }
321 
322         if(!SenEffGeo.isEmpty())
323         {
324             buf.append("Sensor/Effecter Geo: ");
325             for(SensorMount i : SenEffGeo)
326             {
327                 buf.append("Location = ").append(i.getLocation().x).append(",").append(i.getLocation().y).append(",").append(i.getLocation().z).append(" ");
328                 buf.append("Name = ").append(i.getName()).append(" ");
329                 buf.append("Mount = ").append(i.getMount()).append(" ");
330                 buf.append("Orientation = ").append(i.getOrientation().yaw).append(",").append(i.getOrientation().roll).append(",").append(i.getOrientation().pitch).append(" ");
331             }
332             buf.append(" | ");
333         }
334         return buf.toString();
335 
336     }
337 
338     /**
339      * Gets all properties and values to create a HTML formated string;
340      *
341      * @return Returns all properties in HTML format
342      */
343     public String toHtmlString()
344     {
345         StringBuilder buf = new StringBuilder();
346         buf.append(super.toString()
347                 + "<b>Type</b> : "
348                 + String.valueOf(Type)
349                 + " <br/> "
350                 + "<b>Name</b> : "
351                 + String.valueOf(Name)
352                 + " <br/> "
353                 + "<b>WheelBase</b> : "
354                 + String.valueOf(WheelBase)
355                 + " <br/> "
356                 + "<b>WheelRadius</b> : "
357                 + String.valueOf(WheelRadius)
358                 + " <br/> "
359                 + "<b>WheelSeparation</b> : "
360                 + String.valueOf(WheelSeparation)
361                 + " <br/> ");
362 
363         if(Dimensions != null)
364         {
365             buf.append("<b>Dimensions</b> : ").append(String.valueOf(Dimensions)).append(" <br/> ");
366 
367         }
368 
369         if(CenterOfGravity != null)
370         {
371             buf.append("<b>CenterOfGravity</b> : ").append(String.valueOf(CenterOfGravity)).append(" <br/> ");
372         }
373 
374         if(!Links.isEmpty())
375         {
376             for(Integer i : Links)
377             {
378                 buf.append("<b>Link</b> : ").append(i.toString()).append(" <br/> ");
379             }
380         }
381 
382         if(!Locations.isEmpty())
383         {
384             for(Location i : Locations)
385             {
386                 buf.append("<b>Location</b> : ").append(i.x).append(",").append(i.y).append(",").append(i.z).append(" <br/> ");
387             }
388         }
389 
390         if(!ParentLinks.isEmpty())
391         {
392             for(Integer i : ParentLinks)
393             {
394                 buf.append("<b>ParentLink</b> : ").append(i.toString()).append(" <br/> ");
395             }
396         }
397 
398         if(!Orientations.isEmpty())
399         {
400             for(Rotation i : Orientations)
401             {
402                 buf.append("<b>Orientation</b> : ").append(i.yaw).append(",").append(i.roll).append(",").append(i.pitch).append(" <br/> ");
403             }
404         }
405 
406         if(!SenEffGeo.isEmpty())
407         {
408             buf.append("<b>Sensor/Effecter Geo</b> : ");
409             for(SensorMount i : SenEffGeo)
410             {
411                 buf.append("<b>Location</b> : ").append(i.getLocation().x).append(",").append(i.getLocation().y).append(",").append(i.getLocation().z).append(" <br/> ");
412                 buf.append("<b>Name</b> : ").append(i.getName()).append(" <br/> ");
413                 buf.append("<b>Mount</b> : ").append(i.getMount()).append(" <br/> ");
414                 buf.append("<b>Orientation</b> : ").append(i.getOrientation().yaw).append(",").append(i.getOrientation().roll).append(",").append(i.getOrientation().pitch).append(" <br/> ");
415             }
416         }
417 
418         return buf.toString();
419     }
420 
421     @Override
422     public long getSimTime()
423     {
424         throw new UnsupportedOperationException("Not supported yet.");
425     }
426 }