1 #include <gtest/gtest.h>
37 unsigned int count = 0;
42 struct timeval
timeout = { 10, 0 };
52 unsigned int count_out = 8;
53 while (count_out > 0) {
54 ASSERT_NE(-1, ioctl(
master_fd, TIOCOUTQ, &count_out));
56 EXPECT_EQ(0, count_out);
77 ASSERT_NE(-1, ioctl(master_fd, FIONREAD, &aval));
78 ASSERT_EQ(out.size(), aval);
79 ASSERT_EQ(out.size(), read(master_fd, out.c_array(), out.size()));
88 robot->joints_[0].velocity_command = 5;
89 robot->joints_[1].velocity_command = -5;
98 ASSERT_NE(-1, ioctl(master_fd, FIONREAD, &aval));
99 ASSERT_EQ(out.size(), aval);
100 ASSERT_EQ(out.size(), read(master_fd, out.c_array(), out.size()));
105 int16_t left = (mm.
getData() >> 16) & 0xffff;
106 int16_t right = mm.
getData() & 0xffff;
118 mm.
setData((50 << 16) | (-50 & 0x0000ffff));
121 ASSERT_EQ(out.size(), write(master_fd, out.c_array(), out.size()));
123 robot->readInputs(0);
125 double left = robot->joints_[0].position;
126 double right = robot->joints_[1].position;
134 mm.
setData((0 << 16) | (0 & 0x0000ffff));
136 ASSERT_EQ(out.size(), write(master_fd, out.c_array(), out.size()));
138 robot->readInputs(0);
141 ASSERT_EQ(left, robot->joints_[0].position);
142 ASSERT_EQ(right, robot->joints_[1].position);
145 mm.
setData((50 << 16) | (-50 & 0x0000ffff));
147 ASSERT_EQ(out.size(), write(master_fd, out.c_array(), out.size()));
149 robot->readInputs(0);
152 ASSERT_DOUBLE_EQ(left * 2, robot->joints_[0].position);
153 ASSERT_DOUBLE_EQ(right * 2, robot->joints_[1].position);
156 mm.
setData((-50 << 16) | (50 & 0x0000ffff));
158 ASSERT_EQ(out.size(), write(master_fd, out.c_array(), out.size()));
160 robot->readInputs(0);
163 ASSERT_DOUBLE_EQ(left, robot->joints_[0].position);
164 ASSERT_DOUBLE_EQ(right, robot->joints_[1].position);
171 mm.
setData((std::numeric_limits<int16_t>::max() << 16) |
172 (std::numeric_limits<int16_t>::min() & 0x0000ffff));
175 ASSERT_EQ(out.size(), write(master_fd, out.c_array(), out.size()));
177 robot->readInputs(0);
179 double left = robot->joints_[0].position;
180 double right = robot->joints_[1].position;
188 mm.
setData((0 << 16) | (0 & 0x0000ffff));
190 ASSERT_EQ(out.size(), write(master_fd, out.c_array(), out.size()));
192 robot->readInputs(0);
195 ASSERT_EQ(left, robot->joints_[0].position);
196 ASSERT_EQ(right, robot->joints_[1].position);
199 mm.
setData((std::numeric_limits<int16_t>::max() << 16) |
200 (std::numeric_limits<int16_t>::min() & 0x0000ffff));
202 ASSERT_EQ(out.size(), write(master_fd, out.c_array(), out.size()));
204 robot->readInputs(0);
207 ASSERT_DOUBLE_EQ(left * 2, robot->joints_[0].position);
208 ASSERT_DOUBLE_EQ(right * 2, robot->joints_[1].position);
211 mm.
setData((std::numeric_limits<int16_t>::min() << 16) |
212 (std::numeric_limits<int16_t>::max() & 0x0000ffff));
214 ASSERT_EQ(out.size(), write(master_fd, out.c_array(), out.size()));
216 robot->readInputs(0);
220 ASSERT_NEAR(left, robot->joints_[0].position, 0.1);
221 ASSERT_NEAR(right, robot->joints_[1].position, 0.1);
225 robot->requestFirmwareVersion();
232 ASSERT_NE(-1, ioctl(master_fd, FIONREAD, &aval));
233 ASSERT_EQ(out.size(), aval);
234 ASSERT_EQ(out.size(), read(master_fd, out.c_array(), out.size()));
249 ASSERT_EQ(out.size(), write(master_fd, out.c_array(), out.size()));
252 ASSERT_THROW(robot->readInputs(0), std::runtime_error);
256 robot->setDeadmanTimer(1000);
262 ASSERT_NE(-1, ioctl(master_fd, FIONREAD, &aval));
263 ASSERT_EQ(out.size(), aval);
264 ASSERT_EQ(out.size(), read(master_fd, out.c_array(), out.size()));
351 int main(
int argc,
char **argv) {
352 testing::InitGoogleTest(&argc, argv);
354 return RUN_ALL_TESTS();