title: child class of leafsystem generating sinusoidal signal
body: <p>I am trying to make a child class of <code>LeafSystem</code> whose output is sinusoidal and its derivative.
  I wrote the code and try to plot it but signal logger doesn't log correctly.</p>
  
  <pre><code>#include "drake/systems/framework/leaf_system.h"
  #include "drake/systems/analysis/simulator.h"
  #include "drake/systems/framework/diagram.h"
  #include "drake/systems/framework/diagram_builder.h"
  #include "drake/systems/primitives/signal_logger.h"
  #include "drake/common/proto/call_python.h"
  
  class Sinusoid : public drake::systems::LeafSystem&lt;double&gt;
  {
  public:
      Sinusoid (double tstart, double freq, double amp, double offset) :
          m_freq(freq), m_amp(amp), m_offset(offset), m_tstart(tstart) {
      this-&gt;DeclareVectorOutputPort(
              drake::systems::BasicVector&lt;double&gt;(2), &amp;Sinusoid::output);
          }
  
  private:
      void output(const drake::systems::Context&lt;double&gt;&amp; c,             drake::systems::BasicVector&lt;double&gt;* output) const {
        double t(c.get_time());
        double tknot(t - m_tstart);
        if (t &gt; m_tstart) {
            output-&gt;SetAtIndex(0, std::sin(tknot*m_freq +     m_offset)*m_amp);
            output-&gt;SetAtIndex(1, std::cos(tknot*m_freq +     m_offset)*m_amp*m_freq);
        } else {
            output-&gt;SetAtIndex(0, 0.0);
            output-&gt;SetAtIndex(1, 0.0);
        }
      }
      double m_freq{0.0}, m_amp{0.0}, m_offset{0.0}, m_tstart{0.0};
  };
  
  int main(int argc, char *argv[])
  {
      // Add System and Connect
      drake::systems::DiagramBuilder&lt;double&gt; builder;
      auto system  = builder.AddSystem&lt;Sinusoid&gt;(1.0, 2.*M_PI*1., 3., 0.);
      auto logger = LogOutput(system-&gt;get_output_port(0), &amp;builder);
      auto diagram = builder.Build();
  
      // Construct Simulator
      drake::systems::Simulator&lt;double&gt; simulator(*diagram);
  
      // Run simulation
      simulator.StepTo(100);
  
      // Plot with Python
      auto sample_time = logger-&gt;sample_times();
      auto sample_data = logger-&gt;data();
      std::cout &lt;&lt; sample_time.size() &lt;&lt; std::endl;
      for (int i = 0; i &lt; sample_time.size(); ++i) {
          std::cout &lt;&lt; sample_time(i) &lt;&lt; " : " &lt;&lt; sample_data(i, 0) &lt;&lt; "      " &lt;&lt; sample_data(i, 1) &lt;&lt; std::endl;
          }
  
      std::cout &lt;&lt; "END" &lt;&lt; std::endl;
      return 0;
  }
  </code></pre>
  
  <p>The output of the code is
  <code>
  2
  0 : 0  0
  0 : 0  0
  END
  </code>
  Whatever number I used in <code>StepTo</code> function, signal logger only cate 2 data whose sampled times are both 0.</p>