Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: proto01.cpp
- Revision:
- 9:5b4d60ae982f
- Parent:
- 7:c9707baaf007
diff -r c9707baaf007 -r 5b4d60ae982f proto01.cpp
--- a/proto01.cpp Mon Sep 23 23:28:45 2019 +0000
+++ b/proto01.cpp Thu Oct 03 08:40:53 2019 +0000
@@ -1,16 +1,16 @@
#include "proto01.h"
-
+
Proto1::Proto1(double accdis_, double decdis_, double maxspeed_, double s_vector_)
{
accdis = accdis_;
- accdis2 = accdis_;
+ accdis2 = accdis;
decdis = decdis_;
- decdis2 = decdis_;
+ decdis2 = decdis;
maxspeed = maxspeed_;
- maxspeed2 = maxspeed_;
+ maxspeed2 = maxspeed;
s_vector = s_vector_;
}
-
+
void Proto1::target(double target_, double start_)
{
targetDis = target_;
@@ -22,15 +22,15 @@
consdis = targetDis - accdis - decdis;
} else {
maxspeed = maxspeed2 / 2.0;
- accdis = targetDis / 2.0;
- decdis = targetDis / 2.0;
- consdis = 0.0;
+ accdis = targetDis / 2;
+ decdis = targetDis / 2;
+ consdis = 0;
}
/*秘伝のコード*/ /*いじるな*/
accsec = 2.0 / maxspeed * accdis;
decsec = 2.0 / maxspeed * decdis;
}
-
+
void Proto1::targetXY(int targetx_, int targety_, int startx_, int starty_)
{
targetDis = hypot((float)(startx_-targetx_), (float)(starty_-targety_));
@@ -44,22 +44,22 @@
decdis = decdis2;
consdis = targetDis - accdis - decdis;
} else {
- maxspeed = maxspeed2 / 2.0;
- accdis = targetDis / 2.0;
- decdis = targetDis / 2.0;
- consdis = 0.0;
+ maxspeed = maxspeed / 2.0;
+ accdis = targetDis / 2;
+ decdis = targetDis / 2;
+ consdis = 0;
}
/*秘伝のコード*/ /*いじるな*/
accsec = 2.0 / maxspeed * accdis;
decsec = 2.0 / maxspeed * decdis;
}
-
+
void Proto1::Input_now(double now_)
{
now = now_;
nowDis = now - start;
}
-
+
void Proto1::Input_nowXY(int now_x, int now_y)
{
nowx = now_x;
@@ -67,11 +67,11 @@
nowDis = hypot((startx-nowx),(starty-nowy));
targetRad = atan2((double)(targety-nowy), (double)(targetx-nowx));
}
-
+
void Proto1::calculate()
{
if (nowDis < accdis) {
- counter = sqrt(2.0*accsec/maxspeed*fabs(nowDis));
+ counter = sqrt(2.0*accsec/maxspeed*nowDis);
vector = s_vector + (-1 * sin((2.0*PI/accsec)*counter) + (2.0*PI/accsec)*counter) / ((2.0*PI)/(maxspeed-s_vector));
} else if (nowDis >= accdis && nowDis < accdis+consdis) {
vector = maxspeed;
@@ -82,23 +82,18 @@
vector = 0;
}
}
-
+
double Proto1::getvalue()
{
return vector;
}
-
+
double Proto1::getvalue_x()
{
return vector * cos(targetRad);
}
-
+
double Proto1::getvalue_y()
{
return vector * sin(targetRad);
-}
-
-double Proto1::getTheta()
-{
- return targetRad;
}
\ No newline at end of file