Skip to content

Commit f2d8654

Browse files
committed
updated readme for 1.2
1 parent aa4aba6 commit f2d8654

File tree

12 files changed

+97
-18
lines changed

12 files changed

+97
-18
lines changed

README.md

Lines changed: 97 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ src/
6060
my_robot.cc // Contains the implementation of the classes in my_robot.h
6161
```
6262

63-
Note that `esm generate` only makes directional robots. For an omni-directional robot, you need to subsequently edit the `defs/my_robot.json` file and change "shape" to "omni" and add a "radius" field (see below). 🔷 New in 1.1.
63+
Note that `esm generate` only makes directional robots. For an omni-directional robot, you need to subsequently edit the `defs/my_robot.json` file and change "shape" to "omni" and add a "radius" field (see below). ⑪ New in 1.1.
6464

6565
To compile the robot code, do
6666
```
@@ -126,10 +126,10 @@ A string describing the agent.
126126

127127
> `shape`<br>
128128
> ***polygon shaped:*** A list of pairs of the form `{ "x": 10, "y": 12 }` defining the vertices of a polygon. The physics engine will use this to determine the moment of initial and collision shape of the robot, and the user interface will use it to render the agent. All points are relative to the robot's center.<br>
129-
> ***circular:*** The string "omni", which makes a circular omni-directional agent. If you choose this option, you also need to specify a "radius". &#x1F537; New in 1.1.
129+
> ***circular:*** The string "omni", which makes a circular omni-directional agent. If you choose this option, you also need to specify a "radius". &#x246A; New in 1.1.
130130
131131
> `radius`<br>
132-
The radius of a circular, omnidirectional robot. Only used when the `shape` field is "omni". &#x1F537; New in 1.1.
132+
The radius of a circular, omnidirectional robot. Only used when the `shape` field is "omni". &#x246A; New in 1.1.
133133

134134
> `friction`<br>
135135
An object with three numerical fields, `collision`, `linear`, and `rotational` defining the fricition coefficients of the robot with other robots and with the environment. Note that the latter two coefficients are only used if you apply a control in your `update()` methods such as `damp_movement()` or `track_velocity()`.
@@ -194,14 +194,17 @@ Processes and state machines that are added to agents are both elma processes an
194194
195195
The agent interface class methods are described below. They are available in the `init()`, `start()`, `update()`, and `stop()` methods of your process, as well as the `entry()`, `during()` and `exit()` methods of any states in your state machines.
196196
197+
Agent State
198+
---
199+
197200
> `cpVect position()` <br>
198201
This method returns the position of the agent. The `cpVect` structure has fields `x` and `y` that can be treated as `doubles`.
199202
200203
> `cpVect velocity()`<br>
201204
This method returns the velocity of the agent. The `cpVect` structure has fields `x` and `y` that can be treated as `doubles`.
202205
203206
> `x()`, `y()`, `vx()`, `vy()`<br>
204-
The horizontal and verical positions, and the horizonal and vertical velocities -- separated out so you do not need to about the structure. &#x1F537; New in 1.1.
207+
The horizontal and verical positions, and the horizonal and vertical velocities -- separated out so you do not need to about the structure. &#x246A; New in 1.1.
205208
206209
> `double angle()`<br>
207210
This method returns the angle of the agent in radians and can be treated as a `double`.
@@ -212,6 +215,9 @@ This method returns the angular velocity of the agent in radians per second and
212215
> `int id()`<br>
213216
This method returns a unique id of the agent.
214217
218+
Motion Control for Oriented Agents
219+
---
220+
215221
> `void apply_force(double thrust, double torque)`<br>
216222
This methied applies a force specified by the `thrust` argument in the direction the agent is currently facing, and applies a torque specified by the `torque` argument around the center of the agent. The agent's mass comes in to play here using Newton's laws of motion.
217223
@@ -233,20 +239,93 @@ This method returns the value of the specificed index. It is the distance from t
233239
> `std::vector<double> sensor_values()`<br>
234240
This method returns a list of all the sensor values, in the same order as the sensors appear in the agent's JSON definition.
235241
236-
For Omni Directional Robots
242+
Motion Control For Omni Directional Agents
237243
---
238244
239245
> `void omni_apply_force(double fx, double fy)`<br>
240-
This methied applies a force specified by the arguments. The agent's mass comes in to play here using Newton's laws of motion. &#x1F537; New in 1.1.
246+
This methied applies a force specified by the arguments. The agent's mass comes in to play here using Newton's laws of motion. &#x246A; New in 1.1.
241247
242248
> `void omni_track_velocity(double vx, double vy, double k=10)` <br>
243-
This method makes the agent attempty to track the given translational velocity. If other elements are in the way, or if it is experience collisions, it may not be able to exactly track these values. The optional argument is the proportional gain on the feedback controller that implements the tracking controller. &#x1F537; New in 1.1.
249+
This method makes the agent attempty to track the given translational velocity. If other elements are in the way, or if it is experience collisions, it may not be able to exactly track these values. The optional argument is the proportional gain on the feedback controller that implements the tracking controller. &#x246A; New in 1.1.
244250
245251
> `void omni_damp_movement()`<br>
246-
This method slows the agent down using the linear and angular friction coefficients defined in the agent's JSON definition file. &#x1F537; New in 1.1.
252+
This method slows the agent down using the linear and angular friction coefficients defined in the agent's JSON definition file. &#x246A; New in 1.1.
247253
248254
> `void omni_move_toward(double x, double y, double v=1)`<br>
249-
This method attepts to move the agent to the given (x,y) location. If something in the way, the agent will not get there. The robot simultaneously attempts to rotate so that it is pointing toward the target and also moves forward, going faster as its angular error is reduced. The optional argument is the desired velocity of rotation and forward motion. &#x1F537; New in 1.1.
255+
This method attepts to move the agent to the given (x,y) location. If something in the way, the agent will not get there. The robot simultaneously attempts to rotate so that it is pointing toward the target and also moves forward, going faster as its angular error is reduced. The optional argument is the desired velocity of rotation and forward motion. &#x246A; New in 1.1.
256+
257+
Collisions
258+
---
259+
260+
> `void notice_collisions_with(const std::string agent_type, std::function<void(Event&)> handler)` <br>
261+
> Runs the handler function upon collisions with agents of the given agent type.
262+
> The `agent_type` string is the name used in `defs/*.json` files.
263+
> These should usually be set up in the `init` function of a process, as follows:
264+
> ```c++
265+
> void init() {
266+
> notice_collisions_with("Robot", [&](Event &e) {
267+
> int other_robot_id = e.value()["id"];
268+
> Agent& other_robot = find_agent(other_robot_id);
269+
> // etc.
270+
> });
271+
> }
272+
> ```
273+
> &#x246B; New in 1.2.
274+
275+
> `void ignore_collisions_with(const std::string agent_type)` <br>
276+
> Stop noticing collisions with agents of the given type.
277+
> &#x246B; New in 1.2.
278+
279+
Constraints
280+
---
281+
282+
> `void attach_to(Agent &other_agent)` <br>
283+
> Create a constraint that attaches the calling agent to the `other_agent`.
284+
> For example, after the call
285+
> ```c++
286+
> Agent& other_robot = find_agent(other_robot_id);
287+
> attach_to(other_robot);
288+
> ```
289+
> the two agents center's will be constrained to remain at the same distance from each other.
290+
> &#x246B; New in 1.2.
291+
292+
Agent Management
293+
---
294+
295+
> `Agent& find_agent(int id)` <br>
296+
> Given an agent's id, returns a reference to the agent. Note: ***do not*** assign the return value of this function to a normal
297+
> variable, because when it goes out of scope, the agent's destructor will be called. Instead, assign it to a reference, as in
298+
> ```c++
299+
> Agent& other_agent = find_agent(other_agent_id;
300+
> ```
301+
> &#x246B; New in 1.2.
302+
303+
> `bool agent_exists(int id)` <br>
304+
> Returns true or false depending on whether an agent with the given id still exists (i.e. is being managed by enviro).
305+
> Agents may cease to exist if `remove_agent()` is called.
306+
> &#x246B; New in 1.2.
307+
308+
> `void remove_agent(int id)` <br>
309+
> Removes the agent with the given id from the simulation. Also calls it's desctructor, so think of it as remove and delete.
310+
> &#x246B; New in 1.2.
311+
312+
> `Agent& add_agent(const std::string name, double x, double y, double theta, const json style)` <br>
313+
> Add's a new agent to the simulation with the given name at the given position and orientation.
314+
> Note that an agent with this type should have been mentioned in `config.json` so enviro knows about it.
315+
> The style argument determines the agent's style, just as in the configuration file.
316+
> Any valid svg styling will work. For example:
317+
> ```c++
318+
> Agent& v = add_agent("Block", 0, 0, 0, {{"fill": "bllue"},{"stroke": "black"}});
319+
> ```
320+
> &#x246B; New in 1.2.
321+
322+
Styling
323+
---
324+
325+
> `void set_style(json style)` <br>
326+
> Change the agent's style, just as in the configuration file.
327+
> Any valid svg styling will work.
328+
> &#x246B; New in 1.2.
250329
251330
Project Configuration
252331
===
@@ -273,7 +352,7 @@ The port for the server. Use `8765` for now.
273352
> ```
274353
> The name field is used to catch button click events (see below). The label field defines the string displayed on the button.
275354
> The style field is an `css` code you want to add to the stying of the button.
276-
> &#x1F536; New in 1.0.
355+
> &#x2469; New in 1.0.
277356
278357
> `agents`<br>
279358
> A list of agents to put in the simulation. For example,
@@ -310,29 +389,29 @@ Responding to Front End Events
310389
311390
The brower client relays mouse click, button press, and keyboard events to the enviro server, which your process can watch for. The event types and associated information are:
312391
313-
> Name: `screen_click`
392+
> Name: `screen_click`<br>
314393
> Value: An object with `x` and `y` fields holding the location of the click in world coordinates.
315394
316-
> Name: `agent_click`
395+
> Name: `agent_click`<br>
317396
> Value: An object with `id`, `x` and `y` fields holding the agent's id and the location of the click in **agent** coordinates.
318397
319-
> Name: `button_click`
398+
> Name: `button_click`<br>
320399
> Value: An object with the a `name` field that matches the name field used in `config.json`.
321-
> &#x1F536; New in 1.0.
400+
> &#x2469; New in 1.0.
322401
323-
> Name: `keydown`
402+
> Name: `keydown`<br>
324403
> Value: An object with a `key` field, which is the character pressed, as well as the following boolean fields
325404
> ```
326405
> ctrlKey
327406
> shiftKey
328407
> altKey
329408
> metaKey
330409
> ```
331-
> &#x1F536; New in 1.0.
410+
> &#x2469; New in 1.0.
332411
333-
> Name: `keyup`
412+
> Name: `keyup`<br>
334413
> Value: Same as for `keydown`.
335-
> &#x1F536; New in 1.0.
414+
> &#x2469; New in 1.0.
336415
337416
To respond to events in your code, you should put elma watchers into the `init()` method of some process. For example, to respond to an agent click, you might do
338417
```c++
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)