View Javadoc

1   package cz.cuni.amis.pogamut.usar2004.communication.messages.usarcommands;
2   
3   import cz.cuni.amis.pogamut.base.communication.messages.*;
4   import cz.cuni.amis.pogamut.usar2004.communication.messages.datatypes.CustomTypes.*;
5   
6   /**
7    *
8    * Drive command specified for a sub or a boat.
9    *
10   * Corresponding GameBots command is DRIVE.
11   *
12   */
13  public class DriveNautic extends CommandMessage
14  {
15      //constructor for the third type
16      public DriveNautic(double Propeller, double Rudder, double SternPlane, boolean Normalized, boolean Light)
17      {
18          this.Propeller = Propeller;
19          this.Rudder = Rudder;
20          this.SternPlane = SternPlane;
21          this.Normalized = Normalized;
22          this.Light = Light;
23      }
24  
25      /**
26       * <p></p>WARNING: this is empty-command constructor, you have to use
27       * setters to fill it up!
28       */
29      public DriveNautic()
30      {
31      }
32      /////// Properties BEGIN
33      //third type - Propeller, Rudder, SternPlane, Normalized, Light
34      /*
35       * the spin speed for the propellers. If we use normalized values, the value
36       * range is –100 to 100 and corresponds to the propeller’s minimum and
37       * maximum spin speed, respectively. Otherwise, the value is the absolute
38       * propeller’s spin speed, in radians per second.
39       */
40      protected double Propeller = 0;
41  
42      public double getPropeller()
43      {
44          return Propeller;
45      }
46  
47      public DriveNautic setPropeller(double Propeller)
48      {
49          this.Propeller = Propeller;
50          return this;
51      }
52      /*
53       * specifies the angle of the robot’s rudders. If we use normalized values,
54       * the value range is -100 to 100 and corresponds to the rudders’ minimum
55       * and maximum steer angle, respectively. Otherwise, the value is the
56       * absolute rudder angle, in radians.
57       */
58      protected double Rudder = 0;
59  
60      public double getRudder()
61      {
62          return Rudder;
63      }
64  
65      public DriveNautic setRudder(double Rudder)
66      {
67          this.Rudder = Rudder;
68          return this;
69      }
70      /*
71       * specifies the angle of the robot’s stern planes. If we use normalized
72       * values, the value range is -100 to 100 and corresponds to the stern
73       * planes’ minimum and maximum angle, respectively. Otherwise, the value is
74       * the absolute stern plane angle, in radians.
75       */
76      protected double SternPlane = 0;
77  
78      public double getSternPlane()
79      {
80          return SternPlane;
81      }
82  
83      public DriveNautic setSternPlane(double SternPlane)
84      {
85          this.SternPlane = SternPlane;
86          return this;
87      }
88      /*
89       * Indicates whether we are using normalized values or ´ * not. The default
90       * value is ‘False’ which means absolute values are used to control wheel
91       * spin speed.
92       */
93      protected boolean Normalized = false;
94  
95      public boolean isNormalized()
96      {
97          return Normalized;
98      }
99  
100     public DriveNautic setNormalized(boolean Normalized)
101     {
102         this.Normalized = Normalized;
103         return this;
104     }
105     //Indicates whether to turn the headlight on or off
106     protected boolean Light = false;
107 
108     public boolean isLight()
109     {
110         return Light;
111     }
112 
113     public DriveNautic setLight(boolean Light)
114     {
115         this.Light = Light;
116         return this;
117     }
118 
119     /*
120      * Example: Drive {Propeller 1.0} will Drive the robot forward with a
121      * propeller’s spin speed of 1 rad/sec. Drive {Propeller 1.0} {Rudder
122      * 0.523599} will Drive the robot 30° forward and to the right with a spin
123      * speed of 1 rad/sec. Drive {Speed 1.0} {FrontSteer -0.523599} will Drive
124      * the robot 30° forward and to the left with a spin speed of 1 rad/sec.
125      * Drive {Light true} will turn on the robot’s headlights.
126      */
127     /////// Properties END
128     /////// Extra Java code BEGIN
129     /////// Additional code from xslt BEGIN
130     /////// Additional code from xslt END
131     /////// Extra Java from XML BEGIN
132     /////// Extra Java from XML END
133     /////// Extra Java code END
134     /**
135      * Cloning constructor.
136      */
137     public DriveNautic(DriveNautic original)
138     {
139         this.Normalized = original.Normalized;
140         this.Light = original.Light;
141         this.Propeller = original.Propeller;
142         this.Rudder = original.Rudder;
143         this.SternPlane = original.SternPlane;
144     }
145 
146     @Override
147     public String toString()
148     {
149         return toMessage();
150     }
151 
152     public String toHtmlString()
153     {
154         return super.toString()
155                 + "<b>Normalized</b> : "
156                 + String.valueOf(Normalized)
157                 + " <br/> "
158                 + "<b>Light</b> : "
159                 + String.valueOf(Light)
160                 + " <br/> "
161                 + "<b>Propeller</b> : "
162                 + String.valueOf(Propeller)
163                 + " <br/> "
164                 + "<b>Rudder</b> : "
165                 + String.valueOf(Rudder)
166                 + " <br/> "
167                 + "<b>SternPlane</b> : "
168                 + String.valueOf(SternPlane)
169                 + " <br/> "
170                 + "";
171     }
172 
173     public String toMessage()
174     {
175         StringBuilder buf = new StringBuilder();
176         buf.append("DRIVE");
177         buf.append(" {Normalized ").append(Normalized).append("}");
178         buf.append(" {Light ").append(Light).append("}");
179         buf.append(" {Propeller ").append(Propeller).append("}");
180         buf.append(" {Rudder ").append(Rudder).append("}");
181         buf.append(" {SternPlane ").append(SternPlane).append("}");
182 
183         return buf.toString();
184     }
185 }