点列で与えられた連続直線に追従する
#include <iostream>
#include <vector>
using namespace hrk;
using namespace std;
namespace
{
void create_follow_lines(vector<PositionF>& lines,
const vector<PointF>& points)
{
if (points.size() <= 1) {
return;
}
vector<PointF>::const_iterator from_it = points.begin();
for (vector<PointF>::const_iterator to_it = from_it + 1;
to_it != points.end(); ++to_it, ++from_it) {
Angle angle = angle_to(*from_it, *to_it);
lines.push_back(
PositionF(to_it->x(), to_it->y(), angle));
}
}
void follow(
Run_driver& robot,
const vector<PositionF>& lines)
{
size_t line_index = 0;
while (true) {
-Line_change_distance) {
delay_sec(0.1);
}
size_t next_line_index = line_index + 1;
if (lines.size() <= next_line_index) {
return;
}
line_index = next_line_index;
}
}
}
int main(int argc, char *argv[])
{
static_cast<void>(argc);
static_cast<void>(argv);
if (!robot.
open(
"/dev/ttyUSB0")) {
cerr << FILE_POSITION() << robot.
what() << endl;
return 1;
}
vector<PointF> points;
points.push_back(
PointF(0.0, 0.0));
points.push_back(
PointF(1.0, 0.0));
points.push_back(
PointF(1.0, 1.0));
points.push_back(
PointF(2.0, 1.0));
vector<PositionF> lines;
create_follow_lines(lines, points);
follow(robot, lines);
wait_stable(robot, 0.1);
return 0;
}