View Javadoc

1   package cz.cuni.amis.pogamut.usar2004.communication.messages.datatypes;
2   
3   import java.util.ArrayList;
4   import java.util.List;
5   
6   /**
7    *
8    * LINK parameter gives the link number that will be described by the next two
9    * parameters (Value and Torque). Please note that you will have as many as
10   * these parameters as you have links. *
11   *
12   * VALUE parameter has two possible meanings. If the link being described is a
13   * prismatic joint, double gives the distance (in meters) from the original
14   * position of the link. If the link being described is a revolute joint, it
15   * gives a sector(probably).
16   *
17   * The TORQUE parameter gives the current torque of the link being described. *
18   * All of the above are collected into one data structure below this text.
19   *
20   * @author vejmanm
21   *
22   */
23  public class LinkStateSet
24  {
25      private List<Integer> links = new ArrayList<Integer>();
26      private List<Double> values = new ArrayList<Double>();
27      private List<Double> torques = new ArrayList<Double>();
28  
29      public LinkStateSet()
30      {
31      }
32  
33      public void add(int l, double v, double t)
34      {
35          links.add(l);
36          values.add(v);
37          torques.add(t);
38      }
39  
40      public void add(LinkState ls)
41      {
42          links.add(ls.getLink());
43          values.add(ls.getValue());
44          torques.add(ls.getTorque());
45      }
46  
47      public void addLink(int l)
48      {
49          links.add(l);
50      }
51  
52      public void addValue(double v)
53      {
54          values.add(v);
55      }
56  
57      public void addTorque(double t)
58      {
59          torques.add(t);
60      }
61  
62      public List<LinkState> GetLinkStateList()
63      {
64          try
65          {
66              if(links.size() != values.size() || links.size() != torques.size())
67              {
68                  throw new Exception("Could not convert! Arrays are of different sizes!");
69              }
70  
71              List<LinkState> returnee = new ArrayList<LinkState>();
72              for(int i = 0; i < links.size(); i++)
73              {
74                  LinkState l = new LinkState(links.get(i), values.get(i), torques.get(i));
75                  returnee.add(l);
76              }
77              return returnee;
78          }
79          catch(Exception e)
80          {
81              return null;
82          }
83      }
84  
85      public boolean isEmpty()
86      {
87          return links.isEmpty();
88      }
89  }