|
From: <gb...@us...> - 2010-08-16 02:23:00
|
Revision: 514
http://gearbox.svn.sourceforge.net/gearbox/?rev=514&view=rev
Author: gbiggs
Date: 2010-08-16 02:22:54 +0000 (Mon, 16 Aug 2010)
Log Message:
-----------
Changed pointer to reference
Modified Paths:
--------------
gearbox/trunk/src/hokuyo_aist/getid/getid.cpp
gearbox/trunk/src/hokuyo_aist/sensor.cpp
gearbox/trunk/src/hokuyo_aist/sensor.h
gearbox/trunk/src/hokuyo_aist/test/example.cpp
Modified: gearbox/trunk/src/hokuyo_aist/getid/getid.cpp
===================================================================
--- gearbox/trunk/src/hokuyo_aist/getid/getid.cpp 2010-08-16 02:09:25 UTC (rev 513)
+++ gearbox/trunk/src/hokuyo_aist/getid/getid.cpp 2010-08-16 02:22:54 UTC (rev 514)
@@ -63,24 +63,24 @@
// Set the laser to verbose mode (so we see more information in the
// console)
if(verbose)
- laser.set_verbose (true);
+ laser.set_verbose(true);
// Open the laser
- laser.open (port_options);
+ laser.open(port_options);
// Turn the laser on
- laser.set_power (true);
+ laser.set_power(true);
// Get some laser info
hokuyo_aist::SensorInfo info;
- laser.get_sensor_info (&info);
+ laser.get_sensor_info(info);
std::cout << info.serial << '\n';
// Close the laser
- laser.close ();
+ laser.close();
}
catch(hokuyo_aist::BaseError &e)
{
- std::cerr << "Caught exception: " << e.what () << '\n';
+ std::cerr << "Caught exception: " << e.what() << '\n';
return 1;
}
Modified: gearbox/trunk/src/hokuyo_aist/sensor.cpp
===================================================================
--- gearbox/trunk/src/hokuyo_aist/sensor.cpp 2010-08-16 02:09:25 UTC (rev 513)
+++ gearbox/trunk/src/hokuyo_aist/sensor.cpp 2010-08-16 02:22:54 UTC (rev 514)
@@ -664,11 +664,8 @@
}
-void Sensor::get_sensor_info(SensorInfo* info)
+void Sensor::get_sensor_info(SensorInfo& info)
{
- if(info == 0)
- throw NoDestinationError();
-
if(scip_version_ == 1)
{
if(verbose_)
@@ -677,7 +674,7 @@
"() Getting sensor information using SCIP version 1.\n";
}
- info->set_defaults();
+ info.set_defaults();
char buffer[SCIP1_LINE_LENGTH];
memset(buffer, 0, sizeof(char) * SCIP1_LINE_LENGTH);
@@ -685,27 +682,27 @@
send_command("V", 0, 0, 0);
// Get the vendor info line
read_line(buffer);
- info->vendor = &buffer[5]; // Chop off the "VEND:" tag
+ info.vendor = &buffer[5]; // Chop off the "VEND:" tag
// Get the product info line
read_line(buffer);
- info->product = &buffer[5];
+ info.product = &buffer[5];
// Only the URG-04LX supports SCIP1
model_ = MODEL_URG04LX;
// Get the firmware line
read_line(buffer);
- info->firmware = &buffer[5];
+ info.firmware = &buffer[5];
// Get the protocol version line
read_line(buffer);
- info->protocol = &buffer[5];
+ info.protocol = &buffer[5];
// Get the serial number
read_line(buffer);
- info->serial = &buffer[5];
+ info.serial = &buffer[5];
// Get either the status line or the end of message
read_line(buffer);
if(buffer[0] != '\0')
{
// Got a status line
- info->sensor_diagnostic = &buffer[5];
+ info.sensor_diagnostic = &buffer[5];
skip_lines(1);
}
@@ -714,60 +711,60 @@
// eg: FIRM:3.1.04,07/08/02(20-4095[mm],240[deg],44-725[step],600[rpm])
// Note that this example is right up against the maximum SCIP v1 line
// length of 64 bytes.
- if(atoi(info->firmware.c_str()) >= 3)
+ if(atoi(info.firmware.c_str()) >= 3)
{
if(verbose_)
err_output_ << "SCIP1 Firmware line for parsing: " <<
- info->firmware << '\n';
+ info.firmware << '\n';
// Now the fun part: parsing the line. It would be nice if we could
// use the POSIX regex functions, but since MS doesn't believe in
// POSIX we get to do it the hard way.
// Start by finding the first (
char const* valueStart;
- if((valueStart = strchr(info->firmware.c_str(), '(')) == 0)
+ if((valueStart = strchr(info.firmware.c_str(), '(')) == 0)
{
// No bracket? Crud. Fail and use the hard-coded values from
// the manual.
- info->calculate_values();
+ info.calculate_values();
}
// Now put it through sscanf and hope...
int aperture;
int numFound = sscanf(valueStart,
- "(%d-%d[mm],%d[deg],%d-%d[step],%d[rpm]", &info->min_range,
- &info->max_range, &aperture, &info->first_step,
- &info->last_step, &info->speed);
+ "(%d-%d[mm],%d[deg],%d-%d[step],%d[rpm]", &info.min_range,
+ &info.max_range, &aperture, &info.first_step,
+ &info.last_step, &info.speed);
if(numFound != 6)
{
// Didn't get enough values out, assume unknown format and fall
// back on the defaults
- info->set_defaults();
- info->calculate_values();
+ info.set_defaults();
+ info.calculate_values();
if(verbose_)
{
err_output_ << "Retrieved sensor info (hard-coded, not "
"enough values):\n";
- err_output_ << info->as_string();
+ err_output_ << info.as_string();
}
}
else
{
// Need to calculate stuff differently since it gave us an
// aperture value
- info->resolution = DTOR(static_cast<double>(aperture)) /
- static_cast<double>(info->last_step - info->first_step);
+ info.resolution = DTOR(static_cast<double>(aperture)) /
+ static_cast<double>(info.last_step - info.first_step);
// Assume that the range is evenly spread
- info->scanable_steps = info->last_step - info->first_step + 1;
- info->front_step = info->scanable_steps / 2 +
- info->first_step - 1;
- info->min_angle = (static_cast<int>(info->first_step) -
- static_cast<int>(info->front_step)) * info->resolution;
- info->max_angle = (info->last_step - info->front_step) *
- info->resolution;
+ info.scanable_steps = info.last_step - info.first_step + 1;
+ info.front_step = info.scanable_steps / 2 +
+ info.first_step - 1;
+ info.min_angle = (static_cast<int>(info.first_step) -
+ static_cast<int>(info.front_step)) * info.resolution;
+ info.max_angle = (info.last_step - info.front_step) *
+ info.resolution;
if(verbose_)
{
err_output_ << "Retrieved sensor info (from FIRM line):\n";
- err_output_ << info->as_string();
+ err_output_ << info.as_string();
}
}
}
@@ -775,11 +772,11 @@
{
// We're stuck with hard-coded defaults from the manual (already
// set earlier).
- info->calculate_values();
+ info.calculate_values();
if(verbose_)
{
err_output_ << "Retrieved sensor info (hard-coded):\n";
- err_output_ << info->as_string();
+ err_output_ << info.as_string();
}
}
}
@@ -791,7 +788,7 @@
"() Getting sensor information using SCIP version 2.\n";
}
- info->set_defaults();
+ info.set_defaults();
char buffer[SCIP2_LINE_LENGTH];
memset(buffer, 0, sizeof(char) * SCIP2_LINE_LENGTH);
@@ -814,11 +811,11 @@
enable_checksum_workaround_ = false;
- info->calculate_values();
+ info.calculate_values();
if(verbose_)
{
err_output_ << "Retrieved sensor info:\n";
- err_output_ << info->as_string();
+ err_output_ << info.as_string();
}
}
else
@@ -1957,7 +1954,7 @@
// Get the laser's info
SensorInfo info;
- get_sensor_info(&info);
+ get_sensor_info(info);
min_angle_ = info.min_angle;
max_angle_ = info.max_angle;
@@ -1976,62 +1973,62 @@
}
-void Sensor::process_vv_line(char const* buffer, SensorInfo* info)
+void Sensor::process_vv_line(char const* buffer, SensorInfo& info)
{
if(strncmp(buffer, "VEND", 4) == 0)
- info->vendor = &buffer[5]; // Vendor info, minus the "VEND:" tag
+ info.vendor = &buffer[5]; // Vendor info, minus the "VEND:" tag
else if(strncmp(buffer, "PROD", 4) == 0)
{
- info->product = &buffer[5]; // Product info
+ info.product = &buffer[5]; // Product info
// Find the product model
find_model(&buffer[5]);
- info->detected_model = model_;
+ info.detected_model = model_;
}
else if(strncmp(buffer, "FIRM", 4) == 0)
- info->firmware = &buffer[5]; // Firmware version
+ info.firmware = &buffer[5]; // Firmware version
else if(strncmp(buffer, "PROT", 4) == 0)
- info->protocol = &buffer[5]; // Protocol version
+ info.protocol = &buffer[5]; // Protocol version
else if(strncmp(buffer, "SERI", 4) == 0)
- info->serial = &buffer[5]; // Serial number
+ info.serial = &buffer[5]; // Serial number
else if(!ignore_unknowns_)
throw UnknownLineError(buffer);
}
-void Sensor::process_pp_line(char const* buffer, SensorInfo* info)
+void Sensor::process_pp_line(char const* buffer, SensorInfo& info)
{
if(strncmp(buffer, "MODL", 4) == 0)
- info->model = &buffer[5]; // Model
+ info.model = &buffer[5]; // Model
// On to the fun ones that require parsing
else if(strncmp(buffer, "DMIN", 4) == 0)
- info->min_range = atoi(&buffer[5]);
+ info.min_range = atoi(&buffer[5]);
else if(strncmp(buffer, "DMAX", 4) == 0)
- info->max_range = atoi(&buffer[5]);
+ info.max_range = atoi(&buffer[5]);
else if(strncmp(buffer, "ARES", 4) == 0)
- info->steps = atoi(&buffer[5]);
+ info.steps = atoi(&buffer[5]);
else if(strncmp(buffer, "AMIN", 4) == 0)
- info->first_step = atoi(&buffer[5]);
+ info.first_step = atoi(&buffer[5]);
else if(strncmp(buffer, "AMAX", 4) == 0)
- info->last_step = atoi(&buffer[5]);
+ info.last_step = atoi(&buffer[5]);
else if(strncmp(buffer, "AFRT", 4) == 0)
- info->front_step = atoi(&buffer[5]);
+ info.front_step = atoi(&buffer[5]);
else if(strncmp(buffer, "SCAN", 4) == 0)
- info->standard_speed = atoi(&buffer[5]);
+ info.standard_speed = atoi(&buffer[5]);
/* No example in the manual and sensor with support for this has not
* arrived yet, so don't know what to look for.
else if(strncmp(buffer, "", 4) == 0)
{
if(strstr(buffer, "CCW") != 0)
- info->rot_dir = COUNTERCLOCKWISE;
+ info.rot_dir = COUNTERCLOCKWISE;
else
- info->rot_dir = CLOCKWISE;
+ info.rot_dir = CLOCKWISE;
}*/
else if(!ignore_unknowns_)
throw UnknownLineError(buffer);
}
-void Sensor::process_ii_line(char const* buffer, SensorInfo* info)
+void Sensor::process_ii_line(char const* buffer, SensorInfo& info)
{
if(strncmp(buffer, "MODL", 4) == 0)
// Do nothing here - we already know this value from PP
@@ -2039,54 +2036,54 @@
else if(strncmp(buffer, "LASR", 4) == 0)
{
if(strncmp(&buffer[5], "OFF", 3) == 0)
- info->power = false;
+ info.power = false;
else
- info->power = true;
+ info.power = true;
}
else if(strncmp(buffer, "SCSP", 4) == 0)
{
if(strncmp(&buffer[5], "Initial", 7) == 0)
{
// Unchanged motor speed
- if(sscanf(buffer, "SCSP:%*7s(%d[rpm]", &info->speed) != 1)
+ if(sscanf(buffer, "SCSP:%*7s(%d[rpm]", &info.speed) != 1)
{
throw ParseError(buffer, "Motor speed");
}
- info->speed_level = 0;
- time_resolution_ = info->speed;
+ info.speed_level = 0;
+ time_resolution_ = info.speed;
}
else
{
// Changed motor speed, format is:
// <level>%<ignored string>(<speed>[rpm])
- if(sscanf(buffer, "SCSP:%hd%%%*4s(%d[rpm]", &info->speed_level,
- &info->speed) != 2)
+ if(sscanf(buffer, "SCSP:%hd%%%*4s(%d[rpm]", &info.speed_level,
+ &info.speed) != 2)
{
throw ParseError(buffer, "Motor speed");
}
- time_resolution_ = info->speed;
+ time_resolution_ = info.speed;
}
}
else if(strncmp(buffer, "MESM", 4) == 0)
- info->measure_state = &buffer[5];
+ info.measure_state = &buffer[5];
else if(strncmp(buffer, "SBPS", 4) == 0)
{
if(strncmp(&buffer[5], "USB only", 8) == 0 ||
strncmp(&buffer[5], "USB Full Speed", 14) == 0)
{
// No baud rate for USB-only devices such as the UHG-08LX
- info->baud = 0;
+ info.baud = 0;
}
- else if(sscanf(buffer, "SBPS:%d[bps]", &info->baud) != 1)
+ else if(sscanf(buffer, "SBPS:%d[bps]", &info.baud) != 1)
throw ParseError(buffer, "Baud rate");
}
else if(strncmp(buffer, "TIME", 4) == 0)
{
- if(sscanf(buffer, "TIME:%x", &info->time) != 1)
+ if(sscanf(buffer, "TIME:%x", &info.time) != 1)
throw ParseError(buffer, "Timestamp");
}
else if(strncmp(buffer, "STAT", 4) == 0)
- info->sensor_diagnostic = &buffer[5];
+ info.sensor_diagnostic = &buffer[5];
else if(!ignore_unknowns_)
throw UnknownLineError(buffer);
}
Modified: gearbox/trunk/src/hokuyo_aist/sensor.h
===================================================================
--- gearbox/trunk/src/hokuyo_aist/sensor.h 2010-08-16 02:09:25 UTC (rev 513)
+++ gearbox/trunk/src/hokuyo_aist/sensor.h 2010-08-16 02:22:54 UTC (rev 514)
@@ -20,7 +20,6 @@
#ifndef SENSOR_H__
#define SENSOR_H__
-#include <flexiport/port.h>
#include <string>
#if defined(WIN32)
@@ -38,6 +37,11 @@
#define HOKUYO_AIST_EXPORT
#endif
+namespace flexiport
+{
+ class Port;
+}
+
/** @ingroup gbx_library_hokuyo_aist
@{
*/
@@ -189,7 +193,7 @@
/** @brief Get various information about the scanner.
Much of the information is not available with the SCIP v1 protocol. */
- void get_sensor_info(SensorInfo* info);
+ void get_sensor_info(SensorInfo& info);
/** @brief Get the value of the scanner's clock in milliseconds.
@@ -535,9 +539,9 @@
void find_model(char const* buffer);
void get_and_set_scip_version();
void get_defaults();
- void process_vv_line(char const* buffer, SensorInfo* info);
- void process_pp_line(char const* buffer, SensorInfo* info);
- void process_ii_line(char const* buffer, SensorInfo* info);
+ void process_vv_line(char const* buffer, SensorInfo& info);
+ void process_pp_line(char const* buffer, SensorInfo& info);
+ void process_ii_line(char const* buffer, SensorInfo& info);
uint32_t process_echo_buffer(int const* buffer, int num_echos);
void read_2_byte_range_data(ScanData& data, unsigned int num_steps);
Modified: gearbox/trunk/src/hokuyo_aist/test/example.cpp
===================================================================
--- gearbox/trunk/src/hokuyo_aist/test/example.cpp 2010-08-16 02:09:25 UTC (rev 513)
+++ gearbox/trunk/src/hokuyo_aist/test/example.cpp 2010-08-16 02:22:54 UTC (rev 514)
@@ -171,7 +171,7 @@
// Get some laser info
std::cout << "Laser sensor information:\n";
hokuyo_aist::SensorInfo info;
- laser.get_sensor_info(&info);
+ laser.get_sensor_info(info);
std::cout << info.as_string();
// Get range data
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|