Code Examples
A repository of 155 code examples for BeepBeep
RobotEvent.java
1 /*
2  BeepBeep, an event stream processor
3  Copyright (C) 2008-2023 Sylvain HallĂ©
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published
7  by the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package robot;
19 
20 import java.util.Vector;
21 
22 import ca.uqac.lif.cep.functions.UnaryFunction;
23 
24 /**
25  * Event representing the status of a fictional robot that moves in a
26  * two-dimensional space.
27  * @author Sylvain HallĂ©
28  */
29 public class RobotEvent
30 {
31  /**
32  * Static reference to the function {@link GetPosition}.
33  */
34  /*@ non_null @*/ public static final GetPosition getPos = new GetPosition();
35 
36  /**
37  * Static reference to the function {@link GetVelocity}.
38  */
39  /*@ non_null @*/ public static final GetVelocity getVel = new GetVelocity();
40 
41  /**
42  * Static reference to the function {@link GetAngle}.
43  */
44  /*@ non_null @*/ public static final GetAngle getAngle = new GetAngle();
45 
46  /**
47  * A vector indicating the position of the robot.
48  */
49  protected final Vector<Float> m_position;
50 
51  /**
52  * A vector indicating the velocity of the robot.
53  */
54  protected final Vector<Float> m_velocity;
55 
56  /**
57  * The the angle of orientation of the robot (in radians).
58  */
59  protected final float m_theta;
60 
61  /**
62  * Creates a new robot event.
63  * @param position The position of the robot
64  * @param velocity The velocity of the robot
65  * @param theta The angle of orientation of the robot (in radians)
66  */
67  public RobotEvent(Vector<Float> position, Vector<Float> velocity, float theta)
68  {
69  super();
70  m_position = position;
71  m_velocity = velocity;
72  m_theta = theta;
73  }
74 
75  /**
76  * Gets the position of the robot.
77  * @return The position
78  */
79  /*@ pure @*/ public Vector<Float> getPosition()
80  {
81  return m_position;
82  }
83 
84  /**
85  * Gets the velocity of the robot.
86  * @return The velocity
87  */
88  /*@ pure @*/ public Vector<Float> getVelocity()
89  {
90  return m_velocity;
91  }
92 
93  /**
94  * Gets the angle of orientation of the robot.
95  * @return The angle (in radians)
96  */
97  /*@ pure @*/ public float getOrientation()
98  {
99  return m_theta;
100  }
101 
102  @Override
103  public String toString()
104  {
105  StringBuilder out = new StringBuilder();
106  out.append("\u27e8");
107  out.append("p:").append(m_position).append(",");
108  out.append("v:").append(m_velocity).append(",");
109  out.append("p\u03b8:").append(m_theta);
110  out.append("\u27e9");
111  return out.toString();
112  }
113 
114  /**
115  * BeepBeep function that extracts the x-position of a {@link RobotEvent}.
116  */
117  @SuppressWarnings("rawtypes")
118  public static class GetPosition extends UnaryFunction<RobotEvent,Vector>
119  {
120  GetPosition()
121  {
122  super(RobotEvent.class, Vector.class);
123  }
124 
125  @Override
126  public Vector getValue(RobotEvent e)
127  {
128  return e.getPosition();
129  }
130 
131  @Override
132  public GetPosition duplicate(boolean with_state)
133  {
134  return this;
135  }
136 
137  @Override
138  public String toString()
139  {
140  return "p?";
141  }
142  }
143 
144  /**
145  * BeepBeep function that extracts the velocity of a {@link RobotEvent}.
146  */
147  @SuppressWarnings("rawtypes")
148  public static class GetVelocity extends UnaryFunction<RobotEvent,Vector>
149  {
150  GetVelocity()
151  {
152  super(RobotEvent.class, Vector.class);
153  }
154 
155  @Override
156  public Vector getValue(RobotEvent e)
157  {
158  return e.getVelocity();
159  }
160 
161  @Override
162  public GetVelocity duplicate(boolean with_state)
163  {
164  return this;
165  }
166 
167  @Override
168  public String toString()
169  {
170  return "v?";
171  }
172  }
173 
174  /**
175  * BeepBeep function that extracts the orientation of a {@link RobotEvent}.
176  */
177  public static class GetAngle extends UnaryFunction<RobotEvent,Float>
178  {
179  GetAngle()
180  {
181  super(RobotEvent.class, Float.class);
182  }
183 
184  @Override
185  public Float getValue(RobotEvent e)
186  {
187  return e.getOrientation();
188  }
189 
190  @Override
191  public GetAngle duplicate(boolean with_state)
192  {
193  return this;
194  }
195 
196  @Override
197  public String toString()
198  {
199  return "\u03b8?";
200  }
201  }
202 }
Vector< Float > getVelocity()
Gets the velocity of the robot.
Definition: RobotEvent.java:88
static final GetPosition getPos
Static reference to the function GetPosition.
Definition: RobotEvent.java:34
static final GetAngle getAngle
Static reference to the function GetAngle.
Definition: RobotEvent.java:44
final Vector< Float > m_velocity
A vector indicating the velocity of the robot.
Definition: RobotEvent.java:54
final Vector< Float > m_position
A vector indicating the position of the robot.
Definition: RobotEvent.java:49
final float m_theta
The the angle of orientation of the robot (in radians).
Definition: RobotEvent.java:59
static final GetVelocity getVel
Static reference to the function GetVelocity.
Definition: RobotEvent.java:39
Event representing the status of a fictional robot that moves in a two-dimensional space...
Definition: RobotEvent.java:29
RobotEvent(Vector< Float > position, Vector< Float > velocity, float theta)
Creates a new robot event.
Definition: RobotEvent.java:67
Vector< Float > getPosition()
Gets the position of the robot.
Definition: RobotEvent.java:79
float getOrientation()
Gets the angle of orientation of the robot.
Definition: RobotEvent.java:97