[ create a new paste ] login | about

Link: http://codepad.org/x1tMNeEt    [ raw code | fork ]

meigrafd - Python, pasted on Sep 29:
#
#   RobotRadar - Class for control of ultrasonic rangefinder
#
#   Version: 0.1
#   Creator: meigrafd
#   Copyright (C) 2016 by meiraspi@gmail.com published under the MIT License
#
#   DETECTION FIELD
#   02 -  2
#   04 -  3
#   06 -  4
#   08 -  5
#   10 -  6
#   12 -  7
#   14 -  8
#   16 -  9
#   18 -  10
#   20 -  10
#   22 -  11
#   MAX - 11
#
import time
import logging

class RadarClass(object):
    arduino = ""
    utility = ""
    sensor = ""
    settings = {}
    
    # Pin assignments for radar operations - loaded from settings
    rangePin = 0
    triggerPin = 0
    
    logger = ""
    
    def __init__(self, arduino, sensor, utility, settings, status, telemetry):
        self.arduino = arduino
        self.sensor = sensor
        self.utility = utility
        self.settings = settings
        self.status = status
        self.telemetry = telemetry

        # Setup logging by connecting to our main logger
        self.logger = logging.getLogger('Main.' + __name__)

        # Get our pin assignments from the settings
        self.rangePin = self.settings["pins"]["UltraSonic_Echo"]
        self.triggerPin = self.settings["pins"]["UltraSonic_Trig"]
        self.utility.arduinoReturn(self.arduino.pinModeOutput(self.triggerPin))
        self.utility.arduinoReturn(self.arduino.pinModeInput(self.rangePin))

        self.utility.logger("debug", "Initialized radar")
        self.arduino.LCD(0, "Radar up")

    # ------------------------------------------------------------------------
    def range(self):
        """
        Returns the range
        """
        self.utility.timingDisplay("Radar", False)
        range = int(self.utility.arduinoReturn(self.arduino.pwmPulseLow(self.rangePin, self.triggerPin)))
        range = (range / 50 / 2.56) * self.telemetry["rangeAdjust"]
        self.telemetry["range"] = range
        self.utility.timingDisplay("Radar", True)
        return range

#EOF


Create a new paste based on this one


Comments: