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    * This command is used to drive a joint.
9    *
10   *
11   *
12   * Corresponding GameBots command is SET.
13   *
14   */
15  public class SetJoint extends CommandMessage
16  {
17      //constructor for the joints
18      public SetJoint(String Type, String Name, String Opcode, double param1, double param2)
19      {
20          this.Type = Type;
21          this.Name = Name;
22          this.Opcode = Opcode;
23          this.Param1 = param1;
24          this.Param2 = param2;
25      }
26  
27      /**
28       * <p></p>WARNING: this is empty-command constructor, you have to use
29       * Setters to fill it up!
30       */
31      public SetJoint()
32      {
33      }
34      /////// Properties BEGIN
35      protected String Type = "Joint";
36  
37      public String getType()
38      {
39          return Type;
40      }
41      protected String Name = null;
42  
43      public String getName()
44      {
45          return Name;
46      }
47  
48      public SetJoint setName(String Name)
49      {
50          this.Name = Name;
51          return this;
52      }
53      /*
54       * the operation code. The available codes are: ‘Angle’ or ‘0’: set the
55       * extra angle in radian the joint will move. ‘Velocity’ or ‘1’: set the
56       * spin speed in radian per second for the joint. ‘Torque’ or ‘2’: set the
57       * torque applied on the joint.
58       */
59      protected String Opcode = null;
60  
61      public String getOpcode()
62      {
63          return Opcode;
64      }
65  
66      public SetJoint setOpcode(String Opcode)
67      {
68          this.Opcode = Opcode;
69          return this;
70      }
71      //Corresponds with the Opcode
72      protected double Param1 = 0;
73  
74      public double getParam1()
75      {
76          return Param1;
77      }
78  
79      public SetJoint setParam1(double Param1)
80      {
81          this.Param1 = Param1;
82          return this;
83      }
84      //Optional parameter, only uses for the KCarWheelJoint to set the steer angle
85      protected double Param2 = 0;
86  
87      public double getParam2()
88      {
89          return Param2;
90      }
91  
92      public SetJoint setParam2(double Param2)
93      {
94          this.Param2 = Param2;
95          return this;
96      }
97  
98      /*
99       * Example 1: SET {Type Joint} {Name UpperArm} {Opcode Angle} {Params 1.25}
100      * Example 2: SET {Type Gripper} {Name Gripper} {Opcode Open} {Params 0.8}
101      */
102     /////// Properties END
103     /////// Extra Java code BEGIN
104     /////// Additional code from xslt BEGIN
105     /////// Additional code from xslt END
106     /////// Extra Java from XML BEGIN
107     /////// Extra Java from XML END
108     /////// Extra Java code END
109     /**
110      * Cloning constructor.
111      */
112     public SetJoint(SetJoint original)
113     {
114         this.Name = original.Name;
115         this.Opcode = original.Opcode;
116         this.Param1 = original.Param1;
117         this.Param2 = original.Param2;
118     }
119 
120     @Override
121     public String toString()
122     {
123         return toMessage();
124     }
125 
126     public String toHtmlString()
127     {
128         return super.toString()
129                 + "<b>Type</b> : "
130                 + String.valueOf(Type)
131                 + " <br/> "
132                 + "<b>Name</b> : "
133                 + String.valueOf(Name)
134                 + " <br/> "
135                 + "<b>Opcode</b> : "
136                 + String.valueOf(Opcode)
137                 + " <br/> "
138                 + "<b>Param1</b> : "
139                 + String.valueOf(Param1)
140                 + " <br/> "
141                 + "<b>Param2</b> : "
142                 + String.valueOf(Param2)
143                 + " <br/> "
144                 + "";
145 
146     }
147 
148     public String toMessage()
149     {
150 
151         StringBuilder buf = new StringBuilder();
152         buf.append("SET");
153 
154         if(Type != null)
155         {
156             buf.append(" {Type ").append(Type).append("}");
157         }
158 
159         if(Name != null)
160         {
161             buf.append(" {Name ").append(Name).append("}");
162         }
163 
164         if(Opcode != null)
165         {
166             buf.append(" {Opcode ").append(Opcode).append("}");
167         }
168 
169         if(Opcode != null)
170         {
171             buf.append(" {Params ").append(Param1).append(",").append(Param2).append("}");
172         }
173 
174 
175         return buf.toString();
176     }
177 }