Cheetah Software  1.0
SpineBoard.cpp
Go to the documentation of this file.
1 
6 #include <stdio.h>
7 
8 void SpineBoard::init(float sideSign, s32 board) {
9  printf(
10  "[Cheetah Control] Hello! I am the SPINE board for leg %d (0-indexed) "
11  "with side sign %.3f\n",
12  board, sideSign);
13  this->board_num = board;
14  this->side_sign = sideSign;
15 }
16 
18  if (data == nullptr) {
19  printf(
20  "[ERROR: SPINE board] reset_spine_board_data called when "
21  "cheetahlcm_spi_data_t* was null\n");
22  return;
23  }
24 
25  data->flags[board_num] = 0;
26  data->qd_abad[board_num] = 0.f;
27  data->qd_hip[board_num] = 0.f;
28  data->qd_knee[board_num] = 0.f;
29  data->q_abad[board_num] = 0.f;
30  data->q_hip[board_num] = 0.f;
31  data->q_knee[board_num] = 0.f;
33 }
34 
36  if (cmd == nullptr) {
37  printf(
38  "[ERROR: SPINE board] reset_spine_board_command called when "
39  "cheetahlcm_spi_command_t* was null\n");
40  return;
41  }
42 
43  cmd->flags[board_num] = 0;
44  cmd->kd_abad[board_num] = 0.f;
45  cmd->kd_hip[board_num] = 0.f;
46  cmd->kd_knee[board_num] = 0.f;
47  cmd->kp_abad[board_num] = 0.f;
48  cmd->kp_hip[board_num] = 0.f;
49  cmd->kp_knee[board_num] = 0.f;
50  cmd->qd_des_abad[board_num] = 0.f;
51  cmd->qd_des_hip[board_num] = 0.f;
52  cmd->qd_des_knee[board_num] = 0.f;
53  cmd->q_des_abad[board_num] = 0.f;
54  cmd->q_des_hip[board_num] = 0.f;
55  cmd->q_des_knee[board_num] = 0.f;
56  cmd->tau_abad_ff[board_num] = 0.f;
57  cmd->tau_hip_ff[board_num] = 0.f;
58  cmd->tau_hip_ff[board_num] = 0.f;
59  cmd->tau_knee_ff[board_num] = 0.f;
60 }
61 
63  iter_counter++;
64  if (cmd == nullptr || data == nullptr) {
65  printf(
66  "[ERROR: SPINE board] run_spine_board_iteration called with null "
67  "command or data!\n");
68  torque_out[0] = 0.f;
69  torque_out[1] = 0.f;
70  torque_out[2] = 0.f;
71  return;
72  }
73 
75  if (data->q_abad[board_num] > q_limit_p[0]) {
79  } else if (data->q_abad[board_num] < q_limit_n[0]) {
83  } else {
89  }
90 
92  if (data->q_hip[board_num] > q_limit_p[1]) {
96  } else if (data->q_hip[board_num] < q_limit_n[1]) {
100  } else {
101  torque_out[1] = cmd->kp_hip[board_num] *
103  cmd->kd_hip[board_num] *
106  }
107 
111  cmd->kd_knee[board_num] *
114 
115  const float* torque_limits = disabled_torque;
116 
117  if (cmd->flags[board_num] & 0b1) {
118  if (cmd->flags[board_num] & 0b10)
119  torque_limits = wimp_torque;
120  else
121  torque_limits = max_torque;
122  }
123 
124  for (int i = 0; i < 3; i++) {
125  if (torque_out[i] > torque_limits[i]) torque_out[i] = torque_limits[i];
126  if (torque_out[i] < -torque_limits[i]) torque_out[i] = -torque_limits[i];
127  }
128 
129  // if(! (iter_counter % 100))
130  // {
131  // printf("SPINE BOARD %d: flags: 0x%hx, torque out: %.3f %.3f %.3f\n",
132  // board_num, cmd->flags[board_num],
133  // torque_out[0], torque_out[1], torque_out[2]);
134  // }
135 }
void resetData()
Definition: SpineBoard.cpp:17
float q_knee[4]
Definition: SpineBoard.h:37
const float q_limit_n[3]
Definition: SpineBoard.h:63
SpiCommand * cmd
Definition: SpineBoard.h:52
float qd_des_knee[4]
Definition: SpineBoard.h:17
const float q_limit_p[3]
Definition: SpineBoard.h:62
const float max_torque[3]
Definition: SpineBoard.h:59
float tau_abad_ff[4]
Definition: SpineBoard.h:27
float kd_hip[4]
Definition: SpineBoard.h:24
int32_t spi_driver_status
Definition: SpineBoard.h:42
float kd_knee[4]
Definition: SpineBoard.h:25
float q_hip[4]
Definition: SpineBoard.h:36
float q_des_knee[4]
Definition: SpineBoard.h:13
float kd_abad[4]
Definition: SpineBoard.h:23
void init(float side_sign, s32 board)
Definition: SpineBoard.cpp:8
s32 board_num
Definition: SpineBoard.h:58
float tau_knee_ff[4]
Definition: SpineBoard.h:29
float q_des_abad[4]
Definition: SpineBoard.h:11
float kp_knee[4]
Definition: SpineBoard.h:21
float q_des_hip[4]
Definition: SpineBoard.h:12
float qd_des_hip[4]
Definition: SpineBoard.h:16
int32_t flags[4]
Definition: SpineBoard.h:31
Spine Board Code, used to simulate the SpineBoard.
SpiData * data
Definition: SpineBoard.h:53
float kp_abad[4]
Definition: SpineBoard.h:19
float kp_hip[4]
Definition: SpineBoard.h:20
float q_abad[4]
Definition: SpineBoard.h:35
float torque_out[3]
Definition: SpineBoard.h:54
float qd_abad[4]
Definition: SpineBoard.h:38
float tau_hip_ff[4]
Definition: SpineBoard.h:28
int32_t s32
Definition: cTypes.h:23
const float disabled_torque[3]
Definition: SpineBoard.h:61
void run()
Definition: SpineBoard.cpp:62
int32_t flags[4]
Definition: SpineBoard.h:41
const float kp_softstop
Definition: SpineBoard.h:64
const float kd_softstop
Definition: SpineBoard.h:65
float qd_des_abad[4]
Definition: SpineBoard.h:15
const float wimp_torque[3]
Definition: SpineBoard.h:60
s32 iter_counter
Definition: SpineBoard.h:66
void resetCommand()
Definition: SpineBoard.cpp:35
float qd_hip[4]
Definition: SpineBoard.h:39
float side_sign
Definition: SpineBoard.h:57
float qd_knee[4]
Definition: SpineBoard.h:40