Cheetah Software
1.0
Main Page
Namespaces
Classes
Files
File List
File Members
SpineBoard.cpp
Go to the documentation of this file.
1
5
#include "
SimUtilities/SpineBoard.h
"
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
17
void
SpineBoard::resetData
() {
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;
32
data
->
spi_driver_status
= 0;
33
}
34
35
void
SpineBoard::resetCommand
() {
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
62
void
SpineBoard::run
() {
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]) {
76
torque_out
[0] =
kp_softstop
* (
q_limit_p
[0] -
data
->
q_abad
[
board_num
]) -
77
kd_softstop
* (
data
->
qd_abad
[
board_num
]) +
78
cmd
->
tau_abad_ff
[
board_num
];
79
}
else
if
(
data
->
q_abad
[
board_num
] <
q_limit_n
[0]) {
80
torque_out
[0] =
kp_softstop
* (
q_limit_n
[0] -
data
->
q_abad
[
board_num
]) -
81
kd_softstop
* (
data
->
qd_abad
[
board_num
]) +
82
cmd
->
tau_abad_ff
[
board_num
];
83
}
else
{
84
torque_out
[0] =
cmd
->
kp_abad
[
board_num
] *
85
(
cmd
->
q_des_abad
[
board_num
] -
data
->
q_abad
[
board_num
]) +
86
cmd
->
kd_abad
[
board_num
] * (
cmd
->
qd_des_abad
[
board_num
] -
87
data
->
qd_abad
[
board_num
]) +
88
cmd
->
tau_abad_ff
[
board_num
];
89
}
90
92
if
(
data
->
q_hip
[
board_num
] >
q_limit_p
[1]) {
93
torque_out
[1] =
kp_softstop
* (
q_limit_p
[1] -
data
->
q_hip
[
board_num
]) -
94
kd_softstop
* (
data
->
qd_hip
[
board_num
]) +
95
cmd
->
tau_hip_ff
[
board_num
];
96
}
else
if
(
data
->
q_hip
[
board_num
] <
q_limit_n
[1]) {
97
torque_out
[1] =
kp_softstop
* (
q_limit_n
[1] -
data
->
q_hip
[
board_num
]) -
98
kd_softstop
* (
data
->
qd_hip
[
board_num
]) +
99
cmd
->
tau_hip_ff
[
board_num
];
100
}
else
{
101
torque_out
[1] =
cmd
->
kp_hip
[
board_num
] *
102
(
cmd
->
q_des_hip
[
board_num
] -
data
->
q_hip
[
board_num
]) +
103
cmd
->
kd_hip
[
board_num
] *
104
(
cmd
->
qd_des_hip
[
board_num
] -
data
->
qd_hip
[
board_num
]) +
105
cmd
->
tau_hip_ff
[
board_num
];
106
}
107
109
torque_out
[2] =
cmd
->
kp_knee
[
board_num
] *
110
(
cmd
->
q_des_knee
[
board_num
] -
data
->
q_knee
[
board_num
]) +
111
cmd
->
kd_knee
[
board_num
] *
112
(
cmd
->
qd_des_knee
[
board_num
] -
data
->
qd_knee
[
board_num
]) +
113
cmd
->
tau_knee_ff
[
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
}
SpineBoard::resetData
void resetData()
Definition:
SpineBoard.cpp:17
SpiData::q_knee
float q_knee[4]
Definition:
SpineBoard.h:37
SpineBoard::q_limit_n
const float q_limit_n[3]
Definition:
SpineBoard.h:63
SpineBoard::cmd
SpiCommand * cmd
Definition:
SpineBoard.h:52
SpiCommand::qd_des_knee
float qd_des_knee[4]
Definition:
SpineBoard.h:17
SpineBoard::q_limit_p
const float q_limit_p[3]
Definition:
SpineBoard.h:62
SpineBoard::max_torque
const float max_torque[3]
Definition:
SpineBoard.h:59
SpiCommand::tau_abad_ff
float tau_abad_ff[4]
Definition:
SpineBoard.h:27
SpiCommand::kd_hip
float kd_hip[4]
Definition:
SpineBoard.h:24
SpiData::spi_driver_status
int32_t spi_driver_status
Definition:
SpineBoard.h:42
SpiCommand::kd_knee
float kd_knee[4]
Definition:
SpineBoard.h:25
SpiData::q_hip
float q_hip[4]
Definition:
SpineBoard.h:36
SpiCommand::q_des_knee
float q_des_knee[4]
Definition:
SpineBoard.h:13
SpiCommand::kd_abad
float kd_abad[4]
Definition:
SpineBoard.h:23
SpineBoard::init
void init(float side_sign, s32 board)
Definition:
SpineBoard.cpp:8
SpineBoard::board_num
s32 board_num
Definition:
SpineBoard.h:58
SpiCommand::tau_knee_ff
float tau_knee_ff[4]
Definition:
SpineBoard.h:29
SpiCommand::q_des_abad
float q_des_abad[4]
Definition:
SpineBoard.h:11
SpiCommand::kp_knee
float kp_knee[4]
Definition:
SpineBoard.h:21
SpiCommand::q_des_hip
float q_des_hip[4]
Definition:
SpineBoard.h:12
SpiCommand::qd_des_hip
float qd_des_hip[4]
Definition:
SpineBoard.h:16
SpiCommand::flags
int32_t flags[4]
Definition:
SpineBoard.h:31
SpineBoard.h
Spine Board Code, used to simulate the SpineBoard.
SpineBoard::data
SpiData * data
Definition:
SpineBoard.h:53
SpiCommand::kp_abad
float kp_abad[4]
Definition:
SpineBoard.h:19
SpiCommand::kp_hip
float kp_hip[4]
Definition:
SpineBoard.h:20
SpiData::q_abad
float q_abad[4]
Definition:
SpineBoard.h:35
SpineBoard::torque_out
float torque_out[3]
Definition:
SpineBoard.h:54
SpiData::qd_abad
float qd_abad[4]
Definition:
SpineBoard.h:38
SpiCommand::tau_hip_ff
float tau_hip_ff[4]
Definition:
SpineBoard.h:28
s32
int32_t s32
Definition:
cTypes.h:23
SpineBoard::disabled_torque
const float disabled_torque[3]
Definition:
SpineBoard.h:61
SpineBoard::run
void run()
Definition:
SpineBoard.cpp:62
SpiData::flags
int32_t flags[4]
Definition:
SpineBoard.h:41
SpineBoard::kp_softstop
const float kp_softstop
Definition:
SpineBoard.h:64
SpineBoard::kd_softstop
const float kd_softstop
Definition:
SpineBoard.h:65
SpiCommand::qd_des_abad
float qd_des_abad[4]
Definition:
SpineBoard.h:15
SpineBoard::wimp_torque
const float wimp_torque[3]
Definition:
SpineBoard.h:60
SpineBoard::iter_counter
s32 iter_counter
Definition:
SpineBoard.h:66
SpineBoard::resetCommand
void resetCommand()
Definition:
SpineBoard.cpp:35
SpiData::qd_hip
float qd_hip[4]
Definition:
SpineBoard.h:39
SpineBoard::side_sign
float side_sign
Definition:
SpineBoard.h:57
SpiData::qd_knee
float qd_knee[4]
Definition:
SpineBoard.h:40
home
dhkim
Public_Repository
Cheetah-Software
common
src
SimUtilities
SpineBoard.cpp
Generated by
1.8.11