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 ground vehicle capable of stearing.
9    *
10   * Corresponding GameBots command is DRIVE.
11   *
12   */
13  public class DriveAckerman extends CommandMessage
14  {
15      //constructor for the second type
16      public DriveAckerman(double Speed, double FrontSteer, double RearSteer, boolean Normalized, boolean Light, boolean Flip)
17      {
18          this.Speed = Speed;
19          this.FrontSteer = FrontSteer;
20          this.RearSteer = RearSteer;
21          this.Normalized = Normalized;
22          this.Light = Light;
23          this.Flip = Flip;
24      }
25  
26      /**
27       * <p></p>WARNING: this is empty-command constructor, you have to use
28       * setters to fill it up!
29       */
30      public DriveAckerman()
31      {
32      }
33      /////// Properties BEGIN
34      //second type - Speed, FrontSteer, RearSteer, Normalized, Light, Flip
35      /*
36       * the spin speed for the wheels that are powered. If we use normalized
37       * values, the value range is –100 to 100 and corresponds to the robot’s
38       * minimum and maximum spin speed, respectively. Otherwise, the value is the
39       * absolute spin speed, in radians per second.
40       */
41      protected double Speed = 0;
42  
43      public double getSpeed()
44      {
45          return Speed;
46      }
47  
48      public DriveAckerman setSpeed(double Speed)
49      {
50          this.Speed = Speed;
51          return this;
52      }
53      /*
54       * the spin speed for the wheels that are powered. If we use normalized
55       * values, the value range is –100 to 100 and corresponds to the robot’s
56       * minimum and maximum spin speed, respectively. Otherwise, the value is the
57       * absolute spin speed, in radians per second.
58       */
59      protected double FrontSteer = 0;
60  
61      public double getFrontSteer()
62      {
63          return FrontSteer;
64      }
65  
66      public DriveAckerman setFrontSteer(double FrontSteer)
67      {
68          this.FrontSteer = FrontSteer;
69          return this;
70      }
71      //Same as FrontSteer but for rear set of wheels.
72      protected double RearSteer = 0;
73  
74      public double getRearSteer()
75      {
76          return RearSteer;
77      }
78  
79      public DriveAckerman setRearSteer(double RearSteer)
80      {
81          this.RearSteer = RearSteer;
82          return this;
83      }
84      /*
85       * Indicates whether we are using normalized values or ´ * not. The default
86       * value is ‘False’ which means absolute values are used to control wheel
87       * spin speed.
88       */
89      protected boolean Normalized = false;
90  
91      public boolean isNormalized()
92      {
93          return Normalized;
94      }
95  
96      public DriveAckerman setNormalized(boolean Normalized)
97      {
98          this.Normalized = Normalized;
99          return this;
100     }
101     //Indicates whether to turn the headlight on or off
102     protected boolean Light = false;
103 
104     public boolean isLight()
105     {
106         return Light;
107     }
108 
109     public DriveAckerman setLight(boolean Light)
110     {
111         this.Light = Light;
112         return this;
113     }
114     //Flip will flip the robot on its wheels if its rolled over
115     protected boolean Flip = false;
116 
117     public boolean isFlip()
118     {
119         return Flip;
120     }
121 
122     public DriveAckerman setFlip(boolean Flip)
123     {
124         this.Flip = Flip;
125         return this;
126     }
127 
128     /*
129      * Example: DRIVE {Speed -1.0} will drive the robot backward with a spin
130      * speed of 1 rad/sec. DRIVE {Speed 1.0} {FrontSteer 0.523599} will drive
131      * the robot 30° forward and to the left with a spin speed of 1 rad/sec.
132      * DRIVE {Speed 1.0} {FrontSteer -0.523599} will drive the robot 30° forward
133      * and to the right with a spin speed of 1 rad/sec.
134      */
135     /////// Properties END
136     /////// Extra Java code BEGIN
137     /////// Additional code from xslt BEGIN
138     /////// Additional code from xslt END
139     /////// Extra Java from XML BEGIN
140     /////// Extra Java from XML END
141     /////// Extra Java code END
142     /**
143      * Cloning constructor.
144      */
145     public DriveAckerman(DriveAckerman original)
146     {
147         this.FrontSteer = original.FrontSteer;
148         this.RearSteer = original.RearSteer;
149         this.Speed = original.Speed;
150         this.Normalized = original.Normalized;
151         this.Flip = original.Flip;
152         this.Light = original.Light;
153     }
154 
155     @Override
156     public String toString()
157     {
158         return toMessage();
159     }
160 
161     public String toHtmlString()
162     {
163         return super.toString()
164                 + "<b>FrontSteer</b> : "
165                 + String.valueOf(FrontSteer)
166                 + " <br/> "
167                 + "<b>RearSteer</b> : "
168                 + String.valueOf(RearSteer)
169                 + " <br/> "
170                 + "<b>Speed</b> : "
171                 + String.valueOf(Speed)
172                 + " <br/> "
173                 + "<b>Normalized</b> : "
174                 + String.valueOf(Normalized)
175                 + " <br/> "
176                 + "<b>Light</b> : "
177                 + String.valueOf(Light)
178                 + " <br/> "
179                 + "<b>Flip</b> : "
180                 + String.valueOf(Flip)
181                 + " <br/> "
182                 + "";
183     }
184 
185     public String toMessage()
186     {
187 
188         StringBuilder buf = new StringBuilder();
189         buf.append("DRIVE");
190         buf.append(" {FrontSteer ").append(FrontSteer).append("}");
191         buf.append(" {RearSteer ").append(RearSteer).append("}");
192         buf.append(" {Speed ").append(Speed).append("}");
193         buf.append(" {Normalized ").append(Normalized).append("}");
194         buf.append(" {Light ").append(Light).append("}");
195         buf.append(" {Flip ").append(Flip).append("}");
196 
197         return buf.toString();
198     }
199 }