View Javadoc

1   package cz.cuni.amis.pogamut.usar2004.communication.messages.usarcommands;
2   
3   import java.util.*;
4   import cz.cuni.amis.pogamut.base.communication.messages.*;
5   import cz.cuni.amis.pogamut.usar2004.communication.messages.datatypes.CustomTypes.*;
6   
7   /**
8    *
9    * A mission package is constructed of a series of connected elements. Of
10   * course, we can control the joints one by one to set the mission package’s
11   * pose. Here, we provide another command to directly set the package’s terminal
12   * pose and let USARSim control every element’s joint for us. If a camera is
13   * mounted on a pan/tilt mission package, we can use this command to control the
14   * camera’s pose. Using mission package control commands, we can have multiple
15   * cameras and control them separately.
16   *
17   * Corresponding GameBots command is MISPGK.
18   *
19   * TIPS: Pan/tilt mission packages enable the use of multiple cameras with
20   * independent control on each of them.
21   */
22  public class MissionPackage extends CommandMessage
23  {
24      public MissionPackage(String Name, int[] Links, double[] Values, int[] Orders)
25      {
26  
27          this.Name = Name;
28  
29          if((Links.length == Values.length) && (Links.length == Orders.length))
30          {
31              for(int i = 0; i < Links.length; i++)
32              {
33                  this.Links.add(Links[i]);
34                  this.Values.add(Values[i]);
35                  this.Orders.add(Orders[i]);
36              }
37          }
38      }
39  
40      public MissionPackage(String Name, int Link, double Value, int Order)
41      {
42          this.Name = Name;
43          this.Links.add(Link);
44          this.Orders.add(Order);
45          this.Values.add(Value);
46      }
47  
48      public MissionPackage(String Name, int Link, double Value)
49      {
50          this.Name = Name;
51          this.Links.add(Link);
52          this.Orders.add(0);
53          this.Values.add(Value);
54      }
55  
56      /**
57       * <p></p>WARNING: this is empty-command constructor, you have to use
58       * setters to fill it up!
59       */
60      public MissionPackage()
61      {
62      }
63      /////// Properties BEGIN
64      //the joint name
65      protected String Name = null;
66  
67      public String getName()
68      {
69          return Name;
70      }
71  
72      public MissionPackage setName(String Name)
73      {
74          this.Name = Name;
75          return this;
76      }
77      //the link number that will be moved using the next parameters
78      protected List<Integer> Links = new ArrayList<Integer>();
79  
80      public List<Integer> getLinks()
81      {
82          return Links;
83      }
84  
85      public void addLink(int link)
86      {
87          this.Links.add(link);
88      }
89  
90      public void addLink(int[] links)
91      {
92          for(int f : links)
93          {
94              this.Links.add(f);
95          }
96      }
97      /*
98       * value used to move the link. What this parameter describes depends on the
99       * order given. If the order is 0, ‘double’ is the absolute angle, in
100      * radians, for a revolute joint or the distance, in meters, for a prismatic
101      * joint. If the order is 1, ‘double’ is the velocity, in m/s. If the order
102      * is 2, ‘double’ is the torque.
103      */
104     protected List<Double> Values = new ArrayList<Double>();
105 
106     public List<Double> getValues()
107     {
108         return Values;
109     }
110 
111     public void addValue(double value)
112     {
113         this.Values.add(value);
114     }
115 
116     public void addValue(double[] values)
117     {
118         for(double f : values)
119         {
120             this.Values.add(f);
121         }
122     }
123     /*
124      * optional (0 by default) and indicates the control mode. ‘0’ means angle
125      * control, ‘1’ means speed control, and ‘2’ means torque control.
126      */
127     protected List<Integer> Orders = new ArrayList<Integer>();
128 
129     //{Order int} ‘int’ is optional (0 by default) and indicates the control mode. ‘0’ means angle control, ‘1’ means speed control, and ‘2’ means torque control. 
130     public List<Integer> getOrders()
131     {
132         return Orders;
133     }
134 
135     public void addOrder(int order)
136     {
137         this.Orders.add(order);
138     }
139 
140     public void addOrder(int[] orders)
141     {
142         for(int f : orders)
143         {
144             this.Orders.add(f);
145         }
146     }
147 
148     /*
149      * Example: MISPKG {Name CameraPanTilt} {Link 1} {Value 1.5} {Link 2} {Value
150      * 0} MISPKG {Name TalonArm} {Link 1} {Value 0.70} {Link 3} {Value 0.1}
151      * {Order 1}
152      */
153     /////// Properties END
154     /////// Extra Java code BEGIN
155     /////// Additional code from xslt BEGIN
156     /////// Additional code from xslt END
157     /////// Extra Java from XML BEGIN
158     /////// Extra Java from XML END
159     /////// Extra Java code END
160     /**
161      * Cloning constructor.
162      */
163     public MissionPackage(MissionPackage original)
164     {
165         this.Name = original.Name;
166         this.Links.addAll(original.Links);
167         this.Values.addAll(original.Values);
168         this.Orders.addAll(original.Orders);
169     }
170 
171     @Override
172     public String toString()
173     {
174         return toMessage();
175     }
176 
177     public String toHtmlString()
178     {
179 
180         StringBuilder buf = new StringBuilder();
181         buf.append(super.toString());
182 
183 
184 
185         buf.append("<b>Name</b> : ").append(String.valueOf(Name)).append(" <br/> ");
186 
187         if((!Links.isEmpty()) && (Links.size() == Values.size()) && (Links.size() == Orders.size()))
188         {
189             for(int i = 0; i < Links.size(); i++)
190             {
191 
192                 buf.append("<b>Link</b> : "
193                         + String.valueOf(Links.get(i))
194                         + " <br/> "
195                         + "<b>Value</b> : "
196                         + String.valueOf(Values.get(i))
197                         + " <br/> "
198                         + "<b>Order</b> : "
199                         + String.valueOf(Orders.get(i))
200                         + " <br/> ");
201             }
202         }
203 
204         return buf.toString();
205     }
206 
207     public String toMessage()
208     {
209         StringBuilder buf = new StringBuilder();
210         buf.append("MISPKG");
211 
212         if(Name != null)
213         {
214             buf.append(" {Name ").append(Name).append("}");
215         }
216 
217         if((!Links.isEmpty()) && (Links.size() == Values.size()) && (Links.size() == Orders.size()))
218         {
219             for(int i = 0; i < Links.size(); i++)
220             {
221                 buf.append(" {Link ").append(Links.get(i)).append("}");
222                 buf.append(" {Value ").append(Values.get(i)).append("}");
223                 buf.append(" {Order ").append(Orders.get(i)).append("}");
224             }
225         }
226 
227         return buf.toString();
228     }
229 }