Pheromone dispersal first pass.
This commit is contained in:
@@ -24,6 +24,8 @@
|
||||
*************************************************************************************/
|
||||
|
||||
#include <limits>
|
||||
#include <cstdlib>
|
||||
#include <cmath>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "ias_robot.hpp"
|
||||
@@ -34,8 +36,15 @@ static const long HALF_SECOND_USEC = 500000;
|
||||
static const double MIN_DIST_M = 1.5;
|
||||
static const double CRIT_DIST_M = 1.0;
|
||||
static const float MAP_SIZE = 16.0f;
|
||||
static const int PHERO_AMOUNT = 10;
|
||||
static const float PHERO_RADIUS = 1.0;
|
||||
|
||||
static inline float random_num() {
|
||||
return (((static_cast<float>(rand() % 256) / 256.0) - 0.5f) * 2.0f ) * PHERO_RADIUS;
|
||||
}
|
||||
|
||||
IASSS_Robot::IASSS_Robot(std::string hostname, uint32_t port, PheromoneMap * phero_map) : Robot(hostname, port) {
|
||||
srand(port + time(NULL));
|
||||
_phero_map = phero_map;
|
||||
log("Creating IAS-SS robot");
|
||||
}
|
||||
@@ -46,7 +55,6 @@ IASSS_Robot::~IASSS_Robot() {
|
||||
|
||||
void IASSS_Robot::run() {
|
||||
int rv;
|
||||
float x, y;
|
||||
long then, now, delta, wait;
|
||||
struct timeval tv;
|
||||
double dist = std::numeric_limits<double>::infinity();
|
||||
@@ -74,12 +82,8 @@ void IASSS_Robot::run() {
|
||||
now = tv.tv_usec;
|
||||
delta = now - then;
|
||||
|
||||
if(_phero_map != NULL) {
|
||||
x = (_p_proxy->GetXPos() + (MAP_SIZE / 2)) / MAP_SIZE;
|
||||
y = (_p_proxy->GetYPos() + (MAP_SIZE / 2)) / MAP_SIZE;
|
||||
_phero_map->s_draw_point(x, y);
|
||||
}
|
||||
|
||||
deposit_pheromone();
|
||||
|
||||
// Sleep for a bit before finishing this control iteration.
|
||||
wait = rv == 0 ? HALF_SECOND_USEC - delta : HALF_SECOND_USEC;
|
||||
usleep(wait);
|
||||
@@ -102,3 +106,27 @@ void IASSS_Robot::avoid_wall(float front_speed, float turn_speed) {
|
||||
else
|
||||
_p_proxy->SetSpeed(front_speed, PlayerCc::dtor(turn_speed));
|
||||
}
|
||||
|
||||
void IASSS_Robot::deposit_pheromone() {
|
||||
float x = _p_proxy->GetXPos();//
|
||||
float y = _p_proxy->GetYPos();// + (MAP_SIZE / 2)) / MAP_SIZE;
|
||||
float px, py;
|
||||
|
||||
if(_phero_map != NULL) {
|
||||
for(int i = 0; i < PHERO_AMOUNT; i++) {
|
||||
px = random_num() + x;
|
||||
py = random_num() + y;
|
||||
if(fabs(px) < (MAP_SIZE / 2) && fabs(py) < (MAP_SIZE / 2)) {
|
||||
px = (px + (MAP_SIZE / 2)) / MAP_SIZE;
|
||||
py = (py + (MAP_SIZE / 2)) / MAP_SIZE;
|
||||
if(!_phero_map->s_deposit_pheromone(px, py)) {
|
||||
i--;
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
i--;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user