libypspur-md.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 /* 
00022  * YP-Spurとの通信ライブラリ複数デバイス対応版 Communication Library for YP-Spur
00023  */
00024 
00025 #include <stdio.h>
00026 #include <stdlib.h>
00027 #include <string.h>
00028 #include <unistd.h>
00029 
00030 #include <sys/types.h>
00031 
00032 #ifdef HAVE_CONFIG_H
00033 #include <config.h>
00034 #endif  // HAVE_CONFIG_H
00035 
00036 #define YP_SPUR_RUNTIME
00037 
00038 #include <ipcommunication.h>
00039 #include <ypspur-md.h>
00040 #include <param.h>
00041 
00042 /* エラー確認 */
00043 int YP_md_get_error_state(YPSpur *spur)
00044 {
00045   return spur->dev.connection_error;
00046 }
00047 
00048 double YP_md_get_device_error_state(YPSpur *spur, int id, int *error_state)
00049 {
00050   YPSpur_msg msg;
00051   int len;
00052   double time;
00053 
00054   msg.msg_type = YPSPUR_MSG_CMD;
00055   msg.pid = spur->pid;
00056   msg.type = YPSPUR_GET_ERROR_STATE;
00057   msg.data[0] = id;
00058   msg.cs = 0;
00059   if (spur->dev.send(&spur->dev, &msg) < 0)
00060   {
00061     /* error */
00062     spur->connection_error = 1;
00063     return -1;
00064   }
00065 
00066   /* 指定のコマンド受け取り */
00067   len = spur->dev.recv(&spur->dev, &msg);
00068   if (len < 0)
00069   {
00070     /* receive error */
00071     spur->connection_error = 1;
00072     return -1;
00073   }
00074 
00075   *error_state = (int)msg.data[0];
00076   time = msg.data[1];
00077   return time;
00078 }
00079 
00080 /* coordinatorとのメッセージ通信を開始する */
00081 int YPSpur_md_initex(YPSpur *spur, int msq_key)
00082 {
00083   /* メッセージ・キューのオープン */
00084   if (ipcmd_open_msq(&spur->dev, msq_key, 0) < 0)
00085   {
00086     return -1;
00087   }
00088 
00089   spur->pid = spur->dev.pid;
00090 
00091   return 1;
00092 }
00093 
00094 int YPSpur_md_init_socket(YPSpur *spur, char *ip, int port)
00095 {
00096   /* メッセージ・キューのオープン */
00097   if (ipcmd_open_tcp(&spur->dev, ip, port) < 0)
00098   {
00099     return -1;
00100   }
00101 
00102   spur->pid = spur->dev.pid;
00103 
00104   return 1;
00105 }
00106 
00107 /* coordinatorとのメッセージ通信を開始する */
00108 int YPSpur_md_init(YPSpur *spur)
00109 {
00110   return YPSpur_md_initex(spur, YPSPUR_MSQ_KEY);
00111 }
00112 
00113 /* 直線追従 */
00114 int YPSpur_md_line(YPSpur *spur, int cs, double x, double y, double theta)
00115 {
00116   YPSpur_msg msg;
00117 
00118   msg.msg_type = YPSPUR_MSG_CMD;
00119   msg.pid = spur->pid;
00120   msg.type = YPSPUR_LINE;
00121   msg.data[0] = x;
00122   msg.data[1] = y;
00123   msg.data[2] = theta;
00124   msg.cs = cs;
00125 
00126   if (spur->dev.send(&spur->dev, &msg) < 0)
00127   {
00128     /* error */
00129     spur->connection_error = 1;
00130     return -1;
00131   }
00132   return 1;
00133 }
00134 
00135 /* 直線追従 */
00136 int YPSpur_md_stop_line(YPSpur *spur, int cs, double x, double y, double theta)
00137 {
00138   YPSpur_msg msg;
00139 
00140   msg.msg_type = YPSPUR_MSG_CMD;
00141   msg.pid = spur->pid;
00142   msg.type = YPSPUR_STOP_LINE;
00143   msg.data[0] = x;
00144   msg.data[1] = y;
00145   msg.data[2] = theta;
00146   msg.cs = cs;
00147 
00148   if (spur->dev.send(&spur->dev, &msg) < 0)
00149   {
00150     /* error */
00151     spur->connection_error = 1;
00152     return -1;
00153   }
00154   return 1;
00155 }
00156 
00157 /* 円弧追従 */
00158 int YPSpur_md_circle(YPSpur *spur, int cs, double x, double y, double r)
00159 {
00160   YPSpur_msg msg;
00161 
00162   msg.msg_type = YPSPUR_MSG_CMD;
00163   msg.pid = spur->pid;
00164   msg.type = YPSPUR_CIRCLE;
00165   msg.data[0] = x;
00166   msg.data[1] = y;
00167   msg.data[2] = r;
00168   msg.cs = cs;
00169   if (spur->dev.send(&spur->dev, &msg) < 0)
00170   {
00171     /* error */
00172     spur->connection_error = 1;
00173     return -1;
00174   }
00175 
00176   return 1;
00177 }
00178 
00179 /* 旋回 */
00180 int YPSpur_md_spin(YPSpur *spur, int cs, double theta)
00181 {
00182   YPSpur_msg msg;
00183 
00184   msg.msg_type = YPSPUR_MSG_CMD;
00185   msg.pid = spur->pid;
00186   msg.type = YPSPUR_SPIN;
00187   msg.data[0] = theta;
00188   msg.cs = cs;
00189   if (spur->dev.send(&spur->dev, &msg) < 0)
00190   {
00191     /* error */
00192     spur->connection_error = 1;
00193     return -1;
00194   }
00195 
00196   return 1;
00197 }
00198 
00199 /* 方位 */
00200 int YPSpur_md_orient(YPSpur *spur, int cs, double theta)
00201 {
00202   YPSpur_msg msg;
00203 
00204   msg.msg_type = YPSPUR_MSG_CMD;
00205   msg.pid = spur->pid;
00206   msg.type = YPSPUR_ORIENT;
00207   msg.data[0] = theta;
00208   msg.cs = cs;
00209   if (spur->dev.send(&spur->dev, &msg) < 0)
00210   {
00211     /* error */
00212     spur->connection_error = 1;
00213     return -1;
00214   }
00215 
00216   return 1;
00217 }
00218 
00219 /* 急ブレーキ */
00220 int YPSpur_md_stop(YPSpur *spur)
00221 {
00222   YPSpur_msg msg;
00223 
00224   msg.msg_type = YPSPUR_MSG_CMD;
00225   msg.pid = spur->pid;
00226   msg.type = YPSPUR_STOP;
00227 
00228   if (spur->dev.send(&spur->dev, &msg) < 0)
00229   {
00230     /* error */
00231     spur->connection_error = 1;
00232     return -1;
00233   }
00234 
00235   return 1;
00236 }
00237 
00238 /* 緊急停止 */
00239 int YPSpur_md_freeze(YPSpur *spur)
00240 {
00241   YPSpur_msg msg;
00242 
00243   msg.msg_type = YPSPUR_MSG_CMD;
00244   msg.pid = spur->pid;
00245   msg.type = YPSPUR_FREEZE;
00246 
00247   if (spur->dev.send(&spur->dev, &msg) < 0)
00248   {
00249     /* error */
00250     spur->connection_error = 1;
00251     return -1;
00252   }
00253 
00254   return 1;
00255 }
00256 
00257 /* 緊急停止解除 */
00258 int YPSpur_md_unfreeze(YPSpur *spur)
00259 {
00260   YPSpur_msg msg;
00261 
00262   msg.msg_type = YPSPUR_MSG_CMD;
00263   msg.pid = spur->pid;
00264   msg.type = YPSPUR_UNFREEZE;
00265 
00266   if (spur->dev.send(&spur->dev, &msg) < 0)
00267   {
00268     /* error */
00269     spur->connection_error = 1;
00270     return -1;
00271   }
00272 
00273   return 1;
00274 }
00275 
00276 /* ソフトウェア補助フリーモード */
00277 int YPSpur_md_free(YPSpur *spur)
00278 {
00279   YPSpur_msg msg;
00280 
00281   msg.msg_type = YPSPUR_MSG_CMD;
00282   msg.pid = spur->pid;
00283   msg.type = YPSPUR_FREE;
00284 
00285   if (spur->dev.send(&spur->dev, &msg) < 0)
00286   {
00287     /* error */
00288     spur->connection_error = 1;
00289     return -1;
00290   }
00291 
00292   return 1;
00293 }
00294 
00295 /* 制御なしフリーモード */
00296 int YP_md_openfree(YPSpur *spur)
00297 {
00298   YPSpur_msg msg;
00299 
00300   msg.msg_type = YPSPUR_MSG_CMD;
00301   msg.pid = spur->pid;
00302   msg.type = YPSPUR_OPENFREE;
00303 
00304   if (spur->dev.send(&spur->dev, &msg) < 0)
00305   {
00306     /* error */
00307     spur->connection_error = 1;
00308     return -1;
00309   }
00310 
00311   return 1;
00312 }
00313 
00314 /* 位置指定 */
00315 int YPSpur_md_set_pos(YPSpur *spur, int cs, double x, double y, double theta)
00316 {
00317   YPSpur_msg msg;
00318 
00319   msg.msg_type = YPSPUR_MSG_CMD;
00320   msg.pid = spur->pid;
00321   msg.type = YPSPUR_SET_POS;
00322   msg.data[0] = x;
00323   msg.data[1] = y;
00324   msg.data[2] = theta;
00325   msg.cs = cs;
00326 
00327   if (spur->dev.send(&spur->dev, &msg) < 0)
00328   {
00329     /* error */
00330     spur->connection_error = 1;
00331     return -1;
00332   }
00333   return 1;
00334 }
00335 
00336 /* 位置指定 */
00337 int YPSpur_md_adjust_pos(YPSpur *spur, int cs, double x, double y, double theta)
00338 {
00339   YPSpur_msg msg;
00340 
00341   msg.msg_type = YPSPUR_MSG_CMD;
00342   msg.pid = spur->pid;
00343   msg.type = YPSPUR_ADJUST;
00344   msg.data[0] = x;
00345   msg.data[1] = y;
00346   msg.data[2] = theta;
00347   msg.cs = cs;
00348 
00349   if (spur->dev.send(&spur->dev, &msg) < 0)
00350   {
00351     /* error */
00352     spur->connection_error = 1;
00353     return -1;
00354   }
00355   return 1;
00356 }
00357 
00358 /* 速度指定 */
00359 int YPSpur_md_set_vel(YPSpur *spur, double v)
00360 {
00361   YPSpur_msg msg;
00362 
00363   msg.msg_type = YPSPUR_MSG_CMD;
00364   msg.pid = spur->pid;
00365   msg.type = YPSPUR_SET_VEL;
00366   msg.data[0] = v;
00367 
00368   if (spur->dev.send(&spur->dev, &msg) < 0)
00369   {
00370     /* error */
00371     spur->connection_error = 1;
00372     return -1;
00373   }
00374 
00375   return 1;
00376 }
00377 
00378 /* 角速度指定 */
00379 int YPSpur_md_set_angvel(YPSpur *spur, double w)
00380 {
00381   YPSpur_msg msg;
00382 
00383   msg.msg_type = YPSPUR_MSG_CMD;
00384   msg.pid = spur->pid;
00385   msg.type = YPSPUR_SET_ANGVEL;
00386   msg.data[0] = w;
00387 
00388   if (spur->dev.send(&spur->dev, &msg) < 0)
00389   {
00390     /* error */
00391     spur->connection_error = 1;
00392     return -1;
00393   }
00394 
00395   return 1;
00396 }
00397 
00398 /* 速度指定 */
00399 int YPSpur_md_set_accel(YPSpur *spur, double dv)
00400 {
00401   YPSpur_msg msg;
00402 
00403   msg.msg_type = YPSPUR_MSG_CMD;
00404   msg.pid = spur->pid;
00405   msg.type = YPSPUR_SET_ACCEL;
00406   msg.data[0] = dv;
00407 
00408   if (spur->dev.send(&spur->dev, &msg) < 0)
00409   {
00410     /* error */
00411     spur->connection_error = 1;
00412     return -1;
00413   }
00414 
00415   return 1;
00416 }
00417 
00418 /* 角速度指定 */
00419 int YPSpur_md_set_angaccel(YPSpur *spur, double dw)
00420 {
00421   YPSpur_msg msg;
00422 
00423   msg.msg_type = YPSPUR_MSG_CMD;
00424   msg.pid = spur->pid;
00425   msg.type = YPSPUR_SET_ANGACCEL;
00426   msg.data[0] = dw;
00427 
00428   if (spur->dev.send(&spur->dev, &msg) < 0)
00429   {
00430     /* error */
00431     spur->connection_error = 1;
00432     return -1;
00433   }
00434 
00435   return 1;
00436 }
00437 
00438 /* 位置取得 */
00439 double YPSpur_md_get_pos(YPSpur *spur, int cs, double *x, double *y, double *theta)
00440 {
00441   YPSpur_msg msg;
00442   int len;
00443   double time;
00444 
00445   msg.msg_type = YPSPUR_MSG_CMD;
00446   msg.pid = spur->pid;
00447   msg.type = YPSPUR_GET_POS;
00448   msg.cs = cs;
00449   if (spur->dev.send(&spur->dev, &msg) < 0)
00450   {
00451     /* error */
00452     spur->connection_error = 1;
00453     return -1;
00454   }
00455 
00456   /* 指定のコマンド受け取り */
00457   len = spur->dev.recv(&spur->dev, &msg);
00458   if (len < 0)
00459   {
00460     /* receive error */
00461     spur->connection_error = 1;
00462     return -1;
00463   }
00464 
00465   *x = msg.data[0];
00466   *y = msg.data[1];
00467   *theta = msg.data[2];
00468   time = msg.data[3];
00469   return time;
00470 }
00471 
00472 /* 速度取得 */
00473 double YPSpur_md_get_vel(YPSpur *spur, double *v, double *w)
00474 {
00475   YPSpur_msg msg;
00476   int len;
00477   double time;
00478 
00479   msg.msg_type = YPSPUR_MSG_CMD;
00480   msg.pid = spur->pid;
00481   msg.type = YPSPUR_GET_VEL;
00482   msg.cs = 0;
00483   if (spur->dev.send(&spur->dev, &msg) < 0)
00484   {
00485     /* error */
00486     spur->connection_error = 1;
00487     return -1;
00488   }
00489 
00490   /* 指定のコマンド受け取り */
00491   len = spur->dev.recv(&spur->dev, &msg);
00492   if (len < 0)
00493   {
00494     /* receive error */
00495     spur->connection_error = 1;
00496     return -1;
00497   }
00498 
00499   *v = msg.data[0];
00500   *w = msg.data[1];
00501   time = msg.data[2];
00502   return time;
00503 }
00504 
00505 /* 速度取得 */
00506 double YP_md_get_vref(YPSpur *spur, double *v, double *w)
00507 {
00508   YPSpur_msg msg;
00509   int len;
00510   double time;
00511 
00512   msg.msg_type = YPSPUR_MSG_CMD;
00513   msg.pid = spur->pid;
00514   msg.type = YPSPUR_GET_VREF;
00515   msg.cs = 0;
00516   if (spur->dev.send(&spur->dev, &msg) < 0)
00517   {
00518     /* error */
00519     spur->connection_error = 1;
00520     return -1;
00521   }
00522 
00523   /* 指定のコマンド受け取り */
00524   len = spur->dev.recv(&spur->dev, &msg);
00525   if (len < 0)
00526   {
00527     /* receive error */
00528     spur->connection_error = 1;
00529     return -1;
00530   }
00531 
00532   *v = msg.data[0];
00533   *w = msg.data[1];
00534   time = msg.data[2];
00535   return time;
00536 }
00537 
00538 /* 速度取得 */
00539 double YP_md_get_wheel_vref(YPSpur *spur, double *wr, double *wl)
00540 {
00541   YPSpur_msg msg;
00542   int len;
00543   double time;
00544 
00545   msg.msg_type = YPSPUR_MSG_CMD;
00546   msg.pid = spur->pid;
00547   msg.type = YPSPUR_GET_WHEEL_VREF;
00548   msg.cs = 0;
00549   if (spur->dev.send(&spur->dev, &msg) < 0)
00550   {
00551     /* error */
00552     spur->connection_error = 1;
00553     return -1;
00554   }
00555 
00556   /* 指定のコマンド受け取り */
00557   len = spur->dev.recv(&spur->dev, &msg);
00558   if (len < 0)
00559   {
00560     /* receive error */
00561     spur->connection_error = 1;
00562     return -1;
00563   }
00564 
00565   *wr = msg.data[0];
00566   *wl = msg.data[1];
00567   time = msg.data[2];
00568   return time;
00569 }
00570 
00571 /* 速度取得 */
00572 double YP_md_get_wheel_vel(YPSpur *spur, double *wr, double *wl)
00573 {
00574   YPSpur_msg msg;
00575   int len;
00576   double time;
00577 
00578   msg.msg_type = YPSPUR_MSG_CMD;
00579   msg.pid = spur->pid;
00580   msg.type = YPSPUR_GET_WHEEL_VEL;
00581   msg.cs = 0;
00582   if (spur->dev.send(&spur->dev, &msg) < 0)
00583   {
00584     /* error */
00585     spur->connection_error = 1;
00586     return -1;
00587   }
00588 
00589   /* 指定のコマンド受け取り */
00590   len = spur->dev.recv(&spur->dev, &msg);
00591   if (len < 0)
00592   {
00593     /* receive error */
00594     spur->connection_error = 1;
00595     return -1;
00596   }
00597 
00598   *wr = msg.data[0];
00599   *wl = msg.data[1];
00600   time = msg.data[2];
00601   return time;
00602 }
00603 
00604 /* 角度取得 */
00605 double YP_md_get_wheel_ang(YPSpur *spur, double *theta_r, double *theta_l)
00606 {
00607   YPSpur_msg msg;
00608   int len;
00609   double time;
00610 
00611   msg.msg_type = YPSPUR_MSG_CMD;
00612   msg.pid = spur->pid;
00613   msg.type = YPSPUR_GET_WHEEL_ANG;
00614   msg.cs = 0;
00615   if (spur->dev.send(&spur->dev, &msg) < 0)
00616   {
00617     /* error */
00618     spur->connection_error = 1;
00619     return -1;
00620   }
00621 
00622   /* 指定のコマンド受け取り */
00623   len = spur->dev.recv(&spur->dev, &msg);
00624   if (len < 0)
00625   {
00626     /* receive error */
00627     spur->connection_error = 1;
00628     return -1;
00629   }
00630 
00631   *theta_r = msg.data[0];
00632   *theta_l = msg.data[1];
00633   time = msg.data[2];
00634   return time;
00635 }
00636 
00637 /* トルク取得 */
00638 double YP_md_get_wheel_torque(YPSpur *spur, double *torque_r, double *torque_l)
00639 {
00640   YPSpur_msg msg;
00641   int len;
00642   double time;
00643 
00644   msg.msg_type = YPSPUR_MSG_CMD;
00645   msg.pid = spur->pid;
00646   msg.type = YPSPUR_GET_WHEEL_TORQUE;
00647   msg.cs = 0;
00648   if (spur->dev.send(&spur->dev, &msg) < 0)
00649   {
00650     /* error */
00651     spur->connection_error = 1;
00652     return -1;
00653   }
00654 
00655   /* 指定のコマンド受け取り */
00656   len = spur->dev.recv(&spur->dev, &msg);
00657   if (len < 0)
00658   {
00659     /* receive error */
00660     spur->connection_error = 1;
00661     return -1;
00662   }
00663 
00664   *torque_r = msg.data[0];
00665   *torque_l = msg.data[1];
00666   time = msg.data[2];
00667   return time;
00668 }
00669 
00670 /* 力取得 */
00671 double YPSpur_md_get_force(YPSpur *spur, double *trans, double *angular)
00672 {
00673   YPSpur_msg msg;
00674   int len;
00675   double time;
00676 
00677   msg.msg_type = YPSPUR_MSG_CMD;
00678   msg.pid = spur->pid;
00679   msg.type = YPSPUR_GET_FORCE;
00680   msg.cs = 0;
00681   if (spur->dev.send(&spur->dev, &msg) < 0)
00682   {
00683     /* error */
00684     spur->connection_error = 1;
00685     return -1;
00686   }
00687 
00688   /* 指定のコマンド受け取り */
00689   len = spur->dev.recv(&spur->dev, &msg);
00690   if (len < 0)
00691   {
00692     /* receive error */
00693     spur->connection_error = 1;
00694     return -1;
00695   }
00696 
00697   *trans = msg.data[0];
00698   *angular = msg.data[1];
00699   time = msg.data[2];
00700   return time;
00701 }
00702 
00703 /* 緊急停止状態取得 */
00704 int YPSpur_md_isfreeze(YPSpur *spur)
00705 {
00706   YPSpur_msg msg;
00707   int len;
00708   int ret;
00709 
00710   msg.msg_type = YPSPUR_MSG_CMD;
00711   msg.pid = spur->pid;
00712   msg.type = YPSPUR_ISFREEZE;
00713   msg.cs = 0;
00714   if (spur->dev.send(&spur->dev, &msg) < 0)
00715   {
00716     /* error */
00717     spur->connection_error = 1;
00718     return -1;
00719   }
00720 
00721   /* 指定のコマンド受け取り */
00722   len = spur->dev.recv(&spur->dev, &msg);
00723   if (len < 0)
00724   {
00725     /* receive error */
00726     spur->connection_error = 1;
00727     return -1;
00728   }
00729 
00730   ret = (int)msg.data[0];
00731   return ret;
00732 }
00733 
00734 /* 直接速度入力 */
00735 int YPSpur_md_vel(YPSpur *spur, double v, double w)
00736 {
00737   YPSpur_msg msg;
00738 
00739   msg.msg_type = YPSPUR_MSG_CMD;
00740   msg.pid = spur->pid;
00741   msg.type = YPSPUR_VEL;
00742   msg.data[0] = v;
00743   msg.data[1] = w;
00744 
00745   if (spur->dev.send(&spur->dev, &msg) < 0)
00746   {
00747     /* error */
00748     spur->connection_error = 1;
00749     return -1;
00750   }
00751 
00752   return 1;
00753 }
00754 
00755 /* 内部パラメータの変更 */
00756 int YP_md_set_parameter(YPSpur *spur, int param_id, double value)
00757 {
00758   YPSpur_msg msg;
00759 
00760   msg.msg_type = YPSPUR_MSG_CMD;
00761   msg.pid = spur->pid;
00762   msg.type = YPSPUR_PARAM_SET;
00763   msg.cs = param_id;
00764   msg.data[0] = value;
00765   msg.data[1] = value;
00766 
00767   if (spur->dev.send(&spur->dev, &msg) < 0)
00768   {
00769     /* error */
00770     spur->connection_error = 1;
00771     return -1;
00772   }
00773 
00774   return 1;
00775 }
00776 
00777 /* 内部パラメータの変更 */
00778 int YP_md_set_parameter_array(YPSpur *spur, int param_id, double *value)
00779 {
00780   YPSpur_msg msg;
00781 
00782   msg.msg_type = YPSPUR_MSG_CMD;
00783   msg.pid = spur->pid;
00784   msg.type = YPSPUR_PARAM_SET;
00785   msg.cs = param_id;
00786   msg.data[0] = value[0];
00787   msg.data[1] = value[1];
00788 
00789   if (spur->dev.send(&spur->dev, &msg) < 0)
00790   {
00791     /* error */
00792     spur->connection_error = 1;
00793     return -1;
00794   }
00795 
00796   return 1;
00797 }
00798 
00799 /* 内部パラメータの取得 */
00800 int YP_md_get_parameter(YPSpur *spur, int param_id, double *value)
00801 {
00802   YPSpur_msg msg;
00803   int len;
00804 
00805   msg.msg_type = YPSPUR_MSG_CMD;
00806   msg.pid = spur->pid;
00807   msg.type = YPSPUR_PARAM_GET;
00808   msg.cs = param_id;
00809   if (spur->dev.send(&spur->dev, &msg) < 0)
00810   {
00811     /* error */
00812     spur->connection_error = 1;
00813     return -1;
00814   }
00815 
00816   /* 指定のコマンド受け取り */
00817   len = spur->dev.recv(&spur->dev, &msg);
00818   if (len < 0)
00819   {
00820     /* receive error */
00821     spur->connection_error = 1;
00822     return -1;
00823   }
00824 
00825   *value = msg.data[0];
00826   return msg.cs;
00827 }
00828 
00829 int YP_md_get_parameter_array(YPSpur *spur, int param_id, double *value)
00830 {
00831   YPSpur_msg msg;
00832   int len;
00833 
00834   msg.msg_type = YPSPUR_MSG_CMD;
00835   msg.pid = spur->pid;
00836   msg.type = YPSPUR_PARAM_GET;
00837   msg.cs = param_id;
00838   if (spur->dev.send(&spur->dev, &msg) < 0)
00839   {
00840     /* error */
00841     spur->connection_error = 1;
00842     return -1;
00843   }
00844 
00845   /* 指定のコマンド受け取り */
00846   len = spur->dev.recv(&spur->dev, &msg);
00847   if (len < 0)
00848   {
00849     /* receive error */
00850     spur->connection_error = 1;
00851     return -1;
00852   }
00853 
00854   value[0] = msg.data[0];
00855   value[1] = msg.data[1];
00856   return msg.cs;
00857 }
00858 
00859 /* 内部状態の変更 */
00860 int YP_md_set_control_state(YPSpur *spur, int control_id, int state)
00861 {
00862   YPSpur_msg msg;
00863 
00864   msg.msg_type = YPSPUR_MSG_CMD;
00865   msg.pid = spur->pid;
00866   msg.type = YPSPUR_PARAM_STATE;
00867   msg.cs = control_id;
00868   msg.data[0] = state;
00869 
00870   if (spur->dev.send(&spur->dev, &msg) < 0)
00871   {
00872     /* error */
00873     spur->connection_error = 1;
00874     return -1;
00875   }
00876 
00877   return 1;
00878 }
00879 
00880 /* 重力補償用地面の傾き指定 */
00881 int YPSpur_md_tilt(YPSpur *spur, int cs, double dir, double tilt)
00882 {
00883   YPSpur_msg msg;
00884 
00885   msg.msg_type = YPSPUR_MSG_CMD;
00886   msg.pid = spur->pid;
00887   msg.type = YPSPUR_SET_TILT;
00888   msg.data[0] = dir;
00889   msg.data[1] = tilt;
00890   msg.cs = cs;
00891 
00892   if (spur->dev.send(&spur->dev, &msg) < 0)
00893   {
00894     /* error */
00895     spur->connection_error = 1;
00896     return -1;
00897   }
00898 
00899   return 1;
00900 }
00901 
00902 /* 位置判定 */
00903 int YPSpur_md_near_pos(YPSpur *spur, int cs, double x, double y, double r)
00904 {
00905   YPSpur_msg msg;
00906   int len;
00907 
00908   msg.msg_type = YPSPUR_MSG_CMD;
00909   msg.pid = spur->pid;
00910   msg.type = YPSPUR_NEAR_POS;
00911   msg.data[0] = x;
00912   msg.data[1] = y;
00913   msg.data[2] = r;
00914   msg.cs = cs;
00915   if (spur->dev.send(&spur->dev, &msg) < 0)
00916   {
00917     /* error */
00918     spur->connection_error = 1;
00919     return -1;
00920   }
00921 
00922   /* 指定のコマンド受け取り */
00923   len = spur->dev.recv(&spur->dev, &msg);
00924   if (len < 0)
00925   {
00926     /* receive error */
00927     spur->connection_error = 1;
00928     return -1;
00929   }
00930 
00931   return msg.cs;
00932 }
00933 
00934 /* 角度判定 */
00935 int YPSpur_md_near_ang(YPSpur *spur, int cs, double th, double d)
00936 {
00937   YPSpur_msg msg;
00938   int len;
00939 
00940   msg.msg_type = YPSPUR_MSG_CMD;
00941   msg.pid = spur->pid;
00942   msg.type = YPSPUR_NEAR_ANG;
00943   msg.data[0] = th;
00944   msg.data[1] = d;
00945   msg.cs = cs;
00946   if (spur->dev.send(&spur->dev, &msg) < 0)
00947   {
00948     /* error */
00949     spur->connection_error = 1;
00950     return -1;
00951   }
00952 
00953   /* 指定のコマンド受け取り */
00954   len = spur->dev.recv(&spur->dev, &msg);
00955   if (len < 0)
00956   {
00957     /* receive error */
00958     spur->connection_error = 1;
00959     return -1;
00960   }
00961 
00962   return msg.cs;
00963 }
00964 
00965 /* 領域判定 */
00966 int YPSpur_md_over_line(YPSpur *spur, int cs, double x, double y, double theta)
00967 {
00968   YPSpur_msg msg;
00969   int len;
00970 
00971   msg.msg_type = YPSPUR_MSG_CMD;
00972   msg.pid = spur->pid;
00973   msg.type = YPSPUR_OVER_LINE;
00974   msg.data[0] = x;
00975   msg.data[1] = y;
00976   msg.data[2] = theta;
00977   msg.cs = cs;
00978   if (spur->dev.send(&spur->dev, &msg) < 0)
00979   {
00980     /* error */
00981     spur->connection_error = 1;
00982     return -1;
00983   }
00984 
00985   /* 指定のコマンド受け取り */
00986   len = spur->dev.recv(&spur->dev, &msg);
00987   if (len < 0)
00988   {
00989     /* receive error */
00990     spur->connection_error = 1;
00991     return -1;
00992   }
00993 
00994   return msg.cs;
00995 }
00996 
00997 /* アナログ値取得 */
00998 int YP_md_get_ad_value(YPSpur *spur, int num)
00999 {
01000   YPSpur_msg msg;
01001   int len;
01002   int ret;
01003 
01004   msg.msg_type = YPSPUR_MSG_CMD;
01005   msg.pid = spur->pid;
01006   msg.type = YPSPUR_GETAD;
01007   msg.cs = 0;
01008   msg.data[0] = (double)num;
01009   if (spur->dev.send(&spur->dev, &msg) < 0)
01010   {
01011     /* error */
01012     spur->connection_error = 1;
01013     return -1;
01014   }
01015 
01016   /* 指定のコマンド受け取り */
01017   len = spur->dev.recv(&spur->dev, &msg);
01018   if (len < 0)
01019   {
01020     /* receive error */
01021     spur->connection_error = 1;
01022     return -1;
01023   }
01024 
01025   ret = (int)msg.data[0];
01026   return ret;
01027 }
01028 
01029 int YP_md_set_io_dir(YPSpur *spur, unsigned char dir)
01030 {
01031   YPSpur_msg msg;
01032 
01033   msg.msg_type = YPSPUR_MSG_CMD;
01034   msg.pid = spur->pid;
01035   msg.type = YPSPUR_SETIODIR;
01036   msg.data[0] = dir;
01037 
01038   if (spur->dev.send(&spur->dev, &msg) < 0)
01039   {
01040     /* error */
01041     spur->connection_error = 1;
01042     return -1;
01043   }
01044 
01045   return 1;
01046 }
01047 
01048 int YP_md_set_io_data(YPSpur *spur, unsigned char data)
01049 {
01050   YPSpur_msg msg;
01051 
01052   msg.msg_type = YPSPUR_MSG_CMD;
01053   msg.pid = spur->pid;
01054   msg.type = YPSPUR_SETIODATA;
01055   msg.data[0] = data;
01056 
01057   if (spur->dev.send(&spur->dev, &msg) < 0)
01058   {
01059     /* error */
01060     spur->connection_error = 1;
01061     return -1;
01062   }
01063 
01064   return 1;
01065 }
01066 
01067 /* 直接タイヤ回転速度入力 */
01068 int YP_md_wheel_vel(YPSpur *spur, double r, double l)
01069 {
01070   YPSpur_msg msg;
01071 
01072   msg.msg_type = YPSPUR_MSG_CMD;
01073   msg.pid = spur->pid;
01074   msg.type = YPSPUR_WHEEL_VEL;
01075   msg.data[0] = r;
01076   msg.data[1] = l;
01077 
01078   if (spur->dev.send(&spur->dev, &msg) < 0)
01079   {
01080     /* error */
01081     spur->connection_error = 1;
01082     return -1;
01083   }
01084 
01085   return 1;
01086 }
01087 
01088 int YP_md_wheel_torque(YPSpur *spur, double r, double l)
01089 {
01090   YPSpur_msg msg;
01091 
01092   msg.msg_type = YPSPUR_MSG_CMD;
01093   msg.pid = spur->pid;
01094   msg.type = YPSPUR_WHEEL_TORQUE;
01095   msg.data[0] = r;
01096   msg.data[1] = l;
01097 
01098   if (spur->dev.send(&spur->dev, &msg) < 0)
01099   {
01100     /* error */
01101     spur->connection_error = 1;
01102     return -1;
01103   }
01104 
01105   return 1;
01106 }
01107 
01108 int YP_md_set_wheel_vel(YPSpur *spur, double r, double l)
01109 {
01110   YPSpur_msg msg;
01111 
01112   msg.msg_type = YPSPUR_MSG_CMD;
01113   msg.pid = spur->pid;
01114   msg.type = YPSPUR_SET_WHEEL_VEL;
01115   msg.data[0] = r;
01116   msg.data[1] = l;
01117 
01118   if (spur->dev.send(&spur->dev, &msg) < 0)
01119   {
01120     /* error */
01121     spur->connection_error = 1;
01122     return -1;
01123   }
01124 
01125   return 1;
01126 }
01127 
01128 int YP_md_set_wheel_accel(YPSpur *spur, double r, double l)
01129 {
01130   YPSpur_msg msg;
01131 
01132   msg.msg_type = YPSPUR_MSG_CMD;
01133   msg.pid = spur->pid;
01134   msg.type = YPSPUR_SET_WHEEL_ACCEL;
01135   msg.data[0] = r;
01136   msg.data[1] = l;
01137 
01138   if (spur->dev.send(&spur->dev, &msg) < 0)
01139   {
01140     /* error */
01141     spur->connection_error = 1;
01142     return -1;
01143   }
01144 
01145   return 1;
01146 }
01147 
01148 int YP_md_wheel_ang(YPSpur *spur, double r, double l)
01149 {
01150   YPSpur_msg msg;
01151 
01152   msg.msg_type = YPSPUR_MSG_CMD;
01153   msg.pid = spur->pid;
01154   msg.type = YPSPUR_WHEEL_ANGLE;
01155   msg.data[0] = r;
01156   msg.data[1] = l;
01157 
01158   if (spur->dev.send(&spur->dev, &msg) < 0)
01159   {
01160     /* error */
01161     spur->connection_error = 1;
01162     return -1;
01163   }
01164 
01165   return 1;
01166 }
01167 
01168 int YP_md_joint_torque(YPSpur *spur, int id, double t)
01169 {
01170   YPSpur_msg msg;
01171 
01172   msg.msg_type = YPSPUR_MSG_CMD;
01173   msg.pid = spur->pid;
01174   msg.type = YPSPUR_JOINT_TORQUE;
01175   msg.cs = id;
01176   msg.data[0] = t;
01177 
01178   if (spur->dev.send(&spur->dev, &msg) < 0)
01179   {
01180     /* error */
01181     spur->connection_error = 1;
01182     return -1;
01183   }
01184 
01185   return 1;
01186 }
01187 
01188 int YP_md_joint_vel(YPSpur *spur, int id, double v)
01189 {
01190   YPSpur_msg msg;
01191 
01192   msg.msg_type = YPSPUR_MSG_CMD;
01193   msg.pid = spur->pid;
01194   msg.type = YPSPUR_JOINT_VEL;
01195   msg.cs = id;
01196   msg.data[0] = v;
01197 
01198   if (spur->dev.send(&spur->dev, &msg) < 0)
01199   {
01200     /* error */
01201     spur->connection_error = 1;
01202     return -1;
01203   }
01204 
01205   return 1;
01206 }
01207 
01208 int YP_md_joint_ang(YPSpur *spur, int id, double a)
01209 {
01210   YPSpur_msg msg;
01211 
01212   msg.msg_type = YPSPUR_MSG_CMD;
01213   msg.pid = spur->pid;
01214   msg.type = YPSPUR_JOINT_ANG;
01215   msg.cs = id;
01216   msg.data[0] = a;
01217 
01218   if (spur->dev.send(&spur->dev, &msg) < 0)
01219   {
01220     /* error */
01221     spur->connection_error = 1;
01222     return -1;
01223   }
01224 
01225   return 1;
01226 }
01227 
01228 int YP_md_joint_ang_vel(YPSpur *spur, int id, double a, double v)
01229 {
01230   YPSpur_msg msg;
01231 
01232   msg.msg_type = YPSPUR_MSG_CMD;
01233   msg.pid = spur->pid;
01234   msg.type = YPSPUR_JOINT_ANG_VEL;
01235   msg.cs = id;
01236   msg.data[0] = a;
01237   msg.data[1] = v;
01238 
01239   if (spur->dev.send(&spur->dev, &msg) < 0)
01240   {
01241     /* error */
01242     spur->connection_error = 1;
01243     return -1;
01244   }
01245 
01246   return 1;
01247 }
01248 
01249 int YP_md_set_joint_accel(YPSpur *spur, int id, double a)
01250 {
01251   YPSpur_msg msg;
01252 
01253   msg.msg_type = YPSPUR_MSG_CMD;
01254   msg.pid = spur->pid;
01255   msg.type = YPSPUR_SET_JOINT_ACCEL;
01256   msg.cs = id;
01257   msg.data[0] = a;
01258 
01259   if (spur->dev.send(&spur->dev, &msg) < 0)
01260   {
01261     /* error */
01262     spur->connection_error = 1;
01263     return -1;
01264   }
01265 
01266   return 1;
01267 }
01268 
01269 int YP_md_set_joint_vel(YPSpur *spur, int id, double v)
01270 {
01271   YPSpur_msg msg;
01272 
01273   msg.msg_type = YPSPUR_MSG_CMD;
01274   msg.pid = spur->pid;
01275   msg.type = YPSPUR_SET_JOINT_VEL;
01276   msg.cs = id;
01277   msg.data[0] = v;
01278 
01279   if (spur->dev.send(&spur->dev, &msg) < 0)
01280   {
01281     /* error */
01282     spur->connection_error = 1;
01283     return -1;
01284   }
01285 
01286   return 1;
01287 }
01288 
01289 double YP_md_get_joint_vel(YPSpur *spur, int id, double *v)
01290 {
01291   YPSpur_msg msg;
01292   int len;
01293   double time;
01294 
01295   msg.msg_type = YPSPUR_MSG_CMD;
01296   msg.pid = spur->pid;
01297   msg.type = YPSPUR_GET_JOINT_VEL;
01298   msg.cs = id;
01299   if (spur->dev.send(&spur->dev, &msg) < 0)
01300   {
01301     /* error */
01302     spur->connection_error = 1;
01303     return -1;
01304   }
01305 
01306   /* 指定のコマンド受け取り */
01307   len = spur->dev.recv(&spur->dev, &msg);
01308   if (len < 0)
01309   {
01310     /* receive error */
01311     spur->connection_error = 1;
01312     return -1;
01313   }
01314 
01315   *v = msg.data[0];
01316   time = msg.data[1];
01317   return time;
01318 }
01319 
01320 double YP_md_get_joint_vref(YPSpur *spur, int id, double *v)
01321 {
01322   YPSpur_msg msg;
01323   int len;
01324   double time;
01325 
01326   msg.msg_type = YPSPUR_MSG_CMD;
01327   msg.pid = spur->pid;
01328   msg.type = YPSPUR_GET_JOINT_VREF;
01329   msg.cs = id;
01330   if (spur->dev.send(&spur->dev, &msg) < 0)
01331   {
01332     /* error */
01333     spur->connection_error = 1;
01334     return -1;
01335   }
01336 
01337   /* 指定のコマンド受け取り */
01338   len = spur->dev.recv(&spur->dev, &msg);
01339   if (len < 0)
01340   {
01341     /* receive error */
01342     spur->connection_error = 1;
01343     return -1;
01344   }
01345 
01346   *v = msg.data[0];
01347   time = msg.data[1];
01348   return time;
01349 }
01350 
01351 double YP_md_get_joint_ang(YPSpur *spur, int id, double *a)
01352 {
01353   YPSpur_msg msg;
01354   int len;
01355   double time;
01356 
01357   msg.msg_type = YPSPUR_MSG_CMD;
01358   msg.pid = spur->pid;
01359   msg.type = YPSPUR_GET_JOINT_ANG;
01360   msg.cs = id;
01361   if (spur->dev.send(&spur->dev, &msg) < 0)
01362   {
01363     /* error */
01364     spur->connection_error = 1;
01365     return -1;
01366   }
01367 
01368   /* 指定のコマンド受け取り */
01369   len = spur->dev.recv(&spur->dev, &msg);
01370   if (len < 0)
01371   {
01372     /* receive error */
01373     spur->connection_error = 1;
01374     return -1;
01375   }
01376 
01377   *a = msg.data[0];
01378   time = msg.data[1];
01379   return time;
01380 }
01381 
01382 double YP_md_get_joint_torque(YPSpur *spur, int id, double *t)
01383 {
01384   YPSpur_msg msg;
01385   int len;
01386   double time;
01387 
01388   msg.msg_type = YPSPUR_MSG_CMD;
01389   msg.pid = spur->pid;
01390   msg.type = YPSPUR_GET_JOINT_TORQUE;
01391   msg.cs = id;
01392   if (spur->dev.send(&spur->dev, &msg) < 0)
01393   {
01394     /* error */
01395     spur->connection_error = 1;
01396     return -1;
01397   }
01398 
01399   /* 指定のコマンド受け取り */
01400   len = spur->dev.recv(&spur->dev, &msg);
01401   if (len < 0)
01402   {
01403     /* receive error */
01404     spur->connection_error = 1;
01405     return -1;
01406   }
01407 
01408   *t = msg.data[0];
01409   time = msg.data[1];
01410   return time;
01411 }
01412 
01413 ParamOutputLv output_lv(void)
01414 {
01415   return OUTPUT_LV_INFO;
01416 }


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