pathUtils.cpp
00001
00002
00003
00004
00005
00006
00007 #include "pathUtils.h"
00008 #include "timeUtils.h"
00009
00010
00016 typedef struct {
00017 double a;
00018 double b;
00019 double c;
00020 } line_t;
00021
00022
00023 void VXV::waitStable(RunInterface& obj,
00024 unsigned long poll_msec, unsigned long timeout_msec) {
00025 unsigned long total_wait = 0;
00026
00027 while (!obj.isStable()) {
00028 VXV::Delay(poll_msec);
00029 total_wait += poll_msec;
00030 if ((timeout_msec > 0) && (poll_msec >= timeout_msec)) {
00031 break;
00032 }
00033 }
00034 }
00035
00036
00037 static void createLine(line_t *line, const VXV::Position& position) {
00038 line->a = cos(position.zt.to_rad());
00039 line->b = -sin(position.zt.to_rad());
00040 line->c = position.y * cos(position.zt.to_rad())
00041 - position.x * sin(position.zt.to_rad());
00042 }
00043
00044
00045 VXV::Position VXV::getNextLinePoint(const VXV::Position& base,
00046 const VXV::Position& next, int radius) {
00047
00048 VXV::Direction center = next.zt - base.zt;
00049
00050 line_t first, second;
00051 createLine(&first, base);
00052 createLine(&second, next);
00053
00054 double t = first.b * second.a - second.b * first.a;
00055 if (fabs(t) < 0.00001) {
00056 return base;
00057 }
00058 double x = (second.a * first.c - first.a * second.c) / t;
00059 double y = (second.c * first.b - first.c * second.b) / t;
00060 double l = fabs(radius * sin(M_PI - center.to_rad() / 2.0));
00061
00062 VXV::Position change(static_cast<int>(x + l * -cos(base.zt.to_rad())),
00063 static_cast<int>(y + l * -sin(base.zt.to_rad())),
00064 base.zt);
00065
00066 return change;
00067 }
00068
00069
00070 bool VXV::followLinesUpdate(RunCtrl& obj,
00071 std::deque<VXV::Position>& lines, int radius,
00072 const CoordinateCtrl* crd) {
00073 switch (lines.size()) {
00074 case 0:
00075 return false;
00076 break;
00077
00078 case 1:
00079 if (obj.getLengthToLine(lines[0], crd) > 0) {
00080 lines.pop_front();
00081 }
00082 break;
00083
00084 default:
00085 VXV::Position next = VXV::getNextLinePoint(lines[0], lines[1], radius);
00086 if (obj.getLengthToLine(next, crd) > 0) {
00087 lines.pop_front();
00088 obj.followLine(lines.front(), crd);
00089 }
00090 break;
00091 }
00092 return true;
00093 }
00094