changeset 186:4ef780aebd7e main

Update the simulator for the new front sonar (ultrasonics) layout.
author Bob Cook <bob@bobcookdev.com>
date Sat, 08 Jun 2013 11:50:20 -0700
parents 9bbf1ab744cd
children b716d7cb9c78
files main/robots/odr-sim/SimDisplay.cpp main/robots/odr-sim/SimDisplay.h main/robots/odr-sim/SonarFrontStatus.cpp main/robots/odr-sim/SonarFrontStatus.h
diffstat 4 files changed, 86 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/main/robots/odr-sim/SimDisplay.cpp	Sat Jun 08 11:49:25 2013 -0700
+++ b/main/robots/odr-sim/SimDisplay.cpp	Sat Jun 08 11:50:20 2013 -0700
@@ -175,7 +175,7 @@
 
 // ----------------------------------------------------------------------------------------
 
-static void SonarFrontSliderCenterCB( Fl_Widget* widget, void* value )
+static void SonarFrontSliderCenterLeftCB( Fl_Widget* widget, void* value )
 {
     Fl_Slider* slider = dynamic_cast< Fl_Slider* >( widget );
     if ( slider == 0 )
@@ -183,7 +183,26 @@
         return; // opps, not what we thought?!
     }
 
-    SonarFrontStatus::setSonarFrontCenter( slider->value() );
+    SonarFrontStatus::setSonarFrontCenterLeft( slider->value() );
+
+    SimDisplay* theDisplay = reinterpret_cast< SimDisplay* >( value );
+    if ( theDisplay )
+    {
+        theDisplay->updateSonarFrontValues();
+    }
+}
+
+// ----------------------------------------------------------------------------------------
+
+static void SonarFrontSliderCenterRightCB( Fl_Widget* widget, void* value )
+{
+    Fl_Slider* slider = dynamic_cast< Fl_Slider* >( widget );
+    if ( slider == 0 )
+    {
+        return; // opps, not what we thought?!
+    }
+
+    SonarFrontStatus::setSonarFrontCenterRight( slider->value() );
 
     SimDisplay* theDisplay = reinterpret_cast< SimDisplay* >( value );
     if ( theDisplay )
@@ -233,7 +252,8 @@
       m_buttonB( 0 ),
       m_buttonSonarFrontKA( 0 ),
       m_sliderSonarFrontL( 0 ),
-      m_sliderSonarFrontC( 0 ),
+      m_sliderSonarFrontCL( 0 ),
+      m_sliderSonarFrontCR( 0 ),
       m_sliderSonarFrontR( 0 ),
       m_textSonarFront( 0 ),
       m_timerMainHbTimeout()
@@ -487,10 +507,10 @@
     {
         m_textSonarFront->box( FL_THIN_DOWN_BOX );
         m_textSonarFront->align( FL_ALIGN_CENTER );
-        m_textSonarFront->label( "0F00  0F00  0F00" );
+        m_textSonarFront->label( "0F00 0F00 0F00 0F00" );
     }
 
-    m_sliderSonarFrontL = new Fl_Slider( 250, 210, 40, 100 );
+    m_sliderSonarFrontL = new Fl_Slider( 250, 210, 35, 100 );
     if ( m_sliderSonarFrontL )
     {
         m_sliderSonarFrontL->label( "Left" );
@@ -500,17 +520,27 @@
         m_sliderSonarFrontL->callback( SonarFrontSliderLeftCB, this );
     }
 
-    m_sliderSonarFrontC = new Fl_Slider( 312, 210, 40, 100 );
-    if ( m_sliderSonarFrontC )
+    m_sliderSonarFrontCL = new Fl_Slider( 293, 210, 35, 100 );
+    if ( m_sliderSonarFrontCL )
     {
-        m_sliderSonarFrontC->label( "Center" );
-        m_sliderSonarFrontC->slider( FL_UP_BOX );
-        m_sliderSonarFrontC->bounds( 0x0fff, 0 );
-        m_sliderSonarFrontC->value( SonarFrontStatus::sonarFrontCenter() );
-        m_sliderSonarFrontC->callback( SonarFrontSliderCenterCB, this );
+        m_sliderSonarFrontCL->label( "C Left" );
+        m_sliderSonarFrontCL->slider( FL_UP_BOX );
+        m_sliderSonarFrontCL->bounds( 0x0fff, 0 );
+        m_sliderSonarFrontCL->value( SonarFrontStatus::sonarFrontCenterLeft() );
+        m_sliderSonarFrontCL->callback( SonarFrontSliderCenterLeftCB, this );
     }
 
-    m_sliderSonarFrontR = new Fl_Slider( 375, 210, 40, 100 );
+    m_sliderSonarFrontCR = new Fl_Slider( 336, 210, 35, 100 );
+    if ( m_sliderSonarFrontCR )
+    {
+        m_sliderSonarFrontCR->label( "C Right" );
+        m_sliderSonarFrontCR->slider( FL_UP_BOX );
+        m_sliderSonarFrontCR->bounds( 0x0fff, 0 );
+        m_sliderSonarFrontCR->value( SonarFrontStatus::sonarFrontCenterRight() );
+        m_sliderSonarFrontCR->callback( SonarFrontSliderCenterRightCB, this );
+    }
+
+    m_sliderSonarFrontR = new Fl_Slider( 380, 210, 35, 100 );
     if ( m_sliderSonarFrontR )
     {
         m_sliderSonarFrontR->label( "Right" );
@@ -731,14 +761,16 @@
 {
     Fl::lock();
 
-    unsigned left   = SonarFrontStatus::sonarFrontLeft();
-    unsigned center = SonarFrontStatus::sonarFrontCenter();
-    unsigned right  = SonarFrontStatus::sonarFrontRight();
+    unsigned left        = SonarFrontStatus::sonarFrontLeft();
+    unsigned centerLeft  = SonarFrontStatus::sonarFrontCenterLeft();
+    unsigned centerRight = SonarFrontStatus::sonarFrontCenterRight();
+    unsigned right       = SonarFrontStatus::sonarFrontRight();
 
     if ( m_textSonarFront )
     {
         char buf[ 80 ];
-        snprintf( buf, sizeof( buf ), "%04X  %04X  %04X", left, center, right );
+        snprintf( buf, sizeof( buf ), "%04X %04X %04X %04X",
+                  left, centerLeft, centerRight, right );
         m_textSonarFront->label( buf );
     }
 
--- a/main/robots/odr-sim/SimDisplay.h	Sat Jun 08 11:49:25 2013 -0700
+++ b/main/robots/odr-sim/SimDisplay.h	Sat Jun 08 11:50:20 2013 -0700
@@ -80,7 +80,8 @@
         Fl_Toggle_Button* m_buttonB;
         Fl_Light_Button*  m_buttonSonarFrontKA;
         Fl_Slider*        m_sliderSonarFrontL;
-        Fl_Slider*        m_sliderSonarFrontC;
+        Fl_Slider*        m_sliderSonarFrontCL;
+        Fl_Slider*        m_sliderSonarFrontCR;
         Fl_Slider*        m_sliderSonarFrontR;
         Fl_Box*           m_textSonarFront;
         Poco::Timer       m_timerMainHbTimeout;
--- a/main/robots/odr-sim/SonarFrontStatus.cpp	Sat Jun 08 11:49:25 2013 -0700
+++ b/main/robots/odr-sim/SonarFrontStatus.cpp	Sat Jun 08 11:50:20 2013 -0700
@@ -71,9 +71,10 @@
 
     can_data_sonar_front data;
 
-    data.left   = SonarFrontStatus::sonarFrontLeft();
-    data.center = SonarFrontStatus::sonarFrontCenter();
-    data.right  = SonarFrontStatus::sonarFrontRight();
+    data.left         = SonarFrontStatus::sonarFrontLeft();
+    data.center_left  = SonarFrontStatus::sonarFrontCenterLeft();
+    data.center_right = SonarFrontStatus::sonarFrontCenterRight();
+    data.right        = SonarFrontStatus::sonarFrontRight();
 
     CANMessage::QueueToSend( new CANMessage( 
                 msgid, reinterpret_cast< uint8_t* >( &data ), sizeof( data ) ) );
@@ -82,10 +83,11 @@
 // ----------------------------------------------------------------------------------------
 
 Poco::RWLock SonarFrontStatus::sm_rwLock;
-bool         SonarFrontStatus::sm_isEnabled = false;
-unsigned     SonarFrontStatus::sm_left   = 0x0f00;
-unsigned     SonarFrontStatus::sm_center = 0x0f00;
-unsigned     SonarFrontStatus::sm_right  = 0x0f00;
+bool         SonarFrontStatus::sm_isEnabled   = false;
+unsigned     SonarFrontStatus::sm_left        = 0x0f00;
+unsigned     SonarFrontStatus::sm_centerLeft  = 0x0f00;
+unsigned     SonarFrontStatus::sm_centerRight = 0x0f00;
+unsigned     SonarFrontStatus::sm_right       = 0x0f00;
 
 // ----------------------------------------------------------------------------------------
 
@@ -121,10 +123,18 @@
 
 // ----------------------------------------------------------------------------------------
 
-unsigned SonarFrontStatus::sonarFrontCenter()
+unsigned SonarFrontStatus::sonarFrontCenterLeft()
 {
     Poco::RWLock::ScopedReadLock lock( sm_rwLock );
-    return sm_center;
+    return sm_centerLeft;
+}
+
+// ----------------------------------------------------------------------------------------
+
+unsigned SonarFrontStatus::sonarFrontCenterRight()
+{
+    Poco::RWLock::ScopedReadLock lock( sm_rwLock );
+    return sm_centerRight;
 }
 
 // ----------------------------------------------------------------------------------------
@@ -145,10 +155,18 @@
 
 // ----------------------------------------------------------------------------------------
 
-void SonarFrontStatus::setSonarFrontCenter( unsigned value )
+void SonarFrontStatus::setSonarFrontCenterLeft( unsigned value )
 {
     Poco::RWLock::ScopedWriteLock lock( sm_rwLock );
-    sm_center = value;
+    sm_centerLeft = value;
+}
+
+// ----------------------------------------------------------------------------------------
+
+void SonarFrontStatus::setSonarFrontCenterRight( unsigned value )
+{
+    Poco::RWLock::ScopedWriteLock lock( sm_rwLock );
+    sm_centerRight = value;
 }
 
 // ----------------------------------------------------------------------------------------
--- a/main/robots/odr-sim/SonarFrontStatus.h	Sat Jun 08 11:49:25 2013 -0700
+++ b/main/robots/odr-sim/SonarFrontStatus.h	Sat Jun 08 11:50:20 2013 -0700
@@ -45,10 +45,12 @@
         static void     setSonarFrontEnabled();
         static void     setSonarFrontDisabled();
         static unsigned sonarFrontLeft();
-        static unsigned sonarFrontCenter();
+        static unsigned sonarFrontCenterLeft();
+        static unsigned sonarFrontCenterRight();
         static unsigned sonarFrontRight();
         static void     setSonarFrontLeft( unsigned value );
-        static void     setSonarFrontCenter( unsigned value );
+        static void     setSonarFrontCenterLeft( unsigned value );
+        static void     setSonarFrontCenterRight( unsigned value );
         static void     setSonarFrontRight( unsigned value );
 
     public:
@@ -64,7 +66,8 @@
         static Poco::RWLock sm_rwLock;
         static bool         sm_isEnabled;
         static unsigned     sm_left;
-        static unsigned     sm_center;
+        static unsigned     sm_centerLeft;
+        static unsigned     sm_centerRight;
         static unsigned     sm_right;
 
     private: