Ejemplo n.º 1
0
void Copter::move(const ControlData& controldata)
{
	//еще нужно:
	//проверка границ
	//приведение значений(умное приведение значений, _controlData.THROTTLE < max, нахождение максимальных углов в зависимости от
	//ускорения висения)

	_controlData.YAW = controldata.oZ/2 + mid;

	Angle angle;
	if(_throtCorrectionMode == CorrectionByInputData)
	{
		angle.oX = (((double)controldata.x)*M_PI_2)/max_range;
		angle.oY = (((double)controldata.y)*M_PI_2)/max_range;
	}
	else if(_throtCorrectionMode == CorrectionByInputAngle)
	{
		angle = _throtCorrectionAngle;
	}
	else
	{
		angle.oX = 0;
		angle.oY = 0;
	}

	//Здесь корректировка углов.
	_controlData.PITCH = controldata.y/2 + mid;
	_controlData.ROLL = controldata.x/2 + mid;

	_controlData.THROTTLE = ((controldata.z + _accelZeroGravity) * sqrt(pow(tan(angle.oX), 2) + pow(tan(angle.oY), 2) + 1))/2 + mid;

	directMove(_controlData);
}
Ejemplo n.º 2
0
void Ant::freeMove(Ground& ground)
{
  Direction tmp;
  if ((tmp = ground.findFoodNextTo(x, y)) != Direction::NO_DIRECTION)
  {
    goToDirectionNoCheck(tmp);
    
    return;
  }

  createMoveDistribution(ground);

  directMove(ground);

  //check if some enemy is near.

}
Ejemplo n.º 3
0
void Copter::applySettings()
{directMove(_controlData);}
Ejemplo n.º 4
0
void Ant::goToNest(Ground& ground)
{
  //leave smell
  //  if (food)
  //  {
  ////    ground.makeSmell(x, y, id);
  //    ground.makeSmell(x, y, id, getDirectionFromDifferenceSigns(x - last_x, y - last_y));
  //  }

  Direction act_direction = getDirectionFromDifferenceSigns(nest_x - x, nest_y - y);
  if (move_distribution != nullptr)
  {
    delete move_distribution;
  }

  switch (act_direction)
  {
  case Direction::UL:
    move_distribution = new std::discrete_distribution<> ({2, 1, 0, 1, 0, 0, 0, 0});
    break;
  case Direction::UR:
    move_distribution = new std::discrete_distribution<> ({0, 1, 2, 0, 1, 0, 0, 0});
    break;
  case Direction::U:
    move_distribution = new std::discrete_distribution<> ({1, 2, 1, 0, 0, 0, 0, 0});
    break;
  case Direction::DL:
    move_distribution = new std::discrete_distribution<> ({0, 0, 0, 1, 0, 2, 1, 0});
    break;
  case Direction::DR:
    move_distribution = new std::discrete_distribution<> ({0, 0, 0, 0, 1, 0, 1, 2});
    break;
  case Direction::D:
    move_distribution = new std::discrete_distribution<> ({0, 0, 0, 0, 0, 1, 2, 1});
    break;
  case Direction::L:
    move_distribution = new std::discrete_distribution<> ({1, 0, 0, 2, 0, 1, 0, 0});
    break;
  case Direction::R:
    move_distribution = new std::discrete_distribution<> ({0, 0, 1, 0, 2, 0, 0, 1});
    break;
  case Direction::NO_DIRECTION:
    move_distribution = new std::discrete_distribution<> ({1, 1, 1, 1, 1, 1, 1, 1});
    break;
  }

  directMove(ground);

  if (make_path)
  {
    //    ground.makeSmell(x, y, id);
    ground.makeSmell(x, y, id, getDirectionFromDifferenceSigns(last_x - x, last_y - y));
  }

  //  //for now it's closest way
  //  if (x > nest_x && ground.checkifInGround(x - 1, y))
  //  {
  //    --x;
  //  }
  //  if (x < nest_x && ground.checkifInGround(x + 1, y))
  //  {
  //    ++x;
  //  }
  //
  //  if (y > nest_y && ground.checkifInGround(x, y - 1))
  //  {
  //    --y;
  //  }
  //  if (y < nest_y && ground.checkifInGround(x, y + 1))
  //  {
  //    ++y;
  //  }

}