Skip to content

Commit

Permalink
heading following example
Browse files Browse the repository at this point in the history
  • Loading branch information
klavins committed Mar 13, 2020
1 parent f0203f5 commit ac8a65e
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 2 deletions.
10 changes: 10 additions & 0 deletions examples/track_heading/Makefile
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



21 changes: 21 additions & 0 deletions examples/track_heading/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{

"name": "My Enviro Project",
"ip": "0.0.0.0",
"port": 8765,

"buttons": [],

"agents": [
{
"definition": "defs/robot.json",
"style": { "fill": "lightgreen", "stroke": "black" },
"position": { "x": -200, "y": -200, "theta": 0 }
}
],

"statics": [

]

}
1 change: 1 addition & 0 deletions examples/track_heading/defs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Put agent definitions in this folder.
32 changes: 32 additions & 0 deletions examples/track_heading/defs/robot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "Robot",
"type": "dynamic",
"description": "Replace this string with a description",
"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/robot.so"
}
1 change: 1 addition & 0 deletions examples/track_heading/lib/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Shared object libraries will be place here by make.
38 changes: 38 additions & 0 deletions examples/track_heading/src/Makefile
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 $@

6 changes: 6 additions & 0 deletions examples/track_heading/src/robot.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <iostream>
#include "robot.h"

using namespace enviro;

// Put your implementations here
45 changes: 45 additions & 0 deletions examples/track_heading/src/robot.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#ifndef __ROBOT_AGENT__H
#define __ROBOT_AGENT__H

#include "enviro.h"
#include "math.h"

using namespace enviro;

class RobotController : public Process, public AgentInterface {

public:
RobotController() : Process(), AgentInterface() {}

void init() {
desired_heading = 0;
counter = 0;
}
void start() {}
void update() {
if ( counter++ > 50 ) {
desired_heading += M_PI / 2;
counter = 0;
}
track_velocity(20,30*sin(desired_heading-angle()) - 100*angular_velocity());
label(std::to_string((int) (2*desired_heading/M_PI)) + " pi",15,-15);
}
void stop() {}

int counter;
double desired_heading;

};

class Robot : public Agent {
public:
Robot(json spec, World& world) : Agent(spec, world) {
add_process(c);
}
private:
RobotController c;
};

DECLARE_INTERFACE(Robot)

#endif
5 changes: 3 additions & 2 deletions server/src/world.cc
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,9 @@ namespace enviro {
}

void World::remove(int id) {
std::cout << "marking " << id << " for removal" << "\n";
find_agent(id).mark_for_removal();
if ( exists(id) ) {
find_agent(id).mark_for_removal();
}
}

void World::remove_constraints_involving(int id) {
Expand Down

0 comments on commit ac8a65e

Please sign in to comment.