@@ -0,0 +1,2941 @@
+#!/usr/bin/env python%0A#%0A# Copyright 2017 Robot Garden, Inc.%0A#%0A# Licensed under the Apache License, Version 2.0 (the %22License%22);%0A# you may not use this file except in compliance with the License.%0A# You may obtain a copy of the License at%0A#%0A#      http://www.apache.org/licenses/LICENSE-2.0%0A#%0A# Unless required by applicable law or agreed to in writing, software%0A# distributed under the License is distributed on an %22AS IS%22 BASIS,%0A# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A# See the License for the specific language governing permissions and%0A# limitations under the License.%0A#%0A############################################################%0A#  Node to monitor magnetic wheel sensor%0A#  Sensor provides 2 digital outputs to UP GPIO:%0A#    1) moving: true if the wheel is rotating%0A#    2) direction: true if wheel direction is forward%0A#  Note: the direction signal from the sensor is not valid for the first %0A#    approx 1/2 wheel rotation when starting from a stopped condition%0A#%0A#  This node publishes on topic 'wheel' a String message with values:%0A#    * 'Not moving'%0A#    * 'Moving forward'%0A#    * 'Moving reverse'%0A#    * 'Moving direction unknown'%0A############################################################%0A%0Aimport rospy%0Aimport rospkg%0Aimport RPi.GPIO as GPIO%0Aimport time%0A%0Afrom std_msgs.msg import String%0A       %0Adef wheel_sensor():%0A    NODE_FREQ = 20  # Hz%0A    rospy.init_node('wheel_sensor', anonymous=True)%0A    pubWheel  = rospy.Publisher('wheel', String, queue_size=10)%0A    rate = rospy.Rate(NODE_FREQ)  %0A%0A    moving_gpio_pin = 29%0A    direction_gpio_pin = 31%0A    GPIO.setmode(GPIO.BOARD)%0A%0A    GPIO.setup(moving_gpio_pin, GPIO.IN)%0A    GPIO.setup(direction_gpio_pin, GPIO.IN)%0A%0A    DIRECTION_BLACKOUT = 0.5  # seconds after standing start when direction signal is invalid%0A%0A    while not rospy.is_shutdown():%0A        try:%0A            if not GPIO.input(moving_gpio_pin):%0A                pubWheel.publish(%22Not moving%22)%0A                start_time = time.time()  # gets reset every 1/NODE_FREQ sec%0A                elapsed_time = 0%0A            else:%0A                if elapsed_time %3E DIRECTION_BLACKOUT:%0A                    if GPIO.input(direction_gpio_pin):%0A                        pubWheel.publish(%22Moving forward%22)%0A                    else:%0A                        pubWheel.publish(%22Moving reverse%22)%0A                else:%0A                    pubWheel.publish(%22Moving direction unknown%22)%0A                    elapsed_time = time.time() - start_time  # how long have we been moving%0A            rate.sleep()%0A%0A        except Exception, e:%0A            # print e%0A            #Revert all GPIO pins to their normal states (i.e. input = safe)%0A            GPIO.cleanup()%0A            # break %0A%0Aif __name__ == '__main__':%0A    # Start the node%0A    try:%0A        wheel_sensor()%0A    except rospy.ROSInterruptException:%0A        #Revert all GPIO pins to their normal states (i.e. input = safe)%0A        GPIO.cleanup()%0A        pass%0A%0A

Add wheel_sensor node