View Javadoc

1   package SteeringProperties;
2   
3   import SteeringStuff.SteeringType;
4   import XMLSteeringProperties.XMLObstacleAvoidanceProperties;
5   
6   /**
7    * The steering properties of the Obstacle Avoidance Steering.
8    * @author Marki
9    */
10  public class ObstacleAvoidanceProperties extends SteeringProperties {
11  
12      /**The magnitude of the repulsive force from the obstacles.
13       * Reasonable values are 0 - 1000, the default value is 240.*/
14      private int repulsiveForce;
15  
16      /**The order of the force. Possible values are 1 - 10, the default value is 1.
17       * The curve of reactions to obstacles according to the order 1 is linear, 2 quadratic, etc.
18       * It means that with higher order, the bot reacts less to dsitant obstacles and more to near obstacles.
19       * But the value 1 is most usefull value. Other values can cause strange behavior alongside walls etc.*/
20      private int forceOrder;
21  
22      /**Special solution of head-on collisions (front collisions). Basic behaviour leads to rebounding from the obstacles
23       * (when the bot aims to the obstacle head-on, he turns nearly 180° round just in front of the obstacle).
24       * When this parameter is on, bot turns and continues alongside the side of the obstacle. Recommended value is true.*/
25      private boolean frontCollisions;
26  
27      /**Tree collisions. The default value (in basic baheviour) is false. Recommended value is true.
28       * Special solution of collisions with trees and other narrow obstacles (so narrow, that just one of the rays will hit them).
29       * In basic behaviour (when the switch is off), when the bot aims to the tree that just the front side rays hits, he avoids the tree from the worse side.
30       * When the switch is on, he avoids the obstacle from the right (nearer) side.*/
31      private boolean treeCollisions;
32  
33      /**Creates the dafult ObstacleAvoidanceProperties. The order is 1, front collisions false and tree collision also false.*/
34      public ObstacleAvoidanceProperties() {
35          super(SteeringType.OBSTACLE_AVOIDANCE);
36          repulsiveForce = 240;
37          forceOrder = 1;
38          frontCollisions = true;
39          treeCollisions = true;
40      }
41  
42      /**Creates the dafult ObstacleAvoidanceProperties. The order is 1, front collisions false and tree collision also false.*/
43      public ObstacleAvoidanceProperties(BehaviorType behaviorType) {
44          super(SteeringType.OBSTACLE_AVOIDANCE, behaviorType);
45          repulsiveForce = 240;
46          forceOrder = 1;
47          frontCollisions = true;
48          treeCollisions = true;
49          setNewBehaviorType(behaviorType);
50      }
51  
52      /**Creates the ObstacleAvoidanceProperties from the XMLObstacleAvoidanceProperties.*/
53      public ObstacleAvoidanceProperties(XMLObstacleAvoidanceProperties xml) {
54          super(SteeringType.OBSTACLE_AVOIDANCE, xml.active, xml.weight, xml.behavior);
55          repulsiveForce = xml.repulsiveForce;
56          forceOrder = xml.forceOrder;
57          frontCollisions = xml.frontCollisions;
58          treeCollisions = xml.treeCollisions;
59      }
60  
61      /**
62       * Creates the ObstacleAvoidanceProperties.
63       * @param orderOfTheForce
64       * @param frontCollisions
65       * @param treeCollisions
66       */
67      public ObstacleAvoidanceProperties(int repulsiveForce, int orderOfTheForce, boolean frontCollisions, boolean treeCollisions) {
68          super(SteeringType.OBSTACLE_AVOIDANCE);
69          this.repulsiveForce = repulsiveForce;
70          this.forceOrder = orderOfTheForce;
71          this.frontCollisions = frontCollisions;
72          this.treeCollisions = treeCollisions;
73      }
74  
75      protected void setNewBehaviorType(BehaviorType behaviorType) {
76          if (behaviorType.equals(BehaviorType.BASIC)) {
77              frontCollisions = false;
78              treeCollisions = false;
79          } else if (behaviorType.equals(BehaviorType.ADVANCED)) {
80              frontCollisions = true;
81              treeCollisions = true;
82          }
83      }
84  
85      public int getRepulsiveForce() {
86          return repulsiveForce;
87      }
88  
89      public void setRepulsiveForce(int repulsiveForce) {
90          this.repulsiveForce = repulsiveForce;
91      }
92  
93      public int getForceOrder() {
94          return forceOrder;
95      }
96  
97      public void setForceOrder(int orderOfTheForce) {
98          this.forceOrder = orderOfTheForce;
99      }
100 
101     public boolean isFrontCollisions() {
102         return frontCollisions;
103     }
104 
105     public void setFrontCollisions(boolean frontCollisions) {
106         this.frontCollisions = frontCollisions;
107     }
108 
109     public boolean isTreeCollisions() {
110         return treeCollisions;
111     }
112 
113     public void setTreeCollisions(boolean treeCollisions) {
114         this.treeCollisions = treeCollisions;
115     }
116 
117     @Override
118     public String getSpecialText() {
119         String text = "";
120         text += "  * Repulsive Force: " + repulsiveForce + "\n";
121         text += "  * Force Order: " + forceOrder + "\n";
122         text += "  * Front Collisions: " + frontCollisions + "\n";
123         text += "  * Tree Collisions: " + treeCollisions + "\n";
124         return text;
125     }
126 
127     @Override
128     public void setProperties(SteeringProperties newProperties) {
129         this.repulsiveForce = ((ObstacleAvoidanceProperties)newProperties).getRepulsiveForce();
130         this.forceOrder = ((ObstacleAvoidanceProperties)newProperties).getForceOrder();
131         this.frontCollisions = ((ObstacleAvoidanceProperties)newProperties).isFrontCollisions();
132         this.treeCollisions = ((ObstacleAvoidanceProperties)newProperties).isTreeCollisions();
133     }
134 
135     public XMLObstacleAvoidanceProperties getXMLProperties() {
136         XMLObstacleAvoidanceProperties xmlProp = new XMLObstacleAvoidanceProperties();
137         xmlProp.repulsiveForce = repulsiveForce;
138         xmlProp.frontCollisions = frontCollisions;
139         xmlProp.forceOrder = forceOrder;
140         xmlProp.treeCollisions = treeCollisions;
141         xmlProp.active = active;
142         xmlProp.weight = weight;
143         xmlProp.behavior = behaviorType;
144         return xmlProp;
145     }
146 }