libypspur-md.c
Go to the documentation of this file.
1 // Copyright (c) 2010-2016 The YP-Spur Authors, except where otherwise indicated.
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to
5 // deal in the Software without restriction, including without limitation the
6 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7 // sell copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 // SOFTWARE.
20 
21 /*
22  * YP-Spurとの通信ライブラリ複数デバイス対応版 Communication Library for YP-Spur
23  */
24 
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <unistd.h>
29 
30 #include <sys/types.h>
31 
32 #ifdef HAVE_CONFIG_H
33 #include <config.h>
34 #endif // HAVE_CONFIG_H
35 
36 #define YP_SPUR_RUNTIME
37 
38 #include <ipcommunication.h>
39 #include <ypspur-md.h>
40 #include <param.h>
41 
42 /* エラー確認 */
44 {
45  return spur->dev.connection_error;
46 }
47 
48 double YP_md_get_device_error_state(YPSpur *spur, int id, int *error_state)
49 {
50  YPSpur_msg msg;
51  int len;
52  double time;
53 
55  msg.pid = spur->pid;
57  msg.data[0] = id;
58  msg.cs = 0;
59  if (spur->dev.send(&spur->dev, &msg) < 0)
60  {
61  /* error */
62  spur->connection_error = 1;
63  return -1;
64  }
65 
66  /* 指定のコマンド受け取り */
67  len = spur->dev.recv(&spur->dev, &msg);
68  if (len < 0)
69  {
70  /* receive error */
71  spur->connection_error = 1;
72  return -1;
73  }
74 
75  *error_state = (int)msg.data[0];
76  time = msg.data[1];
77  return time;
78 }
79 
80 /* coordinatorとのメッセージ通信を開始する */
81 int YPSpur_md_initex(YPSpur *spur, int msq_key)
82 {
83  /* メッセージ・キューのオープン */
84  if (ipcmd_open_msq(&spur->dev, msq_key, 0) < 0)
85  {
86  return -1;
87  }
88 
89  spur->pid = spur->dev.pid;
90 
91  return 1;
92 }
93 
94 int YPSpur_md_init_socket(YPSpur *spur, char *ip, int port)
95 {
96  /* メッセージ・キューのオープン */
97  if (ipcmd_open_tcp(&spur->dev, ip, port) < 0)
98  {
99  return -1;
100  }
101 
102  spur->pid = spur->dev.pid;
103 
104  return 1;
105 }
106 
107 /* coordinatorとのメッセージ通信を開始する */
109 {
110  return YPSpur_md_initex(spur, YPSPUR_MSQ_KEY);
111 }
112 
113 /* 直線追従 */
114 int YPSpur_md_line(YPSpur *spur, int cs, double x, double y, double theta)
115 {
116  YPSpur_msg msg;
117 
118  msg.msg_type = YPSPUR_MSG_CMD;
119  msg.pid = spur->pid;
120  msg.type = YPSPUR_LINE;
121  msg.data[0] = x;
122  msg.data[1] = y;
123  msg.data[2] = theta;
124  msg.cs = cs;
125 
126  if (spur->dev.send(&spur->dev, &msg) < 0)
127  {
128  /* error */
129  spur->connection_error = 1;
130  return -1;
131  }
132  return 1;
133 }
134 
135 /* 直線追従 */
136 int YPSpur_md_stop_line(YPSpur *spur, int cs, double x, double y, double theta)
137 {
138  YPSpur_msg msg;
139 
140  msg.msg_type = YPSPUR_MSG_CMD;
141  msg.pid = spur->pid;
142  msg.type = YPSPUR_STOP_LINE;
143  msg.data[0] = x;
144  msg.data[1] = y;
145  msg.data[2] = theta;
146  msg.cs = cs;
147 
148  if (spur->dev.send(&spur->dev, &msg) < 0)
149  {
150  /* error */
151  spur->connection_error = 1;
152  return -1;
153  }
154  return 1;
155 }
156 
157 /* 円弧追従 */
158 int YPSpur_md_circle(YPSpur *spur, int cs, double x, double y, double r)
159 {
160  YPSpur_msg msg;
161 
162  msg.msg_type = YPSPUR_MSG_CMD;
163  msg.pid = spur->pid;
164  msg.type = YPSPUR_CIRCLE;
165  msg.data[0] = x;
166  msg.data[1] = y;
167  msg.data[2] = r;
168  msg.cs = cs;
169  if (spur->dev.send(&spur->dev, &msg) < 0)
170  {
171  /* error */
172  spur->connection_error = 1;
173  return -1;
174  }
175 
176  return 1;
177 }
178 
179 /* 旋回 */
180 int YPSpur_md_spin(YPSpur *spur, int cs, double theta)
181 {
182  YPSpur_msg msg;
183 
184  msg.msg_type = YPSPUR_MSG_CMD;
185  msg.pid = spur->pid;
186  msg.type = YPSPUR_SPIN;
187  msg.data[0] = theta;
188  msg.cs = cs;
189  if (spur->dev.send(&spur->dev, &msg) < 0)
190  {
191  /* error */
192  spur->connection_error = 1;
193  return -1;
194  }
195 
196  return 1;
197 }
198 
199 /* 方位 */
200 int YPSpur_md_orient(YPSpur *spur, int cs, double theta)
201 {
202  YPSpur_msg msg;
203 
204  msg.msg_type = YPSPUR_MSG_CMD;
205  msg.pid = spur->pid;
206  msg.type = YPSPUR_ORIENT;
207  msg.data[0] = theta;
208  msg.cs = cs;
209  if (spur->dev.send(&spur->dev, &msg) < 0)
210  {
211  /* error */
212  spur->connection_error = 1;
213  return -1;
214  }
215 
216  return 1;
217 }
218 
219 /* 急ブレーキ */
221 {
222  YPSpur_msg msg;
223 
224  msg.msg_type = YPSPUR_MSG_CMD;
225  msg.pid = spur->pid;
226  msg.type = YPSPUR_STOP;
227 
228  if (spur->dev.send(&spur->dev, &msg) < 0)
229  {
230  /* error */
231  spur->connection_error = 1;
232  return -1;
233  }
234 
235  return 1;
236 }
237 
238 /* 緊急停止 */
240 {
241  YPSpur_msg msg;
242 
243  msg.msg_type = YPSPUR_MSG_CMD;
244  msg.pid = spur->pid;
245  msg.type = YPSPUR_FREEZE;
246 
247  if (spur->dev.send(&spur->dev, &msg) < 0)
248  {
249  /* error */
250  spur->connection_error = 1;
251  return -1;
252  }
253 
254  return 1;
255 }
256 
257 /* 緊急停止解除 */
259 {
260  YPSpur_msg msg;
261 
262  msg.msg_type = YPSPUR_MSG_CMD;
263  msg.pid = spur->pid;
264  msg.type = YPSPUR_UNFREEZE;
265 
266  if (spur->dev.send(&spur->dev, &msg) < 0)
267  {
268  /* error */
269  spur->connection_error = 1;
270  return -1;
271  }
272 
273  return 1;
274 }
275 
276 /* ソフトウェア補助フリーモード */
278 {
279  YPSpur_msg msg;
280 
281  msg.msg_type = YPSPUR_MSG_CMD;
282  msg.pid = spur->pid;
283  msg.type = YPSPUR_FREE;
284 
285  if (spur->dev.send(&spur->dev, &msg) < 0)
286  {
287  /* error */
288  spur->connection_error = 1;
289  return -1;
290  }
291 
292  return 1;
293 }
294 
295 /* 制御なしフリーモード */
297 {
298  YPSpur_msg msg;
299 
300  msg.msg_type = YPSPUR_MSG_CMD;
301  msg.pid = spur->pid;
302  msg.type = YPSPUR_OPENFREE;
303 
304  if (spur->dev.send(&spur->dev, &msg) < 0)
305  {
306  /* error */
307  spur->connection_error = 1;
308  return -1;
309  }
310 
311  return 1;
312 }
313 
314 /* 位置指定 */
315 int YPSpur_md_set_pos(YPSpur *spur, int cs, double x, double y, double theta)
316 {
317  YPSpur_msg msg;
318 
319  msg.msg_type = YPSPUR_MSG_CMD;
320  msg.pid = spur->pid;
321  msg.type = YPSPUR_SET_POS;
322  msg.data[0] = x;
323  msg.data[1] = y;
324  msg.data[2] = theta;
325  msg.cs = cs;
326 
327  if (spur->dev.send(&spur->dev, &msg) < 0)
328  {
329  /* error */
330  spur->connection_error = 1;
331  return -1;
332  }
333  return 1;
334 }
335 
336 /* 位置指定 */
337 int YPSpur_md_adjust_pos(YPSpur *spur, int cs, double x, double y, double theta)
338 {
339  YPSpur_msg msg;
340 
341  msg.msg_type = YPSPUR_MSG_CMD;
342  msg.pid = spur->pid;
343  msg.type = YPSPUR_ADJUST;
344  msg.data[0] = x;
345  msg.data[1] = y;
346  msg.data[2] = theta;
347  msg.cs = cs;
348 
349  if (spur->dev.send(&spur->dev, &msg) < 0)
350  {
351  /* error */
352  spur->connection_error = 1;
353  return -1;
354  }
355  return 1;
356 }
357 
358 /* 速度指定 */
360 {
361  YPSpur_msg msg;
362 
363  msg.msg_type = YPSPUR_MSG_CMD;
364  msg.pid = spur->pid;
365  msg.type = YPSPUR_SET_VEL;
366  msg.data[0] = v;
367 
368  if (spur->dev.send(&spur->dev, &msg) < 0)
369  {
370  /* error */
371  spur->connection_error = 1;
372  return -1;
373  }
374 
375  return 1;
376 }
377 
378 /* 角速度指定 */
380 {
381  YPSpur_msg msg;
382 
383  msg.msg_type = YPSPUR_MSG_CMD;
384  msg.pid = spur->pid;
385  msg.type = YPSPUR_SET_ANGVEL;
386  msg.data[0] = w;
387 
388  if (spur->dev.send(&spur->dev, &msg) < 0)
389  {
390  /* error */
391  spur->connection_error = 1;
392  return -1;
393  }
394 
395  return 1;
396 }
397 
398 /* 速度指定 */
400 {
401  YPSpur_msg msg;
402 
403  msg.msg_type = YPSPUR_MSG_CMD;
404  msg.pid = spur->pid;
405  msg.type = YPSPUR_SET_ACCEL;
406  msg.data[0] = dv;
407 
408  if (spur->dev.send(&spur->dev, &msg) < 0)
409  {
410  /* error */
411  spur->connection_error = 1;
412  return -1;
413  }
414 
415  return 1;
416 }
417 
418 /* 角速度指定 */
420 {
421  YPSpur_msg msg;
422 
423  msg.msg_type = YPSPUR_MSG_CMD;
424  msg.pid = spur->pid;
426  msg.data[0] = dw;
427 
428  if (spur->dev.send(&spur->dev, &msg) < 0)
429  {
430  /* error */
431  spur->connection_error = 1;
432  return -1;
433  }
434 
435  return 1;
436 }
437 
438 /* 位置取得 */
439 double YPSpur_md_get_pos(YPSpur *spur, int cs, double *x, double *y, double *theta)
440 {
441  YPSpur_msg msg;
442  int len;
443  double time;
444 
445  msg.msg_type = YPSPUR_MSG_CMD;
446  msg.pid = spur->pid;
447  msg.type = YPSPUR_GET_POS;
448  msg.cs = cs;
449  if (spur->dev.send(&spur->dev, &msg) < 0)
450  {
451  /* error */
452  spur->connection_error = 1;
453  return -1;
454  }
455 
456  /* 指定のコマンド受け取り */
457  len = spur->dev.recv(&spur->dev, &msg);
458  if (len < 0)
459  {
460  /* receive error */
461  spur->connection_error = 1;
462  return -1;
463  }
464 
465  *x = msg.data[0];
466  *y = msg.data[1];
467  *theta = msg.data[2];
468  time = msg.data[3];
469  return time;
470 }
471 
472 /* 速度取得 */
473 double YPSpur_md_get_vel(YPSpur *spur, double *v, double *w)
474 {
475  YPSpur_msg msg;
476  int len;
477  double time;
478 
479  msg.msg_type = YPSPUR_MSG_CMD;
480  msg.pid = spur->pid;
481  msg.type = YPSPUR_GET_VEL;
482  msg.cs = 0;
483  if (spur->dev.send(&spur->dev, &msg) < 0)
484  {
485  /* error */
486  spur->connection_error = 1;
487  return -1;
488  }
489 
490  /* 指定のコマンド受け取り */
491  len = spur->dev.recv(&spur->dev, &msg);
492  if (len < 0)
493  {
494  /* receive error */
495  spur->connection_error = 1;
496  return -1;
497  }
498 
499  *v = msg.data[0];
500  *w = msg.data[1];
501  time = msg.data[2];
502  return time;
503 }
504 
505 /* 速度取得 */
506 double YP_md_get_vref(YPSpur *spur, double *v, double *w)
507 {
508  YPSpur_msg msg;
509  int len;
510  double time;
511 
512  msg.msg_type = YPSPUR_MSG_CMD;
513  msg.pid = spur->pid;
514  msg.type = YPSPUR_GET_VREF;
515  msg.cs = 0;
516  if (spur->dev.send(&spur->dev, &msg) < 0)
517  {
518  /* error */
519  spur->connection_error = 1;
520  return -1;
521  }
522 
523  /* 指定のコマンド受け取り */
524  len = spur->dev.recv(&spur->dev, &msg);
525  if (len < 0)
526  {
527  /* receive error */
528  spur->connection_error = 1;
529  return -1;
530  }
531 
532  *v = msg.data[0];
533  *w = msg.data[1];
534  time = msg.data[2];
535  return time;
536 }
537 
538 /* 速度取得 */
539 double YP_md_get_wheel_vref(YPSpur *spur, double *wr, double *wl)
540 {
541  YPSpur_msg msg;
542  int len;
543  double time;
544 
545  msg.msg_type = YPSPUR_MSG_CMD;
546  msg.pid = spur->pid;
548  msg.cs = 0;
549  if (spur->dev.send(&spur->dev, &msg) < 0)
550  {
551  /* error */
552  spur->connection_error = 1;
553  return -1;
554  }
555 
556  /* 指定のコマンド受け取り */
557  len = spur->dev.recv(&spur->dev, &msg);
558  if (len < 0)
559  {
560  /* receive error */
561  spur->connection_error = 1;
562  return -1;
563  }
564 
565  *wr = msg.data[0];
566  *wl = msg.data[1];
567  time = msg.data[2];
568  return time;
569 }
570 
571 /* 速度取得 */
572 double YP_md_get_wheel_vel(YPSpur *spur, double *wr, double *wl)
573 {
574  YPSpur_msg msg;
575  int len;
576  double time;
577 
578  msg.msg_type = YPSPUR_MSG_CMD;
579  msg.pid = spur->pid;
581  msg.cs = 0;
582  if (spur->dev.send(&spur->dev, &msg) < 0)
583  {
584  /* error */
585  spur->connection_error = 1;
586  return -1;
587  }
588 
589  /* 指定のコマンド受け取り */
590  len = spur->dev.recv(&spur->dev, &msg);
591  if (len < 0)
592  {
593  /* receive error */
594  spur->connection_error = 1;
595  return -1;
596  }
597 
598  *wr = msg.data[0];
599  *wl = msg.data[1];
600  time = msg.data[2];
601  return time;
602 }
603 
604 /* 角度取得 */
605 double YP_md_get_wheel_ang(YPSpur *spur, double *theta_r, double *theta_l)
606 {
607  YPSpur_msg msg;
608  int len;
609  double time;
610 
611  msg.msg_type = YPSPUR_MSG_CMD;
612  msg.pid = spur->pid;
614  msg.cs = 0;
615  if (spur->dev.send(&spur->dev, &msg) < 0)
616  {
617  /* error */
618  spur->connection_error = 1;
619  return -1;
620  }
621 
622  /* 指定のコマンド受け取り */
623  len = spur->dev.recv(&spur->dev, &msg);
624  if (len < 0)
625  {
626  /* receive error */
627  spur->connection_error = 1;
628  return -1;
629  }
630 
631  *theta_r = msg.data[0];
632  *theta_l = msg.data[1];
633  time = msg.data[2];
634  return time;
635 }
636 
637 /* トルク取得 */
638 double YP_md_get_wheel_torque(YPSpur *spur, double *torque_r, double *torque_l)
639 {
640  YPSpur_msg msg;
641  int len;
642  double time;
643 
644  msg.msg_type = YPSPUR_MSG_CMD;
645  msg.pid = spur->pid;
647  msg.cs = 0;
648  if (spur->dev.send(&spur->dev, &msg) < 0)
649  {
650  /* error */
651  spur->connection_error = 1;
652  return -1;
653  }
654 
655  /* 指定のコマンド受け取り */
656  len = spur->dev.recv(&spur->dev, &msg);
657  if (len < 0)
658  {
659  /* receive error */
660  spur->connection_error = 1;
661  return -1;
662  }
663 
664  *torque_r = msg.data[0];
665  *torque_l = msg.data[1];
666  time = msg.data[2];
667  return time;
668 }
669 
670 /* 力取得 */
671 double YPSpur_md_get_force(YPSpur *spur, double *trans, double *angular)
672 {
673  YPSpur_msg msg;
674  int len;
675  double time;
676 
677  msg.msg_type = YPSPUR_MSG_CMD;
678  msg.pid = spur->pid;
679  msg.type = YPSPUR_GET_FORCE;
680  msg.cs = 0;
681  if (spur->dev.send(&spur->dev, &msg) < 0)
682  {
683  /* error */
684  spur->connection_error = 1;
685  return -1;
686  }
687 
688  /* 指定のコマンド受け取り */
689  len = spur->dev.recv(&spur->dev, &msg);
690  if (len < 0)
691  {
692  /* receive error */
693  spur->connection_error = 1;
694  return -1;
695  }
696 
697  *trans = msg.data[0];
698  *angular = msg.data[1];
699  time = msg.data[2];
700  return time;
701 }
702 
703 /* 緊急停止状態取得 */
705 {
706  YPSpur_msg msg;
707  int len;
708  int ret;
709 
710  msg.msg_type = YPSPUR_MSG_CMD;
711  msg.pid = spur->pid;
712  msg.type = YPSPUR_ISFREEZE;
713  msg.cs = 0;
714  if (spur->dev.send(&spur->dev, &msg) < 0)
715  {
716  /* error */
717  spur->connection_error = 1;
718  return -1;
719  }
720 
721  /* 指定のコマンド受け取り */
722  len = spur->dev.recv(&spur->dev, &msg);
723  if (len < 0)
724  {
725  /* receive error */
726  spur->connection_error = 1;
727  return -1;
728  }
729 
730  ret = (int)msg.data[0];
731  return ret;
732 }
733 
734 /* 直接速度入力 */
735 int YPSpur_md_vel(YPSpur *spur, double v, double w)
736 {
737  YPSpur_msg msg;
738 
739  msg.msg_type = YPSPUR_MSG_CMD;
740  msg.pid = spur->pid;
741  msg.type = YPSPUR_VEL;
742  msg.data[0] = v;
743  msg.data[1] = w;
744 
745  if (spur->dev.send(&spur->dev, &msg) < 0)
746  {
747  /* error */
748  spur->connection_error = 1;
749  return -1;
750  }
751 
752  return 1;
753 }
754 
755 /* 内部パラメータの変更 */
756 int YP_md_set_parameter(YPSpur *spur, int param_id, double value)
757 {
758  YPSpur_msg msg;
759 
760  msg.msg_type = YPSPUR_MSG_CMD;
761  msg.pid = spur->pid;
762  msg.type = YPSPUR_PARAM_SET;
763  msg.cs = param_id;
764  msg.data[0] = value;
765  msg.data[1] = value;
766 
767  if (spur->dev.send(&spur->dev, &msg) < 0)
768  {
769  /* error */
770  spur->connection_error = 1;
771  return -1;
772  }
773 
774  return 1;
775 }
776 
777 /* 内部パラメータの変更 */
778 int YP_md_set_parameter_array(YPSpur *spur, int param_id, double *value)
779 {
780  YPSpur_msg msg;
781 
782  msg.msg_type = YPSPUR_MSG_CMD;
783  msg.pid = spur->pid;
784  msg.type = YPSPUR_PARAM_SET;
785  msg.cs = param_id;
786  msg.data[0] = value[0];
787  msg.data[1] = value[1];
788 
789  if (spur->dev.send(&spur->dev, &msg) < 0)
790  {
791  /* error */
792  spur->connection_error = 1;
793  return -1;
794  }
795 
796  return 1;
797 }
798 
799 /* 内部パラメータの取得 */
800 int YP_md_get_parameter(YPSpur *spur, int param_id, double *value)
801 {
802  YPSpur_msg msg;
803  int len;
804 
805  msg.msg_type = YPSPUR_MSG_CMD;
806  msg.pid = spur->pid;
807  msg.type = YPSPUR_PARAM_GET;
808  msg.cs = param_id;
809  if (spur->dev.send(&spur->dev, &msg) < 0)
810  {
811  /* error */
812  spur->connection_error = 1;
813  return -1;
814  }
815 
816  /* 指定のコマンド受け取り */
817  len = spur->dev.recv(&spur->dev, &msg);
818  if (len < 0)
819  {
820  /* receive error */
821  spur->connection_error = 1;
822  return -1;
823  }
824 
825  *value = msg.data[0];
826  return msg.cs;
827 }
828 
829 int YP_md_get_parameter_array(YPSpur *spur, int param_id, double *value)
830 {
831  YPSpur_msg msg;
832  int len;
833 
834  msg.msg_type = YPSPUR_MSG_CMD;
835  msg.pid = spur->pid;
836  msg.type = YPSPUR_PARAM_GET;
837  msg.cs = param_id;
838  if (spur->dev.send(&spur->dev, &msg) < 0)
839  {
840  /* error */
841  spur->connection_error = 1;
842  return -1;
843  }
844 
845  /* 指定のコマンド受け取り */
846  len = spur->dev.recv(&spur->dev, &msg);
847  if (len < 0)
848  {
849  /* receive error */
850  spur->connection_error = 1;
851  return -1;
852  }
853 
854  value[0] = msg.data[0];
855  value[1] = msg.data[1];
856  return msg.cs;
857 }
858 
859 /* 内部状態の変更 */
860 int YP_md_set_control_state(YPSpur *spur, int control_id, int state)
861 {
862  YPSpur_msg msg;
863 
864  msg.msg_type = YPSPUR_MSG_CMD;
865  msg.pid = spur->pid;
866  msg.type = YPSPUR_PARAM_STATE;
867  msg.cs = control_id;
868  msg.data[0] = state;
869 
870  if (spur->dev.send(&spur->dev, &msg) < 0)
871  {
872  /* error */
873  spur->connection_error = 1;
874  return -1;
875  }
876 
877  return 1;
878 }
879 
880 /* 重力補償用地面の傾き指定 */
881 int YPSpur_md_tilt(YPSpur *spur, int cs, double dir, double tilt)
882 {
883  YPSpur_msg msg;
884 
885  msg.msg_type = YPSPUR_MSG_CMD;
886  msg.pid = spur->pid;
887  msg.type = YPSPUR_SET_TILT;
888  msg.data[0] = dir;
889  msg.data[1] = tilt;
890  msg.cs = cs;
891 
892  if (spur->dev.send(&spur->dev, &msg) < 0)
893  {
894  /* error */
895  spur->connection_error = 1;
896  return -1;
897  }
898 
899  return 1;
900 }
901 
902 /* 位置判定 */
903 int YPSpur_md_near_pos(YPSpur *spur, int cs, double x, double y, double r)
904 {
905  YPSpur_msg msg;
906  int len;
907 
908  msg.msg_type = YPSPUR_MSG_CMD;
909  msg.pid = spur->pid;
910  msg.type = YPSPUR_NEAR_POS;
911  msg.data[0] = x;
912  msg.data[1] = y;
913  msg.data[2] = r;
914  msg.cs = cs;
915  if (spur->dev.send(&spur->dev, &msg) < 0)
916  {
917  /* error */
918  spur->connection_error = 1;
919  return -1;
920  }
921 
922  /* 指定のコマンド受け取り */
923  len = spur->dev.recv(&spur->dev, &msg);
924  if (len < 0)
925  {
926  /* receive error */
927  spur->connection_error = 1;
928  return -1;
929  }
930 
931  return msg.cs;
932 }
933 
934 /* 角度判定 */
935 int YPSpur_md_near_ang(YPSpur *spur, int cs, double th, double d)
936 {
937  YPSpur_msg msg;
938  int len;
939 
940  msg.msg_type = YPSPUR_MSG_CMD;
941  msg.pid = spur->pid;
942  msg.type = YPSPUR_NEAR_ANG;
943  msg.data[0] = th;
944  msg.data[1] = d;
945  msg.cs = cs;
946  if (spur->dev.send(&spur->dev, &msg) < 0)
947  {
948  /* error */
949  spur->connection_error = 1;
950  return -1;
951  }
952 
953  /* 指定のコマンド受け取り */
954  len = spur->dev.recv(&spur->dev, &msg);
955  if (len < 0)
956  {
957  /* receive error */
958  spur->connection_error = 1;
959  return -1;
960  }
961 
962  return msg.cs;
963 }
964 
965 /* 領域判定 */
966 int YPSpur_md_over_line(YPSpur *spur, int cs, double x, double y, double theta)
967 {
968  YPSpur_msg msg;
969  int len;
970 
971  msg.msg_type = YPSPUR_MSG_CMD;
972  msg.pid = spur->pid;
973  msg.type = YPSPUR_OVER_LINE;
974  msg.data[0] = x;
975  msg.data[1] = y;
976  msg.data[2] = theta;
977  msg.cs = cs;
978  if (spur->dev.send(&spur->dev, &msg) < 0)
979  {
980  /* error */
981  spur->connection_error = 1;
982  return -1;
983  }
984 
985  /* 指定のコマンド受け取り */
986  len = spur->dev.recv(&spur->dev, &msg);
987  if (len < 0)
988  {
989  /* receive error */
990  spur->connection_error = 1;
991  return -1;
992  }
993 
994  return msg.cs;
995 }
996 
997 /* アナログ値取得 */
999 {
1000  YPSpur_msg msg;
1001  int len;
1002  int ret;
1003 
1004  msg.msg_type = YPSPUR_MSG_CMD;
1005  msg.pid = spur->pid;
1006  msg.type = YPSPUR_GETAD;
1007  msg.cs = 0;
1008  msg.data[0] = (double)num;
1009  if (spur->dev.send(&spur->dev, &msg) < 0)
1010  {
1011  /* error */
1012  spur->connection_error = 1;
1013  return -1;
1014  }
1015 
1016  /* 指定のコマンド受け取り */
1017  len = spur->dev.recv(&spur->dev, &msg);
1018  if (len < 0)
1019  {
1020  /* receive error */
1021  spur->connection_error = 1;
1022  return -1;
1023  }
1024 
1025  ret = (int)msg.data[0];
1026  return ret;
1027 }
1028 
1029 int YP_md_set_io_dir(YPSpur *spur, unsigned char dir)
1030 {
1031  YPSpur_msg msg;
1032 
1033  msg.msg_type = YPSPUR_MSG_CMD;
1034  msg.pid = spur->pid;
1035  msg.type = YPSPUR_SETIODIR;
1036  msg.data[0] = dir;
1037 
1038  if (spur->dev.send(&spur->dev, &msg) < 0)
1039  {
1040  /* error */
1041  spur->connection_error = 1;
1042  return -1;
1043  }
1044 
1045  return 1;
1046 }
1047 
1048 int YP_md_set_io_data(YPSpur *spur, unsigned char data)
1049 {
1050  YPSpur_msg msg;
1051 
1052  msg.msg_type = YPSPUR_MSG_CMD;
1053  msg.pid = spur->pid;
1054  msg.type = YPSPUR_SETIODATA;
1055  msg.data[0] = data;
1056 
1057  if (spur->dev.send(&spur->dev, &msg) < 0)
1058  {
1059  /* error */
1060  spur->connection_error = 1;
1061  return -1;
1062  }
1063 
1064  return 1;
1065 }
1066 
1067 /* 直接タイヤ回転速度入力 */
1068 int YP_md_wheel_vel(YPSpur *spur, double r, double l)
1069 {
1070  YPSpur_msg msg;
1071 
1072  msg.msg_type = YPSPUR_MSG_CMD;
1073  msg.pid = spur->pid;
1074  msg.type = YPSPUR_WHEEL_VEL;
1075  msg.data[0] = r;
1076  msg.data[1] = l;
1077 
1078  if (spur->dev.send(&spur->dev, &msg) < 0)
1079  {
1080  /* error */
1081  spur->connection_error = 1;
1082  return -1;
1083  }
1084 
1085  return 1;
1086 }
1087 
1088 int YP_md_wheel_torque(YPSpur *spur, double r, double l)
1089 {
1090  YPSpur_msg msg;
1091 
1092  msg.msg_type = YPSPUR_MSG_CMD;
1093  msg.pid = spur->pid;
1094  msg.type = YPSPUR_WHEEL_TORQUE;
1095  msg.data[0] = r;
1096  msg.data[1] = l;
1097 
1098  if (spur->dev.send(&spur->dev, &msg) < 0)
1099  {
1100  /* error */
1101  spur->connection_error = 1;
1102  return -1;
1103  }
1104 
1105  return 1;
1106 }
1107 
1108 int YP_md_set_wheel_vel(YPSpur *spur, double r, double l)
1109 {
1110  YPSpur_msg msg;
1111 
1112  msg.msg_type = YPSPUR_MSG_CMD;
1113  msg.pid = spur->pid;
1114  msg.type = YPSPUR_SET_WHEEL_VEL;
1115  msg.data[0] = r;
1116  msg.data[1] = l;
1117 
1118  if (spur->dev.send(&spur->dev, &msg) < 0)
1119  {
1120  /* error */
1121  spur->connection_error = 1;
1122  return -1;
1123  }
1124 
1125  return 1;
1126 }
1127 
1128 int YP_md_set_wheel_accel(YPSpur *spur, double r, double l)
1129 {
1130  YPSpur_msg msg;
1131 
1132  msg.msg_type = YPSPUR_MSG_CMD;
1133  msg.pid = spur->pid;
1135  msg.data[0] = r;
1136  msg.data[1] = l;
1137 
1138  if (spur->dev.send(&spur->dev, &msg) < 0)
1139  {
1140  /* error */
1141  spur->connection_error = 1;
1142  return -1;
1143  }
1144 
1145  return 1;
1146 }
1147 
1148 int YP_md_wheel_ang(YPSpur *spur, double r, double l)
1149 {
1150  YPSpur_msg msg;
1151 
1152  msg.msg_type = YPSPUR_MSG_CMD;
1153  msg.pid = spur->pid;
1154  msg.type = YPSPUR_WHEEL_ANGLE;
1155  msg.data[0] = r;
1156  msg.data[1] = l;
1157 
1158  if (spur->dev.send(&spur->dev, &msg) < 0)
1159  {
1160  /* error */
1161  spur->connection_error = 1;
1162  return -1;
1163  }
1164 
1165  return 1;
1166 }
1167 
1168 int YP_md_joint_torque(YPSpur *spur, int id, double t)
1169 {
1170  YPSpur_msg msg;
1171 
1172  msg.msg_type = YPSPUR_MSG_CMD;
1173  msg.pid = spur->pid;
1174  msg.type = YPSPUR_JOINT_TORQUE;
1175  msg.cs = id;
1176  msg.data[0] = t;
1177 
1178  if (spur->dev.send(&spur->dev, &msg) < 0)
1179  {
1180  /* error */
1181  spur->connection_error = 1;
1182  return -1;
1183  }
1184 
1185  return 1;
1186 }
1187 
1188 int YP_md_joint_vel(YPSpur *spur, int id, double v)
1189 {
1190  YPSpur_msg msg;
1191 
1192  msg.msg_type = YPSPUR_MSG_CMD;
1193  msg.pid = spur->pid;
1194  msg.type = YPSPUR_JOINT_VEL;
1195  msg.cs = id;
1196  msg.data[0] = v;
1197 
1198  if (spur->dev.send(&spur->dev, &msg) < 0)
1199  {
1200  /* error */
1201  spur->connection_error = 1;
1202  return -1;
1203  }
1204 
1205  return 1;
1206 }
1207 
1208 int YP_md_joint_ang(YPSpur *spur, int id, double a)
1209 {
1210  YPSpur_msg msg;
1211 
1212  msg.msg_type = YPSPUR_MSG_CMD;
1213  msg.pid = spur->pid;
1214  msg.type = YPSPUR_JOINT_ANG;
1215  msg.cs = id;
1216  msg.data[0] = a;
1217 
1218  if (spur->dev.send(&spur->dev, &msg) < 0)
1219  {
1220  /* error */
1221  spur->connection_error = 1;
1222  return -1;
1223  }
1224 
1225  return 1;
1226 }
1227 
1228 int YP_md_joint_ang_vel(YPSpur *spur, int id, double a, double v)
1229 {
1230  YPSpur_msg msg;
1231 
1232  msg.msg_type = YPSPUR_MSG_CMD;
1233  msg.pid = spur->pid;
1234  msg.type = YPSPUR_JOINT_ANG_VEL;
1235  msg.cs = id;
1236  msg.data[0] = a;
1237  msg.data[1] = v;
1238 
1239  if (spur->dev.send(&spur->dev, &msg) < 0)
1240  {
1241  /* error */
1242  spur->connection_error = 1;
1243  return -1;
1244  }
1245 
1246  return 1;
1247 }
1248 
1249 int YP_md_set_joint_accel(YPSpur *spur, int id, double a)
1250 {
1251  YPSpur_msg msg;
1252 
1253  msg.msg_type = YPSPUR_MSG_CMD;
1254  msg.pid = spur->pid;
1256  msg.cs = id;
1257  msg.data[0] = a;
1258 
1259  if (spur->dev.send(&spur->dev, &msg) < 0)
1260  {
1261  /* error */
1262  spur->connection_error = 1;
1263  return -1;
1264  }
1265 
1266  return 1;
1267 }
1268 
1269 int YP_md_set_joint_vel(YPSpur *spur, int id, double v)
1270 {
1271  YPSpur_msg msg;
1272 
1273  msg.msg_type = YPSPUR_MSG_CMD;
1274  msg.pid = spur->pid;
1275  msg.type = YPSPUR_SET_JOINT_VEL;
1276  msg.cs = id;
1277  msg.data[0] = v;
1278 
1279  if (spur->dev.send(&spur->dev, &msg) < 0)
1280  {
1281  /* error */
1282  spur->connection_error = 1;
1283  return -1;
1284  }
1285 
1286  return 1;
1287 }
1288 
1289 double YP_md_get_joint_vel(YPSpur *spur, int id, double *v)
1290 {
1291  YPSpur_msg msg;
1292  int len;
1293  double time;
1294 
1295  msg.msg_type = YPSPUR_MSG_CMD;
1296  msg.pid = spur->pid;
1297  msg.type = YPSPUR_GET_JOINT_VEL;
1298  msg.cs = id;
1299  if (spur->dev.send(&spur->dev, &msg) < 0)
1300  {
1301  /* error */
1302  spur->connection_error = 1;
1303  return -1;
1304  }
1305 
1306  /* 指定のコマンド受け取り */
1307  len = spur->dev.recv(&spur->dev, &msg);
1308  if (len < 0)
1309  {
1310  /* receive error */
1311  spur->connection_error = 1;
1312  return -1;
1313  }
1314 
1315  *v = msg.data[0];
1316  time = msg.data[1];
1317  return time;
1318 }
1319 
1320 double YP_md_get_joint_vref(YPSpur *spur, int id, double *v)
1321 {
1322  YPSpur_msg msg;
1323  int len;
1324  double time;
1325 
1326  msg.msg_type = YPSPUR_MSG_CMD;
1327  msg.pid = spur->pid;
1329  msg.cs = id;
1330  if (spur->dev.send(&spur->dev, &msg) < 0)
1331  {
1332  /* error */
1333  spur->connection_error = 1;
1334  return -1;
1335  }
1336 
1337  /* 指定のコマンド受け取り */
1338  len = spur->dev.recv(&spur->dev, &msg);
1339  if (len < 0)
1340  {
1341  /* receive error */
1342  spur->connection_error = 1;
1343  return -1;
1344  }
1345 
1346  *v = msg.data[0];
1347  time = msg.data[1];
1348  return time;
1349 }
1350 
1351 double YP_md_get_joint_ang(YPSpur *spur, int id, double *a)
1352 {
1353  YPSpur_msg msg;
1354  int len;
1355  double time;
1356 
1357  msg.msg_type = YPSPUR_MSG_CMD;
1358  msg.pid = spur->pid;
1359  msg.type = YPSPUR_GET_JOINT_ANG;
1360  msg.cs = id;
1361  if (spur->dev.send(&spur->dev, &msg) < 0)
1362  {
1363  /* error */
1364  spur->connection_error = 1;
1365  return -1;
1366  }
1367 
1368  /* 指定のコマンド受け取り */
1369  len = spur->dev.recv(&spur->dev, &msg);
1370  if (len < 0)
1371  {
1372  /* receive error */
1373  spur->connection_error = 1;
1374  return -1;
1375  }
1376 
1377  *a = msg.data[0];
1378  time = msg.data[1];
1379  return time;
1380 }
1381 
1382 double YP_md_get_joint_torque(YPSpur *spur, int id, double *t)
1383 {
1384  YPSpur_msg msg;
1385  int len;
1386  double time;
1387 
1388  msg.msg_type = YPSPUR_MSG_CMD;
1389  msg.pid = spur->pid;
1391  msg.cs = id;
1392  if (spur->dev.send(&spur->dev, &msg) < 0)
1393  {
1394  /* error */
1395  spur->connection_error = 1;
1396  return -1;
1397  }
1398 
1399  /* 指定のコマンド受け取り */
1400  len = spur->dev.recv(&spur->dev, &msg);
1401  if (len < 0)
1402  {
1403  /* receive error */
1404  spur->connection_error = 1;
1405  return -1;
1406  }
1407 
1408  *t = msg.data[0];
1409  time = msg.data[1];
1410  return time;
1411 }
1412 
1414 {
1415  return OUTPUT_LV_INFO;
1416 }
double YP_md_get_joint_vref(YPSpur *spur, int id, double *v)
#define YPSPUR_MSG_CMD
Definition: ypparam.h:516
int connection_error
Definition: ypparam.h:507
int YP_md_set_joint_accel(YPSpur *spur, int id, double a)
int YP_md_set_io_data(YPSpur *spur, unsigned char data)
double YP_md_get_joint_torque(YPSpur *spur, int id, double *t)
int YPSpur_md_tilt(YPSpur *spur, int cs, double dir, double tilt)
Definition: libypspur-md.c:881
int YPSpur_md_adjust_pos(YPSpur *spur, int cs, double x, double y, double theta)
Definition: libypspur-md.c:337
double YP_md_get_wheel_torque(YPSpur *spur, double *torque_r, double *torque_l)
Definition: libypspur-md.c:638
int ipcmd_open_tcp(struct ipcmd_t *ipcmd, char *host, int port)
long pid
Definition: ypparam.h:485
int YPSpur_md_vel(YPSpur *spur, double v, double w)
Definition: libypspur-md.c:735
double YPSpur_md_get_force(YPSpur *spur, double *trans, double *angular)
Definition: libypspur-md.c:671
int type
Definition: ypparam.h:486
int YP_md_get_parameter_array(YPSpur *spur, int param_id, double *value)
Definition: libypspur-md.c:829
int YP_md_wheel_vel(YPSpur *spur, double r, double l)
pid_t pid
Definition: ypparam.h:508
int YP_md_set_io_dir(YPSpur *spur, unsigned char dir)
int YP_md_set_parameter(YPSpur *spur, int param_id, double value)
Definition: libypspur-md.c:756
int YP_md_set_wheel_accel(YPSpur *spur, double r, double l)
double YPSpur_md_get_vel(YPSpur *spur, double *v, double *w)
Definition: libypspur-md.c:473
static YPSpur spur
Definition: libypspur.c:42
int YPSpur_md_initex(YPSpur *spur, int msq_key)
Definition: libypspur-md.c:81
int YPSpur_md_set_pos(YPSpur *spur, int cs, double x, double y, double theta)
Definition: libypspur-md.c:315
int YPSpur_md_stop_line(YPSpur *spur, int cs, double x, double y, double theta)
Definition: libypspur-md.c:136
int YP_md_joint_ang_vel(YPSpur *spur, int id, double a, double v)
int YPSpur_md_init(YPSpur *spur)
Definition: libypspur-md.c:108
double YPSpur_md_get_pos(YPSpur *spur, int cs, double *x, double *y, double *theta)
Definition: libypspur-md.c:439
int YPSpur_md_near_ang(YPSpur *spur, int cs, double th, double d)
Definition: libypspur-md.c:935
ParamOutputLv
Definition: param.h:62
int YP_md_set_wheel_vel(YPSpur *spur, double r, double l)
int YPSpur_md_unfreeze(YPSpur *spur)
Definition: libypspur-md.c:258
ParamOutputLv output_lv(void)
double YP_md_get_vref(YPSpur *spur, double *v, double *w)
Definition: libypspur-md.c:506
int connection_error
Definition: ypspur-md.h:120
int YPSpur_md_circle(YPSpur *spur, int cs, double x, double y, double r)
Definition: libypspur-md.c:158
int YPSpur_md_init_socket(YPSpur *spur, char *ip, int port)
Definition: libypspur-md.c:94
int YP_md_joint_vel(YPSpur *spur, int id, double v)
int YPSpur_md_spin(YPSpur *spur, int cs, double theta)
Definition: libypspur-md.c:180
int YP_md_get_parameter(YPSpur *spur, int param_id, double *value)
Definition: libypspur-md.c:800
int YPSpur_md_orient(YPSpur *spur, int cs, double theta)
Definition: libypspur-md.c:200
int YPSpur_md_stop(YPSpur *spur)
Definition: libypspur-md.c:220
int(* recv)(struct ipcmd_t *ipcmd, YPSpur_msg *data)
Definition: ypparam.h:511
int YPSpur_md_set_angvel(YPSpur *spur, double w)
Definition: libypspur-md.c:379
int YPSpur_md_free(YPSpur *spur)
Definition: libypspur-md.c:277
int YP_md_get_error_state(YPSpur *spur)
Definition: libypspur-md.c:43
long msg_type
Definition: ypparam.h:484
int cs
Definition: ypparam.h:487
int YPSpur_md_freeze(YPSpur *spur)
Definition: libypspur-md.c:239
int YPSpur_md_set_vel(YPSpur *spur, double v)
Definition: libypspur-md.c:359
int YP_md_joint_torque(YPSpur *spur, int id, double t)
double data[4]
Definition: ypparam.h:488
#define YPSPUR_MSQ_KEY
Definition: ypparam.h:515
int pid
Definition: ypspur-md.h:119
double YP_md_get_joint_vel(YPSpur *spur, int id, double *v)
int YPSpur_md_line(YPSpur *spur, int cs, double x, double y, double theta)
Definition: libypspur-md.c:114
int YP_md_wheel_ang(YPSpur *spur, double r, double l)
int state(YPSpur_state id)
Definition: param.c:64
double YP_md_get_wheel_vel(YPSpur *spur, double *wr, double *wl)
Definition: libypspur-md.c:572
int YP_md_joint_ang(YPSpur *spur, int id, double a)
double YP_md_get_wheel_ang(YPSpur *spur, double *theta_r, double *theta_l)
Definition: libypspur-md.c:605
int YPSpur_md_over_line(YPSpur *spur, int cs, double x, double y, double theta)
Definition: libypspur-md.c:966
int(* send)(struct ipcmd_t *ipcmd, YPSpur_msg *data)
Definition: ypparam.h:510
int YP_md_set_parameter_array(YPSpur *spur, int param_id, double *value)
Definition: libypspur-md.c:778
double YP_md_get_device_error_state(YPSpur *spur, int id, int *error_state)
Definition: libypspur-md.c:48
int YP_md_openfree(YPSpur *spur)
Definition: libypspur-md.c:296
double YP_md_get_wheel_vref(YPSpur *spur, double *wr, double *wl)
Definition: libypspur-md.c:539
int YPSpur_md_isfreeze(YPSpur *spur)
Definition: libypspur-md.c:704
int YP_md_get_ad_value(YPSpur *spur, int num)
Definition: libypspur-md.c:998
int YP_md_set_joint_vel(YPSpur *spur, int id, double v)
int ipcmd_open_msq(struct ipcmd_t *ipcmd, int key, int creat)
int YP_md_set_control_state(YPSpur *spur, int control_id, int state)
Definition: libypspur-md.c:860
int YP_md_wheel_torque(YPSpur *spur, double r, double l)
double YP_md_get_joint_ang(YPSpur *spur, int id, double *a)
int YPSpur_md_set_angaccel(YPSpur *spur, double dw)
Definition: libypspur-md.c:419
int YPSpur_md_near_pos(YPSpur *spur, int cs, double x, double y, double r)
Definition: libypspur-md.c:903
int YPSpur_md_set_accel(YPSpur *spur, double dv)
Definition: libypspur-md.c:399
struct ipcmd_t dev
Definition: ypspur-md.h:118


yp-spur
Author(s):
autogenerated on Sat May 11 2019 02:08:24