command_param.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 <command.h>
42 #include <odometry.h>
43 #include <control.h>
44 #include <utility.h>
45 #include <yprintf.h>
46 
47 /* ライブラリ用 */
48 #include <ypspur.h>
49 #include <cartesian2d.h>
50 
51 void param_set_com(int cs, double *data, SpurUserParamsPtr spur)
52 {
53  if (cs >= 0 && cs < YP_PARAM_NUM)
54  {
55  *pp(cs, 0) = data[0];
56  *pp(cs, 1) = data[1];
57  }
58 }
59 
60 int param_get_com(int cs, double *resdata, SpurUserParamsPtr spur)
61 {
62  if (cs >= 0 && cs < YP_PARAM_NUM)
63  {
64  resdata[0] = *pp(cs, 0);
65  resdata[1] = *pp(cs, 1);
66  return cs;
67  }
68  else
69  {
70  return 0;
71  }
72 }
73 
74 void param_set_motor_com(int cs, double *data, SpurUserParamsPtr spur)
75 {
76  if (cs >= 0 && cs < YP_PARAM_NUM)
77  *pp(cs, data[0]) = data[1];
78 }
79 
80 int param_get_motor_com(int cs, double *resdata, SpurUserParamsPtr spur)
81 {
82  if (cs >= 0 && cs < YP_PARAM_NUM)
83  {
84  resdata[0] = *pp(cs, resdata[0]);
85  return cs;
86  }
87  else
88  {
89  return 0;
90  }
91 }
92 
93 void param_state_com(int cs, double *data, SpurUserParamsPtr spur)
94 {
96 
97  odometry = get_odometry_ptr();
98 
99  if (cs >= 0 && cs < YP_STATE_NUM)
100  {
101  if (data[0])
102  {
103  enable_state(cs);
104  }
105  else
106  {
107  disable_state(cs);
108  }
109  }
110 
111  if (cs == YP_STATE_MOTOR && data[0] == ENABLE)
112  {
113  set_param_motor();
114  yprintf(OUTPUT_LV_DEBUG, "COMMAND: Motor Control: enabled\n");
115  }
116  if (cs == YP_STATE_VELOCITY && data[0] == ENABLE)
117  {
119  yprintf(OUTPUT_LV_DEBUG, "COMMAND: Velocity Control: enabled\n");
120  }
121  if (cs == YP_STATE_BODY && data[0] == ENABLE)
122  {
123  spur->vref_smooth = 0;
124  spur->wref_smooth = 0;
125  robot_speed(spur);
126  odometry->x = 0;
127  odometry->y = 0;
128  odometry->theta = 0;
129  yprintf(OUTPUT_LV_DEBUG, "COMMAND: Body Control: enabled\n");
130  }
131  if (cs == YP_STATE_TRACKING && data[0] == ENABLE)
132  {
133  yprintf(OUTPUT_LV_DEBUG, "COMMAND: Trajectory Control: enabled\n");
134  }
135  if (cs == YP_STATE_GRAVITY && data[0] == ENABLE)
136  {
137  yprintf(OUTPUT_LV_DEBUG, "COMMAND: Gravity Compensation: enabled\n");
138  }
139 }
void param_set_motor_com(int cs, double *data, SpurUserParamsPtr spur)
Definition: command_param.c:74
void robot_speed(SpurUserParamsPtr spur)
void param_state_com(int cs, double *data, SpurUserParamsPtr spur)
Definition: command_param.c:93
double y
Definition: odometry.h:34
void param_set_com(int cs, double *data, SpurUserParamsPtr spur)
Definition: command_param.c:51
double * pp(YPSpur_param id, enum motor_id motor)
Definition: param.c:94
int set_param_velocity(void)
Definition: param.c:1355
int param_get_motor_com(int cs, double *resdata, SpurUserParamsPtr spur)
Definition: command_param.c:80
void odometry(OdometryPtr xp, short *cnt, short *pwm, double dt, double time)
Definition: odometry.c:144
int param_get_com(int cs, double *resdata, SpurUserParamsPtr spur)
Definition: command_param.c:60
パラメータの最大値
Definition: ypparam.h:207
void enable_state(YPSpur_state id)
Definition: param.c:69
static YPSpur spur
Definition: libypspur.c:42
#define ENABLE
Definition: serial.h:24
double theta
Definition: odometry.h:35
void yprintf(ParamOutputLv level, const char *format,...)
Definition: yprintf.c:32
double vref_smooth
Definition: command.h:63
OdometryPtr get_odometry_ptr()
Definition: odometry.c:332
int set_param_motor(void)
Definition: param.c:1187
double wref_smooth
Definition: command.h:64
void disable_state(YPSpur_state id)
Definition: param.c:74
double x
Definition: odometry.h:33


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