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 default ObstacleAvoidanceProperties. The order is 1, front collisions true and tree collision also true.*/
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 ObstacleAvoidanceProperties - BASIC/ADVANCED.*/
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 repulsiveForce The magnitude of the repulsive force from the obstacles.
64       * Reasonable values are 0 - 1000, the default value is 240.
65       * @param orderOfTheForce The order of the force. Possible values are 1 - 10, the default value is 1.
66       * The curve of reactions to obstacles according to the order 1 is linear, 2 quadratic, etc.
67       * It means that with higher order, the bot reacts less to dsitant obstacles and more to near obstacles.
68       * But the value 1 is most usefull value. Other values can cause strange behavior alongside walls etc.
69       * @param frontCollisions Special solution of head-on collisions (front collisions). Basic behaviour leads to rebounding from the obstacles
70       * (when the bot aims to the obstacle head-on, he turns nearly 180° round just in front of the obstacle).
71       * When this parameter is on, bot turns and continues alongside the side of the obstacle. Recommended value is true.
72       * @param treeCollisions Tree collisions. The default value (in basic baheviour) is false. Recommended value is true.
73       * Special solution of collisions with trees and other narrow obstacles (so narrow, that just one of the rays will hit them).
74       * 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.
75       * When the switch is on, he avoids the obstacle from the right (nearer) side.
76       */
77      public ObstacleAvoidanceProperties(int repulsiveForce, int orderOfTheForce, boolean frontCollisions, boolean treeCollisions) {
78          super(SteeringType.OBSTACLE_AVOIDANCE);
79          this.repulsiveForce = repulsiveForce;
80          this.forceOrder = orderOfTheForce;
81          this.frontCollisions = frontCollisions;
82          this.treeCollisions = treeCollisions;
83      }
84  
85      protected void setNewBehaviorType(BehaviorType behaviorType) {
86          if (behaviorType.equals(BehaviorType.BASIC)) {
87              frontCollisions = false;
88              treeCollisions = false;
89          } else if (behaviorType.equals(BehaviorType.ADVANCED)) {
90              frontCollisions = true;
91              treeCollisions = true;
92          }
93      }
94  
95      public int getRepulsiveForce() {
96          return repulsiveForce;
97      }
98  
99      public void setRepulsiveForce(int repulsiveForce) {
100         this.repulsiveForce = repulsiveForce;
101     }
102 
103     public int getForceOrder() {
104         return forceOrder;
105     }
106 
107     public void setForceOrder(int orderOfTheForce) {
108         this.forceOrder = orderOfTheForce;
109     }
110 
111     public boolean isFrontCollisions() {
112         return frontCollisions;
113     }
114 
115     public void setFrontCollisions(boolean frontCollisions) {
116         this.frontCollisions = frontCollisions;
117     }
118 
119     public boolean isTreeCollisions() {
120         return treeCollisions;
121     }
122 
123     public void setTreeCollisions(boolean treeCollisions) {
124         this.treeCollisions = treeCollisions;
125     }
126 
127     @Override
128     public String getSpecialText() {
129         String text = "";
130         text += "  * Repulsive Force: " + repulsiveForce + "\n";
131         text += "  * Force Order: " + forceOrder + "\n";
132         text += "  * Front Collisions: " + frontCollisions + "\n";
133         text += "  * Tree Collisions: " + treeCollisions + "\n";
134         return text;
135     }
136 
137     @Override
138     public void setProperties(SteeringProperties newProperties) {
139         this.repulsiveForce = ((ObstacleAvoidanceProperties)newProperties).getRepulsiveForce();
140         this.forceOrder = ((ObstacleAvoidanceProperties)newProperties).getForceOrder();
141         this.frontCollisions = ((ObstacleAvoidanceProperties)newProperties).isFrontCollisions();
142         this.treeCollisions = ((ObstacleAvoidanceProperties)newProperties).isTreeCollisions();
143     }
144 
145     public XMLObstacleAvoidanceProperties getXMLProperties() {
146         XMLObstacleAvoidanceProperties xmlProp = new XMLObstacleAvoidanceProperties();
147         xmlProp.repulsiveForce = repulsiveForce;
148         xmlProp.frontCollisions = frontCollisions;
149         xmlProp.forceOrder = forceOrder;
150         xmlProp.treeCollisions = treeCollisions;
151         xmlProp.active = active;
152         xmlProp.weight = weight;
153         xmlProp.behavior = behaviorType;
154         return xmlProp;
155     }
156 }