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 with no steering.
9    *
10   * Corresponding GameBots command is DRIVE.
11   *
12   */
13  public class DriveSkid extends CommandMessage
14  {
15      //constructor for the first type
16      public DriveSkid(double Left, double Right, boolean Normalized, boolean Light, boolean Flip)
17      {
18          this.Left = Left;
19          this.Right = Right;
20          this.Normalized = Normalized;
21          this.Light = Light;
22          this.Flip = Flip;
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 DriveSkid()
30      {
31      }
32      /////// Properties BEGIN
33      //first type - Left, Right, Normalized, Light, Flip
34      /*
35       * spin speed for the left side wheels. If we are using normalized values,
36       * the value range is –100 to 100 and corresponds to the robot’s minimum and
37       * maximum spin speed. If we use absolute values, the value will be the real
38       * spin speed in radians per second.
39       */
40      protected double Left = 0;
41  
42      public double getLeft()
43      {
44          return Left;
45      }
46  
47      public DriveSkid setLeft(double Left)
48      {
49          this.Left = Left;
50          return this;
51      }
52      //Same as Left but for the Right side
53      protected double Right = 0;
54  
55      public double getRight()
56      {
57          return Right;
58      }
59  
60      public DriveSkid setRight(double Right)
61      {
62          this.Right = Right;
63          return this;
64      }
65      /*
66       * Indicates whether we are using normalized values or ´ * not. The default
67       * value is ‘False’ which means absolute values are used to control wheel
68       * spin speed.
69       */
70      protected boolean Normalized = false;
71  
72      public boolean isNormalized()
73      {
74          return Normalized;
75      }
76  
77      public DriveSkid setNormalized(boolean Normalized)
78      {
79          this.Normalized = Normalized;
80          return this;
81      }
82      //Indicates whether to turn the headlight on or off
83      protected boolean Light = false;
84  
85      public boolean isLight()
86      {
87          return Light;
88      }
89  
90      public DriveSkid setLight(boolean Light)
91      {
92          this.Light = Light;
93          return this;
94      }
95      //Flip will flip the robot on its wheels if its rolled over
96      protected boolean Flip = false;
97  
98      public boolean isFlip()
99      {
100         return Flip;
101     }
102 
103     public DriveSkid setFlip(boolean Flip)
104     {
105         this.Flip = Flip;
106         return this;
107     }
108 
109     /*
110      * Example: DRIVE {Left 1.0} {Right 1.0} will drive the robot moving forward
111      * with spin seed 1 radian per second. DRIVE {Left -1.0} {Right 1.0} will
112      * turn the robot to left side. DRIVE {Light true} will turn on the
113      * headlight. DRIVE {Flip true} will flip the robot.
114      */
115     /////// Properties END
116     /////// Extra Java code BEGIN
117     /////// Additional code from xslt BEGIN
118     /////// Additional code from xslt END
119     /////// Extra Java from XML BEGIN
120     /////// Extra Java from XML END
121     /////// Extra Java code END
122     /**
123      * Cloning constructor.
124      */
125     public DriveSkid(DriveSkid original)
126     {
127         this.Left = original.Left;
128         this.Right = original.Right;
129         this.Normalized = original.Normalized;
130         this.Flip = original.Flip;
131         this.Light = original.Light;
132     }
133 
134     @Override
135     public String toString()
136     {
137         return toMessage();
138     }
139 
140     public String toHtmlString()
141     {
142         return super.toString()
143                 + "<b>Left</b> : "
144                 + String.valueOf(Left)
145                 + " <br/> "
146                 + "<b>Right</b> : "
147                 + String.valueOf(Right)
148                 + " <br/> "
149                 + "<b>Normalized</b> : "
150                 + String.valueOf(Normalized)
151                 + " <br/> "
152                 + "<b>Flip</b> : "
153                 + String.valueOf(Flip)
154                 + " <br/> "
155                 + "<b>Light</b> : "
156                 + String.valueOf(Light)
157                 + " <br/> "
158                 + "";
159     }
160 
161     public String toMessage()
162     {
163         StringBuilder buf = new StringBuilder();
164         buf.append("DRIVE");
165         buf.append(" {Left ").append(Left).append("}");
166         buf.append(" {Right ").append(Right).append("}");
167         buf.append(" {Normalized ").append(Normalized).append("}");
168         buf.append(" {Light ").append(Light).append("}");
169         buf.append(" {Flip ").append(Flip).append("}");
170 
171         return buf.toString();
172     }
173 }