-
Notifications
You must be signed in to change notification settings - Fork 128
Added commands to set pd controller gains and maximum joint torques #342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -421,6 +421,76 @@ TEST_F(ScriptCommandInterfaceTest, test_set_friction_compensation) | |
EXPECT_EQ(message_sum, expected_message_sum); | ||
} | ||
|
||
TEST_F(ScriptCommandInterfaceTest, test_set_pd_controller_gains) | ||
{ | ||
// Wait for the client to connect to the server | ||
waitForClientConnection(); | ||
|
||
urcl::vector6d_t kp = { 220.2, 220.2, 300.0, 10.32, 10.32, 10.32 }; | ||
urcl::vector6d_t kd = { 29.68, 29.68, 35.0, 6.4, 6.4, 6.4 }; | ||
script_command_interface_->setPDControllerGains(&kp, &kd); | ||
|
||
int32_t command; | ||
std::vector<int32_t> message; | ||
client_->readMessage(command, message); | ||
|
||
// 8 is set PD controller gains | ||
int32_t expected_command = 8; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could think about moving the enum to a public namespace so that can be reused here. or is there a specific reason why That's probably not for this PR, however. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No I think its because it is only intended to be used when sending commands to the external control script. But would make sense to make them available for the test cases. But yes should probably be done in separate PR. |
||
EXPECT_EQ(command, expected_command); | ||
|
||
int32_t message_idx = 0; | ||
|
||
for (auto& p_gain : kp) | ||
{ | ||
const double received_gain = (double)message[message_idx] / script_command_interface_->MULT_JOINTSTATE; | ||
EXPECT_EQ(p_gain, received_gain); | ||
message_idx = message_idx + 1; | ||
} | ||
|
||
for (auto& d_gain : kd) | ||
{ | ||
const double received_gain = (double)message[message_idx] / script_command_interface_->MULT_JOINTSTATE; | ||
EXPECT_EQ(d_gain, received_gain); | ||
message_idx = message_idx + 1; | ||
} | ||
|
||
// The rest of the message should be zero | ||
int32_t message_sum = std::accumulate(std::begin(message) + message_idx, std::end(message), 0); | ||
int32_t expected_message_sum = 0; | ||
EXPECT_EQ(message_sum, expected_message_sum); | ||
} | ||
|
||
TEST_F(ScriptCommandInterfaceTest, test_set_max_joint_torques) | ||
{ | ||
// Wait for the client to connect to the server | ||
waitForClientConnection(); | ||
|
||
urcl::vector6d_t max_joint_torques = { 100.0, 150.0, 21.2, 10.32, 10.32, 10.32 }; | ||
script_command_interface_->setMaxJointTorques(&max_joint_torques); | ||
|
||
int32_t command; | ||
std::vector<int32_t> message; | ||
client_->readMessage(command, message); | ||
|
||
// 9 is set max joint torques | ||
int32_t expected_command = 9; | ||
EXPECT_EQ(command, expected_command); | ||
|
||
int32_t message_idx = 0; | ||
|
||
for (auto& max_torque : max_joint_torques) | ||
{ | ||
const double received_max_torque = (double)message[message_idx] / script_command_interface_->MULT_JOINTSTATE; | ||
EXPECT_EQ(max_torque, received_max_torque); | ||
message_idx = message_idx + 1; | ||
} | ||
|
||
// The rest of the message should be zero | ||
int32_t message_sum = std::accumulate(std::begin(message) + message_idx, std::end(message), 0); | ||
int32_t expected_message_sum = 0; | ||
EXPECT_EQ(message_sum, expected_message_sum); | ||
} | ||
|
||
int main(int argc, char* argv[]) | ||
{ | ||
::testing::InitGoogleTest(&argc, argv); | ||
|
Uh oh!
There was an error while loading. Please reload this page.