Beispiel #1
0
int init(urg_t *urg){
	int error;
	int i;
	char *device = "/dev/ttyACM0";

	//SERIAL PORT DETECTION
	fprintf(stderr, "List of serial ports :\n");
	int found_port_size = urg_serial_find_port();
	if (found_port_size == 0) {
		fprintf(stderr, "could not found serial ports.\n");
		exit(EXIT_FAILURE);
	}
	for (i = 0; i < found_port_size; ++i) {
		fprintf(stderr, "%s", (char *)urg_serial_port_name(i));
		device = (char *)urg_serial_port_name(i);
	}
	fprintf(stderr, "\n");

	fprintf(stderr, "Connection à %s\n", device);
	error = urg_open(urg, URG_SERIAL, device, BAUDRATE);
	if(error < 0){
		error_func(urg, "connection failed");
	}
	else{
		fprintf(stderr, "Connection établie à %s\n", device);
		urg_set_scanning_parameter(urg, urg_rad2step(urg, ANGLE_MIN), urg_rad2step(urg, ANGLE_MAX), 0);//scan en continu, on ne garde que les point entre -PI/2 et PI/2
		fprintf(stderr, "Parameters set\n");
		error = urg_start_measurement(urg, URG_DISTANCE, URG_SCAN_INFINITY, 0);
		if(error < 0){
			error_func(urg, "failed to start measurement");
		}
	}
	get_val(calc, 0, urg);//calcule les tables de cos/sin à l'avance
	return error;
}
void LRF::OpenLRF(sensor_msgs::LaserScan &data)
{
  data.angle_min = deg_min*M_PI/180.0;
  data.angle_max = deg_max*M_PI/180.0;
  data.range_min = range_min;
  data.range_max = range_max;
  data.angle_increment = (skip+1)/1080.0*270.0*M_PI/180.0;
  
  step = (deg_max - deg_min)*4.0 + 1;
  data.ranges.resize(step);
  data.intensities.resize(step);
  
  if(eth_flg){
	if(urg_open(&urg,URG_ETHERNET,ip_address.c_str(),(long)ip_port) < 0){
	  ROS_WARN("Ethernet LRF open error.");
	  throw runtime_error("Ethernet LRF open error.");
	}
  }
  else{
	if(urg_open(&urg,URG_SERIAL,serial_port.c_str(),(long)serial_baud) < 0){
	  ROS_WARN("Serial LRF open error.");
	  throw runtime_error("Serial LRF open error.");
	}
  }
  
  urg_set_scanning_parameter(&urg, urg_deg2step(&urg,deg_min), urg_deg2step(&urg,deg_max), skip);

  if(publish_intensity)
    urg_start_measurement(&urg, URG_DISTANCE_INTENSITY, URG_SCAN_INFINITY, skip);
  else
    urg_start_measurement(&urg, URG_DISTANCE, URG_SCAN_INFINITY, skip);

}
Beispiel #3
0
int main(void)
{
const char connect_device[] = "/dev/ttyACM0";
const long connect_baudrate = 115200;
urg_t urg;
int first_step;
int last_step;
int skip_step;
int scan_times;
int skip_scan;
int ret;
// 計測パラメータの設定

// センサに対して接続を行う。
// 接続を行うと、計測パラメータの設定は初期化される
ret = urg_open(&urg, URG_SERIAL, connect_device, connect_baudrate);
// \todo check error code

// 計測範囲を指定する
// センサ正面方向の 90 [deg] 範囲のデータ取得を行い、ステップ間引きを行わない例
first_step = urg_rad2step(&urg, -45);
last_step = urg_rad2step(&urg, +45);
skip_step = 0;
ret = urg_set_scanning_parameter(&urg, first_step, last_step, skip_step);
// \todo check error code

// 計測回数と計測の間引きを指定して、計測を開始する
// 123 回の計測を指示し、スキャンの間引きを行わない例
scan_times = 123;
skip_scan = 0;
ret = urg_start_measurement(&urg, URG_DISTANCE, scan_times, skip_scan);
// \todo check error code
return 0;
}
Beispiel #4
0
int main(int argc, char *argv[])
{
    enum {
        CAPTURE_TIMES = 0,
    };
    urg_t urg;
    long *data = NULL;
    long time_stamp;
    int n;
    int i;

    if (open_urg_sensor(&urg, argc, argv) < 0) {
        return 1;
    }

    data = (long *)malloc(urg_max_data_size(&urg) * sizeof(data[0]));
    if (!data) {
        perror("urg_max_index()");
        return 1;
    }

    // \~japanese データ取得
#if 0
    // \~japanese データの取得範囲を変更する場合
    urg_set_scanning_parameter(&urg,
                               urg_deg2step(&urg, -90),
                               urg_deg2step(&urg, +90), 0);
#endif
int k;
for (k = 0; k < 3; k++) {
    urg_start_measurement(&urg, URG_DISTANCE, CAPTURE_TIMES, 0);
    for (i = 0; i < 25; ++i) {
        n = urg_get_distance(&urg, data, &time_stamp);
        if (n <= 0) {
            printf("urg_get_distance: %s\n", urg_error(&urg));
            free(data);
            urg_close(&urg);
            return 1;
        }
        print_data(&urg, data, n, time_stamp);
    }
	urg_stop_measurement(&urg);
	sleep(10);
}
    // \~japanese 切断
    free(data);
    urg_close(&urg);

#if defined(URG_MSC)
    getchar();
#endif
    return 0;
}
int main(int argc, char *argv[]){
    enum {
      CAPTURE_TIMES = 1, //modificat_numarul_de_afisari_ale_citirii
    };
    urg_t urg;
    long *data = NULL;
    long time_stamp;
    int n;
    int i;
    
    if (open_urg_sensor(&urg, argc, argv) < 0) {
        return 1;
    }

    data = (long *)malloc(urg_max_data_size(&urg) * sizeof(data[0]));
    if (!data) {
        perror("1urg_max_index()");
        return 1;
    }

    // \~japanese データ取得
#if 0
    // \~japanese データの取得範囲を変更する場合
    urg_set_scanning_parameter(&urg,
                               urg_deg2step(&urg, -90),
                               urg_deg2step(&urg, +90), 0);
#endif

    urg_start_measurement(&urg, URG_DISTANCE, URG_SCAN_INFINITY, 0);
    for (i = 0; i < CAPTURE_TIMES; ++i) {
        n = urg_get_distance(&urg, data, &time_stamp);
        if (n <= 0) {
            printf("urg_get_distance: %s\n", urg_error(&urg));
            free(data);
            urg_close(&urg);
            return 1;
        }
        print_data(&urg, data, n, time_stamp);
	
    }

    // \~japanese 切断
    free(data);
    urg_close(&urg);

#if defined(URG_MSC)
    getchar();
#endif
    return 0;
}
bool openSensor(void * params)
{
	URGPARAMS * tempparams=(URGPARAMS *)params;
	int n=urg_open(&(tempparams->urg),tempparams->connection_type,tempparams->device_or_address.toStdString().c_str(),tempparams->baudreate_or_port);
	if(n<0)
	{
		return 0;
	}
	n=urg_set_scanning_parameter(&(tempparams->urg),tempparams->first_step,tempparams->last_step,tempparams->skip_step);
	if(n<0)
	{
		return 0;
	}
	return 1;
}
bool openSensor(void * params, QObject ** trigger, QString & triggersignal)	//open the sensor using params
{
	URGSENSORPARAMS * URGparams=(URGSENSORPARAMS *)params;
	int n=urg_open(&(URGparams->urg),URGparams->connection_type,URGparams->device_or_address.toStdString().c_str(),URGparams->baudreate_or_port);
	if(n<0)
	{
		return 0;
	}
	n=urg_set_scanning_parameter(&(URGparams->urg),URGparams->first_step,URGparams->last_step,URGparams->skip_step);
	if(n<0)
	{
		return 0;
	}
	return 1;
}