-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug fix for sensors with noninteractive and invisble agents
- Loading branch information
Showing
29 changed files
with
564 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
TARGET := bin/enviro | ||
|
||
all: | ||
$(MAKE) -C src all | ||
|
||
clean: | ||
$(MAKE) -C src clean | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
|
||
"name": "My Enviro Project", | ||
"ip": "0.0.0.0", | ||
"port": 8765, | ||
|
||
"buttons": [], | ||
|
||
"agents": [ | ||
{ | ||
"definition": "defs/guy.json", | ||
"style": { "fill": "azure", "stroke": "black" }, | ||
"position": { "x": 0, "y": -200, "theta": 0 } | ||
} | ||
], | ||
|
||
"invisibles": [ | ||
{ | ||
"definition": "defs/coordinator.json", | ||
"rendered": false | ||
} | ||
], | ||
|
||
"references": [ | ||
{ | ||
"definition": "defs/thing.json", | ||
"style": { "fill": "azure", "stroke": "black" }, | ||
"position": { "x": 0, "y": 0, "theta": 0 } | ||
} | ||
], | ||
|
||
"statics": [] | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Put agent definitions in this folder. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "Coordinator", | ||
"type": "invisible", | ||
"description": "Runs the whole show, but isn't rendered", | ||
"controller": "lib/coordinator.so" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"name": "Guy", | ||
"type": "dynamic", | ||
"description": "A guy that users can move around the screen", | ||
"shape": [ | ||
{ "x": -10, "y": 10 }, | ||
{ "x": 10, "y": 10 }, | ||
{ "x": 10, "y": 2 }, | ||
{ "x": 12, "y": 2 }, | ||
{ "x": 12, "y": 6 }, | ||
{ "x": 16, "y": 6 }, | ||
{ "x": 16, "y": 4 }, | ||
{ "x": 14, "y": 4 }, | ||
{ "x": 14, "y": -4}, | ||
{ "x": 16, "y": -4 }, | ||
{ "x": 16, "y": -6 }, | ||
{ "x": 12, "y": -6 }, | ||
{ "x": 12, "y": -2 }, | ||
{ "x": 10, "y": -2 }, | ||
{ "x": 10, "y": -10 }, | ||
{ "x": -10, "y": -10 }, | ||
{ "x": -9, "y": 0 } | ||
], | ||
"friction": { | ||
"collision": 5, | ||
"linear": 40, | ||
"rotational": 600 | ||
}, | ||
"sensors": [], | ||
"mass": 1, | ||
"controller": "lib/guy.so" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "Thing", | ||
"type": "dynamic", | ||
"description": "Replace this string with a description", | ||
"shape": [ | ||
{ "x": -5, "y": 5 }, | ||
{ "x": 5, "y": 5 }, | ||
{ "x": 5, "y": -5 }, | ||
{ "x": -5, "y": -5 } | ||
], | ||
"friction": { | ||
"collision": 5, | ||
"linear": 40, | ||
"rotational": 600 | ||
}, | ||
"sensors": [], | ||
"mass": 1, | ||
"controller": "lib/thing.so" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Shared object libraries will be place here by make. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#Architecture | ||
ARCH := $(shell uname -m) | ||
|
||
#Compilers | ||
CC := g++ -std=c++17 -Wno-psabi | ||
|
||
#The Target Library | ||
|
||
#The Directories, Source, Includes, Objects, Binary and Resources | ||
SRCEXT := cc | ||
|
||
# Directories | ||
CHIPDIR := /usr/local/src/Chipmunk2D | ||
ENVIRODIR := /usr/local/src/enviro/server/include | ||
|
||
#Flags, Libraries and Includes | ||
CFLAGS := -ggdb -shared -fPIC | ||
INCLUDE := -I $(ENVIRODIR) -I $(CHIPDIR)/include/chipmunk | ||
|
||
#Files | ||
|
||
TARGETDIR := ../lib | ||
SOURCES := $(wildcard *.cc) | ||
HEADERS := $(wildcard *.h) | ||
TARGETS := $(patsubst %.cc,%.so,$(wildcard *.cc)) | ||
FULL_TARGETS := $(addprefix $(TARGETDIR)/, $(TARGETS)) | ||
|
||
#Default Make | ||
all: $(FULL_TARGETS) | ||
|
||
#Clean only Objects | ||
clean: | ||
@$(RM) -rf $(TARGETDIR)/*.so | ||
|
||
# Compile | ||
$(TARGETDIR)/%.so: %.cc %.h | ||
$(CC) $(CFLAGS) $(INCLUDE) $< -o $@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#include <iostream> | ||
#include "coordinator.h" | ||
|
||
using namespace enviro; | ||
|
||
// Put your implementations here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#ifndef __COORDINATOR_AGENT__H | ||
#define __COORDINATOR_AGENT__H | ||
|
||
#include "enviro.h" | ||
|
||
using namespace enviro; | ||
|
||
class CoordinatorController : public Process, public AgentInterface { | ||
|
||
public: | ||
CoordinatorController() : Process(), AgentInterface() {} | ||
|
||
void init() { | ||
for ( double x = -200; x <= 200; x += 50) { | ||
for ( double y = 0; y <= 200; y += 50 ) { | ||
add_agent("Thing", x, y, 0, { {"fill", "blue"}}); | ||
} | ||
} | ||
} | ||
void start() {} | ||
void update() {} | ||
void stop() {} | ||
|
||
}; | ||
|
||
class Coordinator : public Agent { | ||
public: | ||
Coordinator(json spec, World& world) : Agent(spec, world) { | ||
add_process(c); | ||
} | ||
private: | ||
CoordinatorController c; | ||
}; | ||
|
||
DECLARE_INTERFACE(Coordinator) | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#include <iostream> | ||
#include "guy.h" | ||
|
||
using namespace enviro; | ||
|
||
// Put your implementations here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#ifndef __PLAYER_AGENT__H | ||
#define __PLAYER_AGENT__H | ||
|
||
#include "enviro.h" | ||
|
||
using namespace enviro; | ||
|
||
class GuyController : public Process, public AgentInterface { | ||
|
||
public: | ||
GuyController() : Process(), AgentInterface(), v(0), omega(0) {} | ||
|
||
void init() { | ||
watch("keydown", [&](Event &e) { | ||
auto k = e.value()["key"].get<std::string>(); | ||
if ( k == "w" ) { | ||
v = v_m; | ||
} else if ( k == "s" ) { | ||
v = -v_m; | ||
} else if ( k == "a" ) { | ||
omega = -omega_m; | ||
} else if ( k == "d" ) { | ||
omega = omega_m; | ||
} | ||
}); | ||
watch("keyup", [&](Event &e) { | ||
auto k = e.value()["key"].get<std::string>(); | ||
if ( k == "w" || k == "s" ) { | ||
v = 0; | ||
} else if ( k == "a" ) { | ||
omega = 0; | ||
} else if ( k == "d" ) { | ||
omega = 0; | ||
} | ||
}); | ||
} | ||
void start() {} | ||
void update() { | ||
track_velocity(v,omega,10,400); | ||
label(std::to_string((int) x()) + ", " + std::to_string((int)y()),20,20); | ||
emit(Event("guy_position", { { "x", x()}, {"y", y() }})); | ||
} | ||
void stop() {} | ||
|
||
double v, omega; | ||
double const v_m = 30, omega_m = 1; | ||
double const magnitude = 200; | ||
|
||
}; | ||
|
||
class Guy : public Agent { | ||
public: | ||
Guy(json spec, World& world) : Agent(spec, world) { | ||
add_process(c); | ||
} | ||
private: | ||
GuyController c; | ||
|
||
}; | ||
|
||
DECLARE_INTERFACE(Guy) | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#include <iostream> | ||
#include "thing.h" | ||
|
||
using namespace enviro; | ||
|
||
// Put your implementations here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#ifndef __THING_AGENT__H | ||
#define __THING_AGENT__H | ||
|
||
#include "enviro.h" | ||
|
||
using namespace enviro; | ||
|
||
class ThingController : public Process, public AgentInterface { | ||
|
||
public: | ||
ThingController() : Process(), AgentInterface(), guy_x(0), guy_y(0) {} | ||
|
||
void init() { | ||
watch("guy_position", [&](Event& e) { | ||
guy_x = e.value()["x"]; | ||
guy_y = e.value()["y"]; | ||
}); | ||
} | ||
void start() {} | ||
void update() { | ||
omni_move_toward(guy_x, guy_y, 0.1); | ||
} | ||
void stop() {} | ||
|
||
double guy_x, guy_y; | ||
|
||
}; | ||
|
||
class Thing : public Agent { | ||
public: | ||
Thing(json spec, World& world) : Agent(spec, world) { | ||
add_process(c); | ||
} | ||
private: | ||
ThingController c; | ||
}; | ||
|
||
DECLARE_INTERFACE(Thing) | ||
|
||
#endif |
Oops, something went wrong.