changeset 143:403240057abc main

ODR remote ESTOP controller. First check-in. This is really simple, as there is only a transmitter, a push button, and a status LED.
author Bob Cook <bob@bobcookdev.com>
date Mon, 21 May 2012 14:51:07 -0700
parents cf9723976178
children 1f998d3a559a
files main/robots/odr-remote/jamfile main/robots/odr-remote/main.cpp main/robots/odr-remote/project_defs.h
diffstat 3 files changed, 263 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main/robots/odr-remote/jamfile	Mon May 21 14:51:07 2012 -0700
@@ -0,0 +1,43 @@
+# -----------------------------------------------------------------------------------------
+#
+#   Copyright (C) 2012 Bob Cook
+#
+#   Bob Cook Development, Robotics Library
+#   http://www.bobcookdev.com/rl/
+#    
+#   Permission is hereby granted, free of charge, to any person obtaining a copy
+#   of this software and associated documentation files (the "Software"), to deal
+#   in the Software without restriction, including without limitation the rights
+#   to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+#   copies of the Software, and to permit persons to whom the Software is
+#   furnished to do so, subject to the following conditions:
+#
+#   The above copyright notice and this permission notice shall be included in
+#   all copies or substantial portions of the Software.
+#
+#   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+#   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+#   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+#   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+#   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+#   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+#   THE SOFTWARE.
+#
+# -----------------------------------------------------------------------------------------
+
+if $(TRACE) { echo "trace /robots/odr-remote/jamfile" ; }
+
+SubDir TOP robots odr-remote ;
+
+# -----------------------------------------------------------------------------------------
+
+avr_executable
+    odr-remote atmega8
+    : main.cpp
+      packages.avr.device.pkg
+      packages.avr.rfcomm.pkg
+      packages.common.util.pkg
+    ;
+
+# -----------------------------------------------------------------------------------------
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main/robots/odr-remote/main.cpp	Mon May 21 14:51:07 2012 -0700
@@ -0,0 +1,176 @@
+// ----------------------------------------------------------------------------------------
+//
+//  Copyright (C) 2012 Bob Cook
+//    
+//  Bob Cook Development, Robotics Library
+//  http://www.bobcookdev.com/rl/
+// 
+//  Remote kill switch transmitter.
+//
+//  Permission is hereby granted, free of charge, to any person obtaining a copy
+//  of this software and associated documentation files (the "Software"), to deal
+//  in the Software without restriction, including without limitation the rights
+//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+//  copies of the Software, and to permit persons to whom the Software is
+//  furnished to do so, subject to the following conditions:
+// 
+//  The above copyright notice and this permission notice shall be included in
+//  all copies or substantial portions of the Software.
+// 
+//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+//  THE SOFTWARE.
+//
+// ----------------------------------------------------------------------------------------
+
+#include <avr/interrupt.h>
+#include <avr/io.h>
+#include <avr/pgmspace.h>
+#include <avr/sleep.h>
+
+#include "project_defs.h"
+
+#include "packages/avr/device/spinwait.h"
+#include "packages/avr/rfcomm/rfcomm_tx.h"
+#include "packages/common/util/misc.h"
+
+// ----------------------------------------------------------------------------------------
+
+static volatile bool g_transmit;
+
+// ----------------------------------------------------------------------------------------
+
+ISR( TIMER0_OVF_vect )
+{
+    static uint8_t counter = 0;
+
+    if ( ++counter > 15 )   // reduces 30 Hz to 2 Hz
+    {
+        g_transmit = true;
+        counter = 0;
+    }
+}
+
+// ----------------------------------------------------------------------------------------
+
+ISR( TIMER2_COMP_vect )
+{
+    rfcomm_tx_run_task();
+}
+
+// ----------------------------------------------------------------------------------------
+
+int main()
+{
+    //--    Input switch is on PORTD.6, enable the pull-up resistor.
+
+    DDRD  &= ~( 1 << PD6 );
+    PORTD |=  ( 1 << PD6 );
+
+    //--    LED is on PORTB.0.
+    
+    DDRB |= ( 1 << PB0 );
+
+    //--    Say hello.
+
+    for ( uint8_t i = 0; i < 10; ++i )
+    {
+        PORTB ^= ( 1 << PB0 ); // led toggle
+        spinwait_delay_ms( 75 );
+    }
+
+    PORTB |= ( 1 << PB0 ); // led off
+
+    //--    Set up a 30 Hz (approximate) "heartbeat" interrupt timer using the overflow
+    //      interrupt routine.
+
+    TCCR0 = 0
+          | ( 1 << CS02 ) | ( 0 << CS01 ) | ( 1 << CS00 )   // clk/1024
+          ;
+
+    TIMSK |= ( 1 << TOIE0 );
+
+    //--    Set up a 312.5 Hz (approximate) interrupt timer for the transmitter.
+
+    TCCR2 = 0
+          | ( 0 << WGM20 )                                  // CTC
+          | ( 0 << COM21 ) | ( 0 << COM20 )                 // OC2 disconnected
+          | ( 1 << WGM21 )                                  // CTC
+          | ( 1 << CS22  ) | ( 1 << CS21  ) | ( 1 << CS00 ) // clk/1024
+          ;
+
+    OCR2 = 25;
+
+    TIMSK |= ( 1 << OCIE2 );
+
+    //--    When we sleep we want the "idle" mode e.g. wake up on any interrupt.
+    
+    set_sleep_mode( SLEEP_MODE_IDLE );
+    
+    //--    Initialize the transmitter module.
+    
+    rfcomm_tx_init();
+
+    //--    Enable interrupts.
+    
+    sei();
+
+    //--    Start the main loop.
+
+    uint8_t outgoing = static_cast< uint8_t >( 'A' );
+
+    for ( ;; )
+    {
+        //--    Sleep until there is a new interrupt (the transmitter gets one, as does
+        //      the periodic heartbeat, so we won't sleep forever).
+        
+        sleep_mode();
+
+        //--    Time to transmit? If not just continue.
+        
+        if ( ! g_transmit )
+        {
+            continue;
+        }
+
+        g_transmit = false;
+
+        //--    Yes time to transmit, but only if the button is down. The LED matches
+        //      the state of transmitting.
+        
+        if ( ( PIND & ( 1 << PD6 ) ) == 0 )
+        {
+            PORTB &= ~( 1 << PB0 ); // led on
+
+            uint8_t txbuf[ 4 ];
+            txbuf[ 0 ] = outgoing;
+            txbuf[ 1 ] = outgoing + 1;
+            txbuf[ 2 ] = outgoing + 2;
+            txbuf[ 3 ] = outgoing + 3;
+
+            rfcomm_tx_send( txbuf, array_sizeof( txbuf ) );
+
+            if ( outgoing == static_cast< uint8_t >( 'W' ) )
+            {
+                outgoing = static_cast< uint8_t >( 'A' );
+            }
+            else
+            {
+                ++outgoing;
+            }
+        }
+        else
+        {
+            PORTB |= ( 1 << PB0 ); // led off
+        }
+    }
+
+    return 0;
+}
+
+// ----------------------------------------------------------------------------------------
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main/robots/odr-remote/project_defs.h	Mon May 21 14:51:07 2012 -0700
@@ -0,0 +1,44 @@
+// ----------------------------------------------------------------------------------------
+//
+//  robots/odr-remote/project_defs.h
+//  Copyright (C) 2012 Bob Cook
+//
+//  Permission is hereby granted, free of charge, to any person obtaining a copy
+//  of this software and associated documentation files (the "Software"), to deal
+//  in the Software without restriction, including without limitation the rights
+//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+//  copies of the Software, and to permit persons to whom the Software is
+//  furnished to do so, subject to the following conditions:
+//  
+//  The above copyright notice and this permission notice shall be included in
+//  all copies or substantial portions of the Software.
+//  
+//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+//  THE SOFTWARE.
+//
+// ----------------------------------------------------------------------------------------
+
+#if !defined( PROJECT_DEFS_H )
+#define PROJECT_DEFS_H
+
+// ----------------------------------------------------------------------------------------
+
+#define PRJ_CPU_FREQ    8000000L
+
+// ----------------------------------------------------------------------------------------
+
+#define PRJ_RFCOMM_TX_ENABLE
+
+#define PRJ_RFCOMM_TX_DDR   DDRD
+#define PRJ_RFCOMM_TX_PORT  PORTD
+#define PRJ_RFCOMM_TX_PIN   PD7
+
+
+#endif // #if !defined( PROJECT_DEFS_H )
+// ----------------------------------------------------------------------------------------
+