Class for controlling Nav2 via turtle interface. More...
#include <nav2remote.h>
Public Member Functions | |
int | back (double dist) |
Move backward. | |
int | estimatePosition (double &x, double &y, double &orientation) const |
Estimate the position and orientation. | |
int | forward (double dist) |
Move forward. | |
double | getMaxAccel () const |
Get the maximum acceleration for turtle commands. | |
double | getMaxCorneringError () const |
Get the maximum cornering error for turtle commands. | |
double | getMaxSpeed () const |
Get the maximum speed for turtle commands. | |
int | getQueueSize () const |
Get the turtle command queue size. | |
int | move (double dist, double direction) |
Move in a specified direction. | |
Nav2Remote (const char *host, int port=5010) | |
Create the Nav2Remote object. | |
int | setAbsoluteVelocity (double vx, double vy) |
Set the velocity in absolute coordinates. | |
int | setMaxAccel (double maxAccel) |
Set the maximum acceleration for turtle commands. | |
int | setMaxCorneringError (double error) |
Set the maximum cornering error for turtle commands. | |
int | setMaxSpeed (double maxSpeed) |
Set the maximum speed for turtle commands. | |
int | setPosition (double x, double y, double orientation) |
Set the current actual position and orientation. | |
int | setRelativeVelocity (double vx, double vy, double turnRate=0.0) |
Set the relative velocity and turn rate. | |
int | setTargetOrientation (double orientation) |
Set the target orientation in world coordinates. | |
int | stop () |
Stop the robot immediately. | |
int | turnLeft (double angle) |
Turn left. | |
int | turnRight (double angle) |
Turn right. | |
int | wait () const |
Wait until the turtle command queue is empty. | |
~Nav2Remote () | |
Private Member Functions | |
Nav2Remote (const Nav2Remote &) | |
Nav2Remote & | operator= (const Nav2Remote &) |
int | readLine () const |
Private Attributes | |
int | fd |
char * | line |
int | lineLen |
Class for controlling Nav2 via turtle interface.
This class is a C++ front-end for Crosswing's serial turtle interface. This interface is not thread-safe. Most of these functions block on I/O.
Note that the turtle commands run asynchronously. Each command is added to the robot's path plan, and the function returns immediately. Call getQueueSize() to determine whether the robot has completed the requested path. Call wait() to wait until the queue is empty.
When this object goes out of scope (eg, when the program finishes), the robot will stop immediately, even if there are commands in the queue. Use wait() if you want to ensure that the path completes.
Definition at line 27 of file nav2remote.h.
Nav2Remote::Nav2Remote | ( | const Nav2Remote & | ) | [private] |
Nav2Remote::Nav2Remote | ( | const char * | host, |
int | port = 5010 |
||
) |
Create the Nav2Remote object.
Constructs the object and connects to a remote turtle interface. If there is a connection problem, this function throws std::runtime_error.
host | The remote hostname or IP address. |
port | The TCP port. |
Definition at line 18 of file nav2remote.cpp.
Definition at line 50 of file nav2remote.cpp.
int Nav2Remote::back | ( | double | dist | ) | [inline] |
Move backward.
Queue a turtle command to move the robot backward by the specified distance. This is equivalent to move(-dist,0.0).
dist | The distance in meters. |
Definition at line 192 of file nav2remote.h.
int Nav2Remote::estimatePosition | ( | double & | x, |
double & | y, | ||
double & | orientation | ||
) | const |
Estimate the position and orientation.
x | Output parameter for the estimated x coordinate in meters. |
y | Output parameter for the estimated y coordinate in meters. |
orientation | Output parameter for the estimated orientation in radians. |
Definition at line 106 of file nav2remote.cpp.
int Nav2Remote::forward | ( | double | dist | ) | [inline] |
Move forward.
Queue a turtle command to move the robot forward by the specified distance. This is equivalent to move(dist,0.0).
dist | The distance in meters. |
Definition at line 181 of file nav2remote.h.
double Nav2Remote::getMaxAccel | ( | ) | const |
Get the maximum acceleration for turtle commands.
Definition at line 181 of file nav2remote.cpp.
double Nav2Remote::getMaxCorneringError | ( | ) | const |
Get the maximum cornering error for turtle commands.
Definition at line 194 of file nav2remote.cpp.
double Nav2Remote::getMaxSpeed | ( | ) | const |
Get the maximum speed for turtle commands.
Definition at line 168 of file nav2remote.cpp.
int Nav2Remote::getQueueSize | ( | ) | const |
Get the turtle command queue size.
Get the number of turtle line segments remaining in the queue.
Definition at line 207 of file nav2remote.cpp.
int Nav2Remote::move | ( | double | dist, |
double | direction | ||
) |
Move in a specified direction.
Queue a turtle command to move a specified distance in the specified direction (relative to the robot's heading).
dist | The distance in meters. |
direction | The relative direction of travel in radians. Positive values are to the robot's left; Negative values are to the robot's right. |
Definition at line 140 of file nav2remote.cpp.
Nav2Remote& Nav2Remote::operator= | ( | const Nav2Remote & | ) | [private] |
int Nav2Remote::readLine | ( | ) | const [private] |
Definition at line 56 of file nav2remote.cpp.
int Nav2Remote::setAbsoluteVelocity | ( | double | vx, |
double | vy | ||
) |
Set the velocity in absolute coordinates.
Set the robot's velocity in absolute coordinates. This function overrides and clears the turtle command queue.
vx | The x-component of the velocity in meters per second. |
vy | The y-component of the velocity in meters per second. |
Definition at line 92 of file nav2remote.cpp.
int Nav2Remote::setMaxAccel | ( | double | maxAccel | ) |
Set the maximum acceleration for turtle commands.
This does not affect the behaviour of setTargetVelocity().
maxAccel | The maximum acceleration in meters per second squared. |
Definition at line 154 of file nav2remote.cpp.
int Nav2Remote::setMaxCorneringError | ( | double | error | ) |
Set the maximum cornering error for turtle commands.
When following turtle commands, the robot will plan to come at least that near to each corner in the resulting path. If this value is set to 0, the robot will come to a complete stop at each corner. Setting this to larger values allows the robot to follow the path at a higher speed.
error | The maximum cornering error in meters. |
Definition at line 161 of file nav2remote.cpp.
int Nav2Remote::setMaxSpeed | ( | double | maxSpeed | ) |
Set the maximum speed for turtle commands.
This does not affect the behaviour of setTargetVelocity().
maxSpeed | The maximum speed in meters per second. |
Definition at line 147 of file nav2remote.cpp.
int Nav2Remote::setPosition | ( | double | x, |
double | y, | ||
double | orientation | ||
) |
Set the current actual position and orientation.
The provided values will be used as ground truth for future estimates.
x | The absolute x coordinate in meters. |
y | The absolute y coordinate in meters. |
orientation | The absolute orientation in radians. |
Definition at line 121 of file nav2remote.cpp.
int Nav2Remote::setRelativeVelocity | ( | double | vx, |
double | vy, | ||
double | turnRate = 0.0 |
||
) |
Set the relative velocity and turn rate.
Set the robot's velocity relative to its own orientation, and the rate of rotation. If the velocity and turn rate are both non-zero, the robot will follow a circular path. A velocity of zero with a non-zero turn rate will cause the robot to rotate in place. This function overrides and clears the turtle command queue.
Examples:
setRelativeVelocity(0.3,0.0,0.0) - Move straight forward.
setRelativeVelocity(0.0,0.3,0.0) - Move leftward.
setRelativeVelocity(0.0,-0.2,-1.5) - Move rightward, while rotating clockwise.
vx | The x-component of the velocity in meters per second. |
vy | The y-component of the velocity in meters per second. |
turnRate | The turn rate in radians per second. Use positive values for counterclockwise rotation, or negative values for clockwise rotation. |
Definition at line 99 of file nav2remote.cpp.
int Nav2Remote::setTargetOrientation | ( | double | orientation | ) |
Set the target orientation in world coordinates.
At an orientation of zero, the robot is facing in the direction of the positive x axis. If the robot needs to rotate, its rotational speed will gradually increase then gradually decrease to try to achieve the given orientation.
orientation | the target orientation in radians. |
Definition at line 85 of file nav2remote.cpp.
int Nav2Remote::stop | ( | ) |
Stop the robot immediately.
Definition at line 128 of file nav2remote.cpp.
int Nav2Remote::turnLeft | ( | double | angle | ) |
Turn left.
Queue a turtle command to turn left by the specified angle.
angle | The angle in radians. |
Definition at line 133 of file nav2remote.cpp.
int Nav2Remote::turnRight | ( | double | angle | ) | [inline] |
Turn right.
Queue a turtle command to turn right by the specified angle.
angle | The angle in radians. |
Definition at line 156 of file nav2remote.h.
int Nav2Remote::wait | ( | ) | const |
Wait until the turtle command queue is empty.
Definition at line 221 of file nav2remote.cpp.
int Nav2Remote::fd [private] |
Definition at line 35 of file nav2remote.h.
char* Nav2Remote::line [mutable, private] |
Definition at line 33 of file nav2remote.h.
int Nav2Remote::lineLen [mutable, private] |
Definition at line 34 of file nav2remote.h.