command_get.c
Go to the documentation of this file.
00001 // Copyright (c) 2010-2016 The YP-Spur Authors, except where otherwise indicated.
00002 //
00003 // Permission is hereby granted, free of charge, to any person obtaining a copy
00004 // of this software and associated documentation files (the "Software"), to
00005 // deal in the Software without restriction, including without limitation the
00006 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
00007 // sell copies of the Software, and to permit persons to whom the Software is
00008 // furnished to do so, subject to the following conditions:
00009 //
00010 // The above copyright notice and this permission notice shall be included in
00011 // all copies or substantial portions of the Software.
00012 //
00013 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00014 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00015 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
00016 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00017 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00018 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
00019 // SOFTWARE.
00020 
00021 #include <math.h>
00022 #include <stdio.h>
00023 #include <strings.h>
00024 #include <unistd.h>
00025 
00026 #include <fcntl.h>
00027 #include <sys/time.h>
00028 #include <sys/types.h>
00029 #include <time.h>
00030 
00031 #ifdef HAVE_CONFIG_H
00032 #include <config.h>
00033 #endif  // HAVE_CONFIG_H
00034 
00035 /* ボディパラメータ */
00036 #include <shvel-param.h>
00037 
00038 /* yp-spur用 */
00039 #include <serial.h>
00040 #include <param.h>
00041 #include <control.h>
00042 #include <command.h>
00043 
00044 /* ライブラリ用 */
00045 #include <ypspur.h>
00046 #include <cartesian2d.h>
00047 
00048 void get_pos_com(int cs, double *data, double *resdata, SpurUserParamsPtr spur)
00049 {
00050   Odometry odometry;
00051 
00052   cstrans_odometry(cs, &odometry);
00053 
00054   resdata[0] = odometry.x;
00055   resdata[1] = odometry.y;
00056   resdata[2] = odometry.theta;
00057   resdata[3] = odometry.time;
00058   // printf( "get %f %f %f\n", x, y, theta );
00059 }
00060 
00061 void get_wheel_vref_com(int cs, double *data, double *resdata, SpurUserParamsPtr spur)
00062 {
00063   OdometryPtr odometry;
00064 
00065   odometry = get_odometry_ptr();
00066 
00067   resdata[0] = spur->wvelref[0];
00068   resdata[1] = spur->wvelref[1];
00069   resdata[2] = odometry->time;
00070 }
00071 
00072 void get_vref_com(int cs, double *data, double *resdata, SpurUserParamsPtr spur)
00073 {
00074   OdometryPtr odometry;
00075 
00076   odometry = get_odometry_ptr();
00077 
00078   resdata[0] = spur->vref_smooth;
00079   resdata[1] = spur->wref_smooth;
00080   resdata[2] = odometry->time;
00081 }
00082 
00083 void get_vel_com(int cs, double *data, double *resdata, SpurUserParamsPtr spur)
00084 {
00085   OdometryPtr odometry;
00086 
00087   odometry = get_odometry_ptr();
00088 
00089   resdata[0] = odometry->v;
00090   resdata[1] = odometry->w;
00091   resdata[2] = odometry->time;
00092 
00093   // printf("getvel %f %f %f\n",);
00094 }
00095 
00096 void get_force_com(int cs, double *data, double *resdata, SpurUserParamsPtr spur)
00097 {
00098   OdometryPtr odometry;
00099 
00100   odometry = get_odometry_ptr();
00101 
00102   resdata[0] = odometry->torque_trans;
00103   resdata[1] = odometry->torque_angular;
00104   resdata[2] = odometry->time;
00105 
00106   // printf("getvel %f %f %f\n",);
00107 }
00108 
00109 void get_wheel_torque_com(int cs, double *data, double *resdata, SpurUserParamsPtr spur)
00110 {
00111   OdometryPtr odometry;
00112 
00113   odometry = get_odometry_ptr();
00114 
00115   resdata[0] = odometry->wtorque[0];
00116   resdata[1] = odometry->wtorque[1];
00117   resdata[2] = odometry->time;
00118 
00119   // printf("getvel %f %f %f\n",);
00120 }
00121 
00122 void get_wheel_vel_com(double *data, double *resdata, SpurUserParamsPtr spur)
00123 {
00124   OdometryPtr odometry;
00125 
00126   odometry = get_odometry_ptr();
00127 
00128   resdata[0] = odometry->wvel[0];
00129   resdata[1] = odometry->wvel[1];
00130   resdata[2] = odometry->time;
00131 
00132   // printf("getvel %f %f %f\n",);
00133 }
00134 
00135 void get_wheel_ang_com(double *data, double *resdata, SpurUserParamsPtr spur)
00136 {
00137   OdometryPtr odometry;
00138 
00139   odometry = get_odometry_ptr();
00140 
00141   resdata[0] = odometry->wang[0];
00142   resdata[1] = odometry->wang[1];
00143   resdata[2] = odometry->time;
00144 
00145   // printf("getvel %f %f %f\n",);
00146 }
00147 
00148 int near_pos_com(int cs, double *data, double *resdata, SpurUserParamsPtr spur)
00149 {
00150   double x, y, theta, cx, cy;
00151   double dist;
00152   OdometryPtr odometry;
00153 
00154   odometry = get_odometry_ptr();
00155 
00156   x = odometry->x;
00157   y = odometry->y;
00158   theta = odometry->theta;
00159 
00160   cstrans_xy(CS_BS, cs, &x, &y, &theta);
00161 
00162   cx = data[0];
00163   cy = data[1];
00164   dist = sqrt((cx - x) * (cx - x) + (cy - y) * (cy - y));
00165   resdata[0] = dist;
00166 
00167   if (dist < data[2])
00168     return 1;
00169   else
00170     return 0;
00171 }
00172 
00173 int near_ang_com(int cs, double *data, double *resdata, SpurUserParamsPtr spur)
00174 {
00175   double x, y, theta;
00176   double dist;
00177   OdometryPtr odometry;
00178 
00179   odometry = get_odometry_ptr();
00180 
00181   x = odometry->x;
00182   y = odometry->y;
00183   theta = odometry->theta;
00184 
00185   cstrans_xy(CS_BS, cs, &x, &y, &theta);
00186 
00187   dist = theta - data[0];
00188   while (dist > M_PI)
00189     dist -= 2 * M_PI;
00190   while (dist < -M_PI)
00191     dist += 2 * M_PI;
00192   resdata[0] = dist;
00193   if (fabs(dist) < data[1])
00194     return 1;
00195   else
00196     return 0;
00197 }
00198 
00199 int over_line_com(int cs, double *data, double *resdata, SpurUserParamsPtr spur)
00200 {
00201   double x, y, theta;
00202   double dist;
00203   OdometryPtr odometry;
00204 
00205   odometry = get_odometry_ptr();
00206 
00207   x = odometry->x;
00208   y = odometry->y;
00209   theta = odometry->theta;
00210 
00211   cstrans_xy(CS_BS, cs, &x, &y, &theta);
00212 
00213   dist = (x - data[0]) * cos(data[2]) + (y - data[1]) * sin(data[2]);
00214 
00215   resdata[0] = dist;
00216   if (dist > 0)
00217     return 1;
00218   else
00219     return 0;
00220 }


yp-spur
Author(s):
autogenerated on Fri May 10 2019 02:52:19