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.
Dependents: NHK2017_octopus NHK2017_octopus2 NHK2017_octopus2_drive 2018NHK_gakugaku_robo ... more
wheel.cpp
00001 #include "wheel.h" 00002 00003 Wheel::Wheel() : 00004 radian(0), 00005 distance(1.0) 00006 { 00007 } 00008 00009 Wheel::Wheel(double radian) : 00010 radian(radian), 00011 distance(1.0) 00012 { 00013 } 00014 00015 Wheel::Wheel(double radian, double distance) : 00016 radian(radian), 00017 distance(distance) 00018 { 00019 } 00020 00021 Wheel::Wheel(const Wheel &a) : 00022 radian(a.radian), 00023 distance(a.distance) 00024 { 00025 } 00026 00027 Wheel &Wheel::operator=(const Wheel &a) 00028 { 00029 if(this != &a) { 00030 radian = a.radian; 00031 distance = a.distance; 00032 } 00033 return *this; 00034 } 00035 00036 Wheel &Wheel::operator=(double value) 00037 { 00038 setOutput(value); 00039 return *this; 00040 } 00041 00042 Wheel &Wheel::operator=(float value) 00043 { 00044 setOutput(value); 00045 return *this; 00046 } 00047 00048 Wheel::operator double() 00049 { 00050 return output; 00051 } 00052 00053 Wheel::operator float() 00054 { 00055 return float(output); 00056 } 00057 00058 void Wheel::setRadian(double tRadian) 00059 { 00060 radian = tRadian; 00061 } 00062 00063 void Wheel::setDistance(double tDistance) 00064 { 00065 distance = tDistance; 00066 } 00067 00068 void Wheel::setOutput(double value) 00069 { 00070 output = value; 00071 } 00072 00073 double Wheel::calculateShift(double r, double theta) 00074 { 00075 outputShift = sin(theta - radian) * r; 00076 return outputShift; 00077 } 00078 00079 double Wheel::calculateRotate(double X, double Y, double value) 00080 { 00081 outputRotate = fabs(X + tan(radian) * Y - cos(radian) - sin(radian) * tan(radian)) / hypot(1.0, tan(radian)); 00082 outputRotate *= value; 00083 if(Y > 0) { 00084 if(Y > (-1 * (X - sin(radian) * tan(radian))) / tan(radian)) outputRotate *= -1; 00085 } 00086 if(Y < 0) { 00087 if(Y < (-1 * (X - sin(radian) * tan(radian))) / tan(radian)) outputRotate *= -1; 00088 } 00089 return outputRotate; 00090 } 00091 00092 double Wheel::getOutput() 00093 { 00094 return output; 00095 }
Generated on Thu Aug 18 2022 04:25:58 by
1.7.2