forked from pz4kybsvg/Conception
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.1 KiB
37 lines
1.1 KiB
2 years ago
|
import unittest
|
||
|
|
||
|
import numpy as np
|
||
|
|
||
|
from pydrake.examples import VanDerPolOscillator
|
||
|
from pydrake.systems.analysis import Simulator
|
||
|
|
||
|
|
||
|
class TestVanDerPol(unittest.TestCase):
|
||
|
def test_simulation(self):
|
||
|
van_der_pol = VanDerPolOscillator()
|
||
|
|
||
|
# Create the simulator.
|
||
|
simulator = Simulator(van_der_pol)
|
||
|
context = simulator.get_mutable_context()
|
||
|
|
||
|
# Set the initial state.
|
||
|
state = context.get_mutable_continuous_state_vector()
|
||
|
state.SetFromVector([0., 2.])
|
||
|
|
||
|
# Simulate (and make sure the state actually changes).
|
||
|
initial_state = state.CopyToVector()
|
||
|
simulator.AdvanceTo(1.0)
|
||
|
self.assertFalse((state.CopyToVector() == initial_state).any())
|
||
|
|
||
|
def test_ports(self):
|
||
|
vdp = VanDerPolOscillator()
|
||
|
|
||
|
self.assertTrue(vdp.get_position_output_port().get_index().is_valid())
|
||
|
self.assertTrue(
|
||
|
vdp.get_full_state_output_port().get_index().is_valid())
|
||
|
|
||
|
def test_limit_cycle(self):
|
||
|
cycle = VanDerPolOscillator.CalcLimitCycle()
|
||
|
|
||
|
np.testing.assert_almost_equal(cycle[:, 0], cycle[:, -1], 2)
|