()
| 157 | |
| 158 | |
| 159 | def test_centroidal_diff(): |
| 160 | # Test for 3D contact |
| 161 | nx = 9 |
| 162 | space = manifolds.VectorSpace(nx) |
| 163 | force_size = 3 |
| 164 | nk = 3 |
| 165 | nu = force_size * nk |
| 166 | mass = 10.5 |
| 167 | gravity = np.array([0, 0, -9.81]) |
| 168 | contact_names = ["foot1", "foot2", "foot3"] |
| 169 | contact_states = [True, True, False] |
| 170 | contact_poses = [ |
| 171 | np.array([0, 0.1, 0]), |
| 172 | np.array([0.1, -0.1, 0]), |
| 173 | np.array([0.1, 0.2, 0]), |
| 174 | ] |
| 175 | contact_map = aligator.ContactMap(contact_names, contact_states, contact_poses) |
| 176 | ode = dynamics.CentroidalFwdDynamics(space, mass, gravity, contact_map, force_size) |
| 177 | data = ode.createData() |
| 178 | |
| 179 | x0 = np.random.randn(nx) |
| 180 | u0 = np.random.randn(nu) |
| 181 | |
| 182 | ode.forward(x0, u0, data) |
| 183 | ode.dForward(x0, u0, data) |
| 184 | |
| 185 | Jx0 = data.Jx.copy() |
| 186 | Ju0 = data.Ju.copy() |
| 187 | Jxdiff, Judiff = ode_finite_difference(ode, space, x0, u0, epsilon) |
| 188 | |
| 189 | assert np.allclose(Jxdiff, Jx0, epsilon), "err={}".format(infNorm(Jxdiff - Jx0)) |
| 190 | assert np.allclose(Judiff, Ju0, epsilon), "err={}".format(infNorm(Judiff - Ju0)) |
| 191 | |
| 192 | # Test for 6D contact |
| 193 | force_size = 6 |
| 194 | nu = force_size * nk |
| 195 | u0 = np.random.randn(nu) |
| 196 | |
| 197 | ode = dynamics.CentroidalFwdDynamics(space, mass, gravity, contact_map, force_size) |
| 198 | data = ode.createData() |
| 199 | |
| 200 | ode.forward(x0, u0, data) |
| 201 | ode.dForward(x0, u0, data) |
| 202 | |
| 203 | Jx0 = data.Jx.copy() |
| 204 | Ju0 = data.Ju.copy() |
| 205 | Jxdiff, Judiff = ode_finite_difference(ode, space, x0, u0, epsilon) |
| 206 | |
| 207 | assert np.allclose(Jxdiff, Jx0, epsilon), "err={}".format(infNorm(Jxdiff - Jx0)) |
| 208 | assert np.allclose(Judiff, Ju0, epsilon), "err={}".format(infNorm(Judiff - Ju0)) |
| 209 | |
| 210 | |
| 211 | def test_continuous_centroidal(): |
nothing calls this directly
no test coverage detected