コード例 #1
0
ファイル: sonarDeviceTest.cpp プロジェクト: sauver/sauver_sys
void sonarPrinter(void)
{
  ArSonarDevice *sd;
  
  std::list<ArPoseWithTime *>::iterator it;
  std::list<ArPoseWithTime *> *readings;
  ArPose *pose;

  sd = (ArSonarDevice *)robot->findRangeDevice("sonar");
  if (sd != NULL)
  {
    sd->lockDevice();
    readings = sd->getCurrentBuffer();
    if (readings != NULL)
    {
      for (it = readings->begin(); it != readings->end(); ++it)
      {
	pose = (*it);
	//pose->log();
      }
    }
    sd->unlockDevice();
  }

  double d;
  double th;
  int i;
	
  printf("Closest readings within polar sections:\n");

  d = sonar.currentReadingPolar(-45, 45, &th);
  printf(" front quadrant: %5.0f  ", d);
  if (d != 5000)
    printf("%3.0f ", th);
  printf("\n");

  d = sonar.currentReadingPolar(-135, -45, &th);
  printf(" right quadrant: %5.0f ", d);
  if (d != 5000)
    printf("%3.0f ", th);
  printf("\n");

  d = sonar.currentReadingPolar(45, 135, &th);
  printf(" left quadrant: %5.0f ", d);
  if (d != 5000)
    printf("%3.0f ", th);
  printf("\n");

  d = sonar.currentReadingPolar(-135, 135, &th);
  printf(" back quadrant: %5.0f ", d);
  if (d != 5000)
    printf("%3.0f ", th);
  printf("\n");

  fflush(stdout);
}
コード例 #2
0
int RosAriaNode::Setup()
{
	ArArgumentBuilder *args;

	args = new ArArgumentBuilder();
	args->add("-rp"); //pass robot's serial port to Aria
	args->add(serial_port.c_str());
	conn = new ArSimpleConnector(args);


	robot = new ArRobot();
	robot->setCycleTime(1);

	ArLog::init(ArLog::File, ArLog::Verbose, "aria.log", true);

	//parse all command-line arguments
	if (!Aria::parseArgs())
	{
		Aria::logOptions();
		return 1;
	}

	// Connect to the robot
	if (!conn->connectRobot(robot)) {
		ArLog::log(ArLog::Terse, "rotate: Could not connect to robot! Exiting.");
		return 1;
	}

	//Sonar sensor
	sonar.setMaxRange(Max_Range);
	robot->addRangeDevice(&sonar);
	robot->enableSonar();

	// Enable the motors
	robot->enableMotors();

	robot->runAsync(true);

	return 0;
}
コード例 #3
0
void sonarPrinter(void)
{
  double d;
  double th;
	

  d = sonar.currentReadingPolar(-45, 45, &th);
  printf("front: %5.0fmm ", d);
  if (d != sonar.getMaxRange())
    printf("%3.0fdeg ", th);
  else
    printf("???deg ");

  d = sonar.currentReadingPolar(-135, -45, &th);
  printf(" right: %5.0fmm ", d);
  if (d != sonar.getMaxRange())
    printf("%3.0fdeg ", th);
  else
    printf("???deg ");

  d = sonar.currentReadingPolar(45, 135, &th);
  printf(" left: %5.0fmm ", d);
  if (d != sonar.getMaxRange())
    printf("%3.0fdeg ", th);
  else
    printf("???deg ");

  d = sonar.currentReadingPolar(135, -135, &th);
  printf(" back: %5.0fmm ", d);
  if (d != sonar.getMaxRange())
    printf("%3.0fdeg ", th);
  else
    printf("???deg ");

  printf("\r");
  fflush(stdout);
}
コード例 #4
0
void RosAriaNode::cmdvel_cb( const geometry_msgs::PointStampedConstPtr &msg)
{
	veltime = ros::Time::now();
	//get data from Package
	Vsd =ceil(msg->point.x); //Vsd = Xm/Scale
	Vm=msg->point.y;		// Vm
	fk = msg->point.z;

	//real velocity
	Vs = ceil(robot->getVel());
	//Distance from obstacle
	distance = sonar.currentReadingPolar(-30,30);

	//Environment force
	if (distance<Min_Range)
		fe = -Max_Force;
	else if (distance<Max_Range)
		fe = -Ke*1/distance;
	else
		fe=0;
	//Virtual force
	fs = (Vsd-Vs)/50;

	/*
	 * Xm chanel
	 */

	//PO
	if (fs*Vsd>0)
	{
		//do nothing
		slaE_N_Xm-=fs*Vsd; //output
	}
	else
	{
		//slaE_N_Xm+=fs*Vsd; //output
	}

	//ROS_INFO("Slave Energy: %5f",slaE_N_Xm);
	//fprintf(Energy,"%.3f \n",slaE_N_Xm);
	//PC
#if 1
	if (slaE_N_Xm+mstE_P_Xm<0) //input + output<0 =>active
	{
		//modify Vsd
		slaE_N_Xm+=fs*Vsd;
		Vsd = (slaE_N_Xm+mstE_P_Xm)/fs;
		slaE_N_Xm-=fs*Vsd;
		ROS_INFO("Modified Vs");
	}
#endif

	/*
	 * fe chanel
	 */

	if (fe*Vm>0)
	{
		slaE_P_fe+=fe*Vm;
	}
	else
	{
		//do nothing
	}

	//fprintf(Energy,"%.3f \n",slaE_P_fe);
	/*
	 * fk chanel
	 */

	if (fk*Vs>0)
	{
	//	slaE_P_fk+=fk*Vs;
	}
	else
	{
		slaE_P_fk-=fk*Vs;
		//do nothing
	}

	fprintf(Energy,"%.3f \n",slaE_P_fk);
//	ROS_INFO("Slave Energy: %5f",slaE_P_fk);
	//ROS_INFO("Set velocity: %5f",Vsd);
	//ROS_INFO("Real velocity: %5f",Vs);
	//ROS_INFO("Force: %5f",fe);

	robot->setVel(Vsd);

	//Package and publish

	chanelParameter.point.x = Vs;
	chanelParameter.point.y = fs;
	chanelParameter.point.z = fe;

	chanelEnergy.point.x = slaE_P_fe;
	chanelEnergy.point.y = slaE_P_fk;

	chanelParameter_Pub.publish(chanelParameter);
	chanelEnergy_Pub.publish(chanelEnergy);

	fprintf(Vs_save,"%.3f \n",Vs);
	fprintf(Vsd_save,"%.3f \n",Vsd);
}
コード例 #5
0
ファイル: sonarPioneerReader.cpp プロジェクト: 976717326/visp
void sonarPrinter(void)
{
  fprintf(stdout, "in sonarPrinter()\n"); fflush(stdout);
  double scale = (double)half_size / (double)sonar.getMaxRange();

  /*
  ArSonarDevice *sd;

  std::list<ArPoseWithTime *>::iterator it;
  std::list<ArPoseWithTime *> *readings;
  ArPose *pose;

  sd = (ArSonarDevice *)robot->findRangeDevice("sonar");
  if (sd != NULL)
  {
    sd->lockDevice();
    readings = sd->getCurrentBuffer();
    if (readings != NULL)
    {
      for (it = readings->begin(); it != readings->end(); ++it)
      {
        pose = (*it);
        //pose->log();
      }
    }
    sd->unlockDevice();
  }
*/
  double range;
  double angle;

  /*
   * example to show how to find closest readings within polar sections
   */
  printf("Closest readings within polar sections:\n");

  double start_angle = -45;
  double end_angle = 45;
  range = sonar.currentReadingPolar(start_angle, end_angle, &angle);
  printf(" front quadrant: %5.0f  ", range);
  //if (range != sonar.getMaxRange())
  if (std::fabs(range - sonar.getMaxRange()) > std::numeric_limits<double>::epsilon())
    printf("%3.0f ", angle);
  printf("\n");
#if defined(VISP_HAVE_X11) || defined (VISP_HAVE_GDI)
  //if (isInitialized && range != sonar.getMaxRange())
  if (isInitialized && std::fabs(range - sonar.getMaxRange()) > std::numeric_limits<double>::epsilon())
  {
    double x = range * cos(vpMath::rad(angle)); // position of the obstacle in the sensor frame
    double y = range * sin(vpMath::rad(angle));

    // Conversion in pixels so that the robot frame is in the middle of the image
    double j = -y * scale + half_size; // obstacle position
    double i = -x * scale + half_size;

    vpDisplay::display(I);
    vpDisplay::displayLine(I, half_size, half_size, 0, 0, vpColor::red, 5);
    vpDisplay::displayLine(I, half_size, half_size, 0, 2*half_size-1, vpColor::red, 5);
    vpDisplay::displayLine(I, half_size, half_size, i, j, vpColor::green, 3);
    vpDisplay::displayCross(I, i, j, 7, vpColor::blue);
  }
#endif

  range = sonar.currentReadingPolar(-135, -45, &angle);
  printf(" right quadrant: %5.0f ", range);
  //if (range != sonar.getMaxRange())
  if (std::fabs(range - sonar.getMaxRange()) > std::numeric_limits<double>::epsilon())
    printf("%3.0f ", angle);
  printf("\n");

  range = sonar.currentReadingPolar(45, 135, &angle);
  printf(" left quadrant: %5.0f ", range);
  //if (range != sonar.getMaxRange())
  if (std::fabs(range - sonar.getMaxRange()) > std::numeric_limits<double>::epsilon())
    printf("%3.0f ", angle);
  printf("\n");

  range = sonar.currentReadingPolar(-135, 135, &angle);
  printf(" back quadrant: %5.0f ", range);
  //if (range != sonar.getMaxRange())
  if (std::fabs(range - sonar.getMaxRange()) > std::numeric_limits<double>::epsilon())
    printf("%3.0f ", angle);
  printf("\n");

  /*
   * example to show how get all sonar sensor data
   */
  ArSensorReading *reading;
  for (int sensor = 0; sensor < robot->getNumSonar(); sensor++)
  {
    reading = robot->getSonarReading(sensor);
    if (reading != NULL)
    {
      angle = reading->getSensorTh();
      range = reading->getRange();
      double sx = reading->getSensorX(); // position of the sensor in the robot frame
      double sy = reading->getSensorY();
      double ox = range * cos(vpMath::rad(angle)); // position of the obstacle in the sensor frame
      double oy = range * sin(vpMath::rad(angle));
      double x = sx + ox; // position of the obstacle in the robot frame
      double y = sy + oy;

      // Conversion in pixels so that the robot frame is in the middle of the image
      double sj = -sy * scale + half_size; // sensor position
      double si = -sx * scale + half_size;
      double j = -y * scale + half_size; // obstacle position
      double i = -x * scale + half_size;

      //      printf("%d x: %.1f y: %.1f th: %.1f d: %d\n", sensor, reading->getSensorX(),
      //             reading->getSensorY(), reading->getSensorTh(), reading->getRange());

#if defined(VISP_HAVE_X11) || defined (VISP_HAVE_GDI)
      //if (isInitialized && range != sonar.getMaxRange())
      if (isInitialized && std::fabs(range - sonar.getMaxRange()) > std::numeric_limits<double>::epsilon())
      {
        vpDisplay::displayLine(I, si, sj, i, j, vpColor::blue, 2);
        vpDisplay::displayCross(I, si, sj, 7, vpColor::blue);
        char legend[15];
        sprintf(legend, "%d: %1.2fm", sensor, float(range)/1000);
        vpDisplay::displayCharString(I, i-7, j+7, legend, vpColor::blue);
      }
#endif
    }

  }

#if defined(VISP_HAVE_X11) || defined (VISP_HAVE_GDI)
  if (isInitialized)
    vpDisplay::flush(I);
#endif

  fflush(stdout);
}