command_set.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 #include <math.h>
22 #include <stdio.h>
23 #include <strings.h>
24 #include <unistd.h>
25 
26 #include <fcntl.h>
27 #include <sys/time.h>
28 #include <sys/types.h>
29 #include <time.h>
30 
31 #ifdef HAVE_CONFIG_H
32 #include <config.h>
33 #endif // HAVE_CONFIG_H
34 
35 /* ボディパラメータ */
36 #include <shvel-param.h>
37 
38 /* yp-spur用 */
39 #include <serial.h>
40 #include <param.h>
41 #include <control.h>
42 #include <command.h>
43 #include <odometry.h>
44 
45 /* ライブラリ用 */
46 #include <ypspur.h>
47 #include <cartesian2d.h>
48 
49 void set_pos_com(int cs, double *data, SpurUserParamsPtr spur)
50 {
51  double x, y, theta;
52  CSptr cs_src;
53  CSptr cs_fs;
54 
55  x = data[0];
56  y = data[1];
57  theta = data[2];
58 
59  cs_src = get_cs_pointer(cs);
60  cs_fs = get_cs_pointer(CS_FS);
61 
62  if (cs_src->parent != NULL)
63  {
64  CS_turn_base(&x, &y, &theta);
65  CS_recursive_trans(cs_src->parent, cs_fs, &x, &y, &theta);
66  set_cs(cs, x, y, theta);
67  }
68  else if (option(OPTION_ENABLE_SET_BS))
69  {
70  OdometryPtr odm;
71 
72  odm = get_odometry_ptr();
73  odm->x = x;
74  odm->y = y;
75  odm->theta = theta;
76  set_cs(CS_FS, x, y, theta);
77  }
78 }
79 
81 {
82  double x, y, theta;
83  x = data[0];
84  y = data[1];
85  theta = data[2];
86 
87  cstrans_xy(CS_GL, CS_BS, &x, &y, &theta);
88  set_cs(CS_GL, x, y, theta);
89 }
90 
91 void set_adjust_com(int cs, double *data, SpurUserParamsPtr spur)
92 {
93  double x, y, theta;
94  double xgl, ygl, thetagl;
95 
96  x = data[0];
97  y = data[1];
98  theta = data[2];
99 
100  cstrans_xy(cs, CS_GL, &x, &y, &theta);
101  /* ロボット(FS)がGL上のx,y,thetaに見えるとするとき */
102  /* FSからGLがどこに見えるか(GL->FS => FS->GL) */
103  CS_turn_base(&x, &y, &theta);
104  /* それはBS上のどこか */
105  cstrans_xy(CS_FS, CS_BS, &x, &y, &theta);
106  xgl = x;
107  ygl = y;
108  thetagl = theta;
109 
110  // 走行制御用座標系も修正
111  x = data[0];
112  y = data[1];
113  theta = data[2];
114  cstrans_xy(cs, CS_SP, &x, &y, &theta);
115  /* ロボット(FS)がGL上のx,y,thetaに見えるとするとき */
116  /* FSからGLがどこに見えるか(GL->FS => FS->GL) */
117  CS_turn_base(&x, &y, &theta);
118  /* それはBS上のどこか */
119  cstrans_xy(CS_FS, CS_BS, &x, &y, &theta);
120 
121  /* SPをセット */
122  /* GLをセット */
123  set_cs(CS_GL, xgl, ygl, thetagl);
124  set_cs(CS_SP, x, y, theta);
125 }
126 
127 void set_vel_com(double *data, SpurUserParamsPtr spur)
128 {
129  spur->v = data[0];
130  if (spur->v > p(YP_PARAM_MAX_VEL, 0))
131  spur->v = p(YP_PARAM_MAX_VEL, 0);
132  if (spur->v < -p(YP_PARAM_MAX_VEL, 0))
133  spur->v = -p(YP_PARAM_MAX_VEL, 0);
134 }
135 
137 {
138  spur->torque[1] = data[1];
139  spur->torque[0] = data[0];
140  spur->run_mode = RUN_WHEEL_TORQUE;
141 }
142 
144 {
145  spur->w = data[0];
146  if (spur->w > p(YP_PARAM_MAX_W, 0))
147  spur->w = p(YP_PARAM_MAX_W, 0);
148  if (spur->w < 0)
149  spur->w = 0;
150 }
151 
153 {
154  spur->dv = data[0];
155  if (spur->dv > p(YP_PARAM_MAX_ACC_V, 0))
156  spur->dv = p(YP_PARAM_MAX_ACC_V, 0);
157  if (spur->dv < 0)
158  spur->dv = 0;
159 }
160 
162 {
163  spur->dw = data[0];
164  if (spur->dw > p(YP_PARAM_MAX_ACC_W, 0))
165  spur->dw = p(YP_PARAM_MAX_ACC_W, 0);
166  if (spur->dw < 0)
167  spur->dw = 0;
168 }
169 
170 void set_tilt_com(int cs, double *data, SpurUserParamsPtr spur)
171 {
172  double x, y, theta;
173 
174  x = 0;
175  y = 0;
176  theta = data[0];
177 
178  cstrans_xy(CS_GL, cs, &x, &y, &theta);
179 
180  spur->dir = theta;
181  spur->tilt = data[1];
182 }
183 
185 {
186  spur->wheel_accel[1] = data[1];
187  spur->wheel_accel[0] = data[0];
188 }
189 
191 {
192  spur->wheel_vel[1] = data[1];
193  spur->wheel_vel[0] = data[0];
194 }
Definition: ypparam.h:465
SpurRunMode run_mode
Definition: command.h:85
double y
Definition: odometry.h:34
void CS_turn_base(double *x, double *y, double *theta)
Definition: libcarte2d.c:123
void cstrans_xy(YPSpur_cs src, YPSpur_cs dest, double *x, double *y, double *theta)
Definition: odometry.c:131
void CS_recursive_trans(CSptr target_cs, CSptr now_cs, double *x, double *y, double *theta)
Definition: libcarte2d.c:137
double torque[YP_PARAM_MAX_MOTOR_NUM]
Definition: command.h:68
double wheel_accel[YP_PARAM_MAX_MOTOR_NUM]
Definition: command.h:71
void set_adjust_com(int cs, double *data, SpurUserParamsPtr spur)
Definition: command_set.c:91
double p(YPSpur_param id, enum motor_id motor)
Definition: param.c:79
void set_tilt_com(int cs, double *data, SpurUserParamsPtr spur)
Definition: command_set.c:170
Definition: ypparam.h:466
CSptr parent
Definition: cartesian2d.h:39
void set_wheel_vel_com(double *data, SpurUserParamsPtr spur)
Definition: command_set.c:190
void set_ang_accel_com(double *data, SpurUserParamsPtr spur)
Definition: command_set.c:161
void set_accel_com(double *data, SpurUserParamsPtr spur)
Definition: command_set.c:152
static YPSpur spur
Definition: libypspur.c:42
void set_pos_com(int cs, double *data, SpurUserParamsPtr spur)
Definition: command_set.c:49
CSptr get_cs_pointer(YPSpur_cs cs)
Definition: odometry.c:102
Definition: ypparam.h:468
double wheel_vel[YP_PARAM_MAX_MOTOR_NUM]
Definition: command.h:72
void set_ang_vel_com(double *data, SpurUserParamsPtr spur)
Definition: command_set.c:143
void set_vel_com(double *data, SpurUserParamsPtr spur)
Definition: command_set.c:127
double theta
Definition: odometry.h:35
void set_cs(YPSpur_cs cs, double x, double y, double theta)
Definition: odometry.c:138
OdometryPtr get_odometry_ptr()
Definition: odometry.c:332
int option(ParamOptions option)
Definition: param.c:99
void set_GL_on_GL_com(double *data, SpurUserParamsPtr spur)
Definition: command_set.c:80
void set_wheel_accel_com(double *data, SpurUserParamsPtr spur)
Definition: command_set.c:184
Definition: ypparam.h:464
double x
Definition: odometry.h:33
void set_torque_com(double *data, SpurUserParamsPtr spur)
Definition: command_set.c:136


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