View Javadoc

1   package cz.cuni.amis.pogamut.usar2004.communication.messages.usarinfomessages;
2   
3   import java.util.*;
4   import cz.cuni.amis.pogamut.base.communication.worldview.event.*;
5   import cz.cuni.amis.pogamut.base.communication.translator.event.*;
6   import cz.cuni.amis.pogamut.usar2004.communication.messages.*;
7   import cz.cuni.amis.pogamut.usar2004.communication.messages.datatypes.CustomTypes.*;
8   
9   /**
10   *
11   * Configuration message occurs after user has sent a command GetConf. Please
12   * note that the robot Configuration message parameters depend on the type of
13   * robot that you are driving. For example, a robot of type “GroundVehicle” will
14   * not have the same Configuration message as a robot of type “AerialVehicle.” *
15   * Corresponding GameBots message is CONF.
16   *
17   */
18  public class ConfigurationMessage extends GBEvent implements IWorldEvent, IWorldChangeEvent
19  {
20      public ConfigurationMessage(String Type, double MaxFrontSteer, double MaxRearSteer, double Mass, String SteeringType)
21      {
22          this.Type = Type;
23          this.Mass = Mass;
24          this.MaxFrontSteer = MaxFrontSteer;
25          this.MaxRearSteer = MaxRearSteer;
26          this.SteeringType = SteeringType;
27      }
28      /**
29       * Example how the message looks like - used during parser tests.
30       */
31      public static final String PROTOTYPE = "CONF {Type text} {Mass 0} {MaxFrontSteer 0} {MaxRearSteer 0} {SteeringType text}";
32      protected String Type = null;
33  
34      /**
35       * Type describes the vehicle type. It will be one of the following values:
36       * "GroundVehicle”, “LeggedRobot”, “NauticVehicle”, or “AerialVehicle” of
37       * "Camera" or some kind of sensor or effecter or "MisPkg".
38       *
39       * @return Returns type of the geometry message.
40       */
41      public String getType()
42      {
43          return Type;
44      }
45      //Ground Vehicle - Type, Name, SteeringType, Mass, MaxSpeed, MaxTorque, MaxFrontSteer, MaxRearSteer
46      //Name value of ground, nautic, aerial...vehicles is present in the Map (pairs) Name/Value for sensor messages.
47      protected String Name = null;
48  
49      /**
50       * Name of the subject that this geometry message concerns.
51       *
52       * @return Returns the name of the Geometry item.
53       */
54      public String getName()
55      {
56          return Name;
57      }
58      protected String SteeringType = null;
59  
60      /**
61       * Value should be one of the following: “AckermanSteered” or “SkidSteered”
62       * or “OmniDrive”, as dictated by the steering type of the robot.
63       *
64       * @return Returns steering type of the robot.
65       */
66      public String getSteeringType()
67      {
68          return SteeringType;
69      }
70      protected double Mass = 0;
71  
72      /**
73       * It is the robot's mass in kg.
74       *
75       * @return Returns mass of the robot.
76       */
77      public double getMass()
78      {
79          return Mass;
80      }
81      //these are represented by the lists down in mission package block
82  //        protected double MaxSpeed = 0;
83  //
84  //        public double getMaxSpeed() {
85  //            return MaxSpeed;
86  //        }
87  //        
88  //        protected double MaxTorque = 0;
89  //
90  //        public double getMaxTorque() {
91  //            return MaxTorque;
92  //        }
93      protected double MaxFrontSteer = 0;
94  
95      /**
96       * The maximum steering angle for robot’s front wheels, in radians. Please
97       * note that this value will be 0 for skid steered vehicles.
98       *
99       * @return Returns maximum front steer.
100      */
101     public double getMaxFrontSteer()
102     {
103         return MaxFrontSteer;
104     }
105     protected double MaxRearSteer = 0;
106 
107     /**
108      * The maximum steering angle for robot’s rear wheels, in radians. Please
109      * note that this value will be 0 for skid steered vehicles.
110      *
111      * @return Returns maximum rear steer.
112      */
113     public double getMaxRearSteer()
114     {
115         return MaxRearSteer;
116     }
117     //Legged Robot - Type, Name, SteeringType, Mass
118     //Nautic Vehicle - Type, Name, Dimensions, COG
119     //Aerial Vehicle - Type, Name, Dimensions, COG
120     //Sensor/effecter - Type, Name/Value..., Opcode..., MaxVal..., MinVal... 
121     protected Map<String, String> Features = new HashMap<String, String>();
122 
123     /**
124      * For a camera, sensor or effecter, a configuration message conatins a pair
125      * ‘{Name Value}’ that describes the feature of this sensor type. Different
126      * sensor types have different name value pairs. For detailed information,
127      * please refer to section 10 of USARSim manual v3.1.3 about how to
128      * configure the sensor.
129      *
130      * Example: CONF {Type Camera} {CameraDefFov 0.8727} {CameraMinFov 0.3491}
131      * {CameraMaxFov 2.0943} {CameraFov 0.8726}
132      *
133      * @return Returns Map of features.
134      */
135     public Map<String, String> getFeatures()
136     {
137         return Features;
138     }
139     protected List<String> Names = new ArrayList<String>();
140 
141     /**
142      * For an effector, the configuration message can contain multiple names.
143      *
144      * NOTE: An effecter can implement more than one opcode and the CONF message
145      * returns the configuration information for all effecters on the robotic
146      * platform. Therefore the segment with the name value pair indicates a new
147      * effecter and the opcode name value pair indicates the opcode the effecter
148      * specified in by name implements.
149      *
150      * @return Returns list of names.
151      */
152     public List<String> getNames()
153     {
154         return Names;
155     }
156     protected List<String> Opcodes = new ArrayList<String>();
157 
158     /**
159      * For an effector, the configuration message can contain multiple OpCodes.
160      * Opcode value is the name of the opcode that the effecter implements.
161      * Refer to Section 8 of USARSim Manual v3.1.3 for a list of the opcodes.
162      *
163      * NOTE: An effecter can implement more than one opcode and the CONF message
164      * returns the configuration information for all effecters on the robotic
165      * platform. Therefore the segment with the name value pair indicates a new
166      * effecter and the opcode name value pair indicates the opcode the effecter
167      * specified in by name implements.
168      *
169      * @return Returns list of Operation Codes.
170      */
171     public List<String> getOpcodes()
172     {
173         return Opcodes;
174     }
175     protected List<Double> MaxVals = new ArrayList<Double>();
176 
177     /**
178      * It is value that indicates the upper bound for the value that is accepted
179      * by the effecter.
180      *
181      * @return Returns list of max values for effecters.
182      */
183     public List<Double> getMaxVals()
184     {
185         return MaxVals;
186     }
187     protected List<Double> MinVals = new ArrayList<Double>();
188 
189     /**
190      * It is value that indicates the lower bound for the value that is accepted
191      * by the effecter.
192      *
193      * @return Returns list of min values for effecters.
194      */
195     public List<Double> getMinVals()
196     {
197         return MinVals;
198     }
199     //Mission Package - Type, Name, Link..., JointType..., MaxSpeed..., MaxTorque..., MinRange..., MaxRange...
200     //NOTE: For revolute joints, if the MinRange parameter is greater than the MaxRange 
201     //parameter, the joint does not have any constraints.  
202     protected List<Integer> Links = new ArrayList<Integer>();
203 
204     /**
205      * Each value is the mission package’s link number(or index) that is
206      * described further by JoinType, Max/Min Torque, Max/Min Speed and Max/Min
207      * Range.
208      *
209      * @return Returns list of links.
210      */
211     public List<Integer> getLinks()
212     {
213         return Links;
214     }
215     protected List<String> JointTypes = new ArrayList<String>();
216 
217     /**
218      * Each value can either be “Revolute” or “Prismatic”, as determined by the
219      * type of joint being described.
220      *
221      * @return Returns list of joint types.
222      */
223     public List<String> getJointTypes()
224     {
225         return JointTypes;
226     }
227     protected List<Double> MaxSpeeds = new ArrayList<Double>();
228 
229     /**
230      * Each value describes the joint’s maximum speed, in rad/s.
231      *
232      * @return Returns list of maximum speeds.
233      */
234     public List<Double> getMaxSpeeds()
235     {
236         return MaxSpeeds;
237     }
238     protected List<Double> MaxTorques = new ArrayList<Double>();
239 
240     /**
241      * Each value describes the joint’s maximum torque.
242      *
243      * @return Returns list of maximum torques.
244      */
245     public List<Double> getMaxTorques()
246     {
247         return MaxTorques;
248     }
249     protected List<Double> MaxRanges = new ArrayList<Double>();
250 
251     /**
252      * For a revolute joint, Each value is the maximum absolute angle that the
253      * joint can rotate to. For a prismatic joint, Each value is the maximum
254      * distance that the joint can move to.
255      *
256      * @return Returns list of maximum ranges.
257      */
258     public List<Double> getMaxRanges()
259     {
260         return MaxRanges;
261     }
262     protected List<Double> MinRanges = new ArrayList<Double>();
263 
264     /**
265      * For a revolute joint, Each value is the minimum absolute angle that the
266      * joint can rotate to. For a prismatic joint, Each value is the minimum
267      * distance that the joint can move to.
268      *
269      * @return Returns list of minimal ranges.
270      */
271     public List<Double> getMinRanges()
272     {
273         return MinRanges;
274     }
275 
276     /**
277      * Cloning constructor.
278      */
279     public ConfigurationMessage(ConfigurationMessage original)
280     {
281         this.Type = original.Type;
282         this.Mass = original.Mass;
283         this.MaxFrontSteer = original.MaxFrontSteer;
284         this.MaxRearSteer = original.MaxRearSteer;
285         this.SteeringType = original.SteeringType;
286         this.JointTypes.addAll(original.JointTypes);
287         this.Links.addAll(original.Links);
288         this.MaxRanges.addAll(original.MaxRanges);
289         this.MaxSpeeds.addAll(original.MaxSpeeds);
290         this.MaxTorques.addAll(original.MaxTorques);
291         this.MaxVals.addAll(original.MaxVals);
292         this.Features.putAll(original.Features);
293         this.Names.addAll(original.Names);
294         this.Opcodes.addAll(original.Opcodes);
295         this.MinVals.addAll(original.MinVals);
296         this.MinRanges.addAll(original.MinRanges);
297         this.Name = original.Name;
298     }
299 
300     /**
301      * Used by Yylex to create empty message then to fill it's protected fields
302      * (Yylex is in the same package).
303      */
304     public ConfigurationMessage()
305     {
306     }
307 
308     @Override
309     public String toString()
310     {
311         StringBuilder buf = new StringBuilder();
312         buf.append(super.toString() + " | "
313                 + "Type = "
314                 + String.valueOf(Type) + " | "
315                 + "MaxFrontSteer = "
316                 + String.valueOf(MaxFrontSteer) + " | "
317                 + "MaxRearSteer = "
318                 + String.valueOf(MaxRearSteer) + " | "
319                 + "Mass = "
320                 + String.valueOf(Mass) + " | ");
321 
322         if(SteeringType != null)
323         {
324             buf.append("SteeringType = ").append(String.valueOf(SteeringType)).append(" | ");
325         }
326 
327         if(!JointTypes.isEmpty())
328         {
329             for(String i : JointTypes)
330             {
331                 buf.append("JointType = ").append(i).append(" ");
332             }
333             buf.append(" | ");
334         }
335 
336 
337 
338         if(!Links.isEmpty())
339         {
340             for(Integer i : Links)
341             {
342                 buf.append("Link = ").append(i.toString()).append(" ");
343             }
344             buf.append(" | ");
345         }
346 
347 
348         if(!MaxRanges.isEmpty())
349         {
350             for(Double i : MaxRanges)
351             {
352                 buf.append("MaxRange = ").append(i.toString()).append(" ");
353             }
354             buf.append(" | ");
355         }
356 
357 
358         if(!MaxSpeeds.isEmpty())
359         {
360             for(Double i : MaxSpeeds)
361             {
362                 buf.append("MaxSpeed = ").append(i.toString()).append(" ");
363             }
364             buf.append(" | ");
365         }
366 
367 
368         if(!MaxTorques.isEmpty())
369         {
370             for(Double i : MaxTorques)
371             {
372                 buf.append("MaxTorque = ").append(i.toString()).append(" ");
373             }
374             buf.append(" | ");
375         }
376 
377 
378         if(!MaxVals.isEmpty())
379         {
380             for(Double i : MaxVals)
381             {
382                 buf.append("MaxVal = ").append(i.toString()).append(" ");
383             }
384             buf.append(" | ");
385         }
386 
387 
388         if(!Names.isEmpty())
389         {
390             for(String i : Names)
391             {
392                 buf.append("Name = ").append(i.toString()).append(" ");
393             }
394             buf.append(" | ");
395         }
396 
397 
398         if(!Opcodes.isEmpty())
399         {
400             for(String i : Opcodes)
401             {
402                 buf.append("Opcode = ").append(i.toString()).append(" ");
403             }
404             buf.append(" | ");
405         }
406 
407 
408 
409         if(!MinVals.isEmpty())
410         {
411             for(Double i : MinVals)
412             {
413                 buf.append("MinVal = ").append(i.toString()).append(" ");
414             }
415             buf.append(" | ");
416         }
417 
418 
419         if(!MinRanges.isEmpty())
420         {
421             for(Double i : MinRanges)
422             {
423                 buf.append("MinRange = ").append(i.toString()).append(" ");
424             }
425             buf.append(" | ");
426         }
427 
428         if(Name != null)
429         {
430             buf.append("Name = ").append(Name).append(" ");
431             buf.append(" | ");
432         }
433 
434 
435 
436         if(!Features.isEmpty())
437         {
438             Iterator it = Features.entrySet().iterator();
439             while(it.hasNext())
440             {
441                 Map.Entry en = (Map.Entry) it.next();
442                 buf.append(" ").append(en.getKey()).append(" ").append(en.getValue()).append(",");
443             }
444             buf.append(" | ");
445         }
446 
447         return buf.toString();
448     }
449 
450     /**
451      * Gets all properties and values to create a HTML formated string;
452      *
453      * @return Returns all properties in HTML format
454      */
455     public String toHtmlString()
456     {
457         StringBuilder buf = new StringBuilder();
458         buf.append(super.toString()
459                 + "<b>Type</b> : "
460                 + String.valueOf(Type)
461                 + " <br/> "
462                 + "<b>Mass</b> : "
463                 + String.valueOf(Mass)
464                 + " <br/> "
465                 + "<b>MaxFrontSteer</b> : "
466                 + String.valueOf(MaxFrontSteer)
467                 + " <br/> "
468                 + "<b>MaxRearSteer</b> : "
469                 + String.valueOf(MaxRearSteer)
470                 + " <br/> "
471                 + "<b>SteeringType</b> : "
472                 + String.valueOf(SteeringType)
473                 + " <br/> ");
474 
475         if(!JointTypes.isEmpty())
476         {
477             for(String i : JointTypes)
478             {
479                 buf.append("<b>JointType</b> : ").append(i).append(" ");
480             }
481         }
482 
483         buf.append(" <br/> ");
484 
485 
486         if(!Links.isEmpty())
487         {
488             for(Integer i : Links)
489             {
490                 buf.append("<b>Link</b> : ").append(i.toString()).append(" ");
491             }
492         }
493 
494         buf.append(" <br/> ");
495 
496         if(!MaxRanges.isEmpty())
497         {
498             for(Double i : MaxRanges)
499             {
500                 buf.append("<b>MaxRange</b> : ").append(i.toString()).append(" ");
501             }
502         }
503 
504         buf.append(" <br/> ");
505 
506         if(!MaxSpeeds.isEmpty())
507         {
508             for(Double i : MaxSpeeds)
509             {
510                 buf.append("<b>MaxSpeed</b> : ").append(i.toString()).append(" ");
511             }
512         }
513 
514         buf.append(" <br/> ");
515 
516         if(!MaxTorques.isEmpty())
517         {
518             for(Double i : MaxTorques)
519             {
520                 buf.append("<b>MaxTorque</b> : ").append(i.toString()).append(" ");
521             }
522         }
523 
524         buf.append(" <br/> ");
525 
526         if(!MaxVals.isEmpty())
527         {
528             for(Double i : MaxVals)
529             {
530                 buf.append("<b>MaxVal</b> : ").append(i.toString()).append(" ");
531             }
532         }
533 
534         buf.append(" <br/> ");
535 
536         if(!Names.isEmpty())
537         {
538             for(String i : Names)
539             {
540                 buf.append("<b>Name</b> : ").append(i.toString()).append(" ");
541             }
542         }
543 
544         buf.append(" <br/> ");
545 
546         if(!Opcodes.isEmpty())
547         {
548             for(String i : Opcodes)
549             {
550                 buf.append("<b>Opcode</b> : ").append(i.toString()).append(" ");
551             }
552         }
553 
554 
555         buf.append(" <br/> ");
556 
557         if(!MinVals.isEmpty())
558         {
559             for(Double i : MinVals)
560             {
561                 buf.append("<b>MinVal</b> : ").append(i.toString()).append(" ");
562             }
563         }
564 
565         buf.append(" <br/> ");
566 
567         if(!MinRanges.isEmpty())
568         {
569             for(Double i : MinRanges)
570             {
571                 buf.append("<b>MinRange</b> : ").append(i.toString()).append(" ");
572             }
573         }
574         buf.append(" <br/> ");
575 
576         if(Name != null)
577         {
578             buf.append("<b>Name</b> : ").append(Name).append(" ");
579         }
580 
581         buf.append(" <br/> ");
582 
583 
584         if(!Features.isEmpty())
585         {
586             Iterator it = Features.entrySet().iterator();
587             while(it.hasNext())
588             {
589                 Map.Entry en = (Map.Entry) it.next();
590                 buf.append("<b>").append(en.getKey()).append("</b> : ").append(en.getValue()).append(",");
591             }
592         }
593 
594         buf.append(" <br/> ");
595         return buf.toString();
596     }
597 }