31 #include <gtest/gtest.h> 84 const unsigned int nb_values = 7;
86 bool with_friction_compensation =
false;
93 with_friction_compensation =
true;
97 with_friction_compensation =
false;
101 const double values[nb_values] = {-123.123, -1.0, -0.5, 0.0, 0.5, 1.0, 456.456};
102 const double expected_values_no_fc[nb_values] = {-123.123, -1.0, -0.5, 0.0, 0.5, 1.0, 456.456};
103 const double expected_values_with_fc[nb_values] = {-323.123, -1.0, -0.5, 0.0, 0.5, 1.0, 656.456};
106 double ctrl_output = 0.0;
107 for (
unsigned int i = 0; i < nb_values; ++i)
112 ctrl_output = test_jpc->compute_output(values[i], 0.0);
113 if (with_friction_compensation)
115 ROS_INFO_STREAM(
"Expected value: " << expected_values_with_fc[i] <<
" Computed value: " << ctrl_output);
116 EXPECT_EQ(ctrl_output, expected_values_with_fc[i]);
120 ROS_INFO_STREAM(
"Expected value: " << expected_values_no_fc[i] <<
" Computed value: " << ctrl_output);
121 EXPECT_EQ(ctrl_output, expected_values_no_fc[i]);
127 const double pos[5] = {0.0, 0.11, 0.099, 0.116, 0.115};
128 const double expected_values[5] = {0.1, 0.0, 0.0, -0.016, 0.0};
129 for (
unsigned int i = 0; i < 5; ++i)
133 ctrl_output = test_jpc->compute_output(target, pos[i]);
134 ROS_INFO_STREAM(
"Expected value: " << expected_values[i] <<
" Computed value: " << ctrl_output);
135 EXPECT_EQ(ctrl_output, expected_values[i]);
141 pid->setGains(0.0, 1.0, 0.0, 2.0, -2.0);
147 const double expected_values_one_sec[nb_values] = {-2.0, -1.0, -0.5, 0.0, 0.5, 1.0, 2.0};
148 const double expected_values_half_sec[nb_values] = {-2.0, -0.5, -0.25, 0.0, 0.25, 0.5, 2.0};
150 for (
unsigned int i = 0; i < nb_values; ++i)
157 ctrl_output = test_jpc->compute_output(0.0, 0.0);
158 one_sec_pause.
sleep();
160 ctrl_output = test_jpc->compute_output(values[i], 0.0);
162 ROS_INFO_STREAM(
"Expected value: " << expected_values_one_sec[i] <<
" Computed value: " << ctrl_output);
163 EXPECT_TRUE(fabs(ctrl_output - expected_values_one_sec[i])
166 for (
unsigned int i = 0; i < nb_values; ++i)
173 ctrl_output = test_jpc->compute_output(0.0, 0.0);
174 half_sec_pause.
sleep();
176 ctrl_output = test_jpc->compute_output(values[i], 0.0);
178 ROS_INFO_STREAM(
"Expected value: " << expected_values_half_sec[i] <<
" Computed value: " << ctrl_output);
179 EXPECT_TRUE(fabs(ctrl_output - expected_values_half_sec[i]) < 0.001);
189 int main(
int argc,
char **argv)
191 ros::init(argc, argv,
"test_joint_pos_controller");
193 testing::InitGoogleTest(&argc, argv);
194 return RUN_ALL_TESTS();
pr2_mechanism_model::JointState * joint_state
std::vector< double > values
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
virtual ~TestJointPositionController()
TestJointPositionController(boost::shared_ptr< control_toolbox::Pid > pid)
ROSCPP_DECL bool get(const std::string &key, std::string &s)
int main(int argc, char **argv)
ROSCPP_DECL bool has(const std::string &key)
boost::shared_ptr< pr2_mechanism_model::RobotState > robot_state
boost::shared_ptr< control_toolbox::Pid > pid
#define ROS_INFO_STREAM(args)
TEST(SrhJointPositionController, TestPID)
bool init(ros_ethercat_model::RobotStateInterface *robot, ros::NodeHandle &n)
boost::shared_ptr< pr2_hardware_interface::HardwareInterface > hw
double compute_output(double input, double current_position)