def __init__(s, pd): """ initializer """ # Get object instance of necessary data s.current = pd.current s.position = pd.position # Setup pin positions hd.setup(s._DFR, hd.OUT) hd.setup(s._DFL, hd.OUT) hd.setup(s._DBR, hd.OUT) hd.setup(s._DBL, hd.OUT) hd.setup(s._SAFETY, hd.OUT) s._pwmfr = hd.pwm(s._PFR, 333) # 333 Hz beacuse I did the math s._pwmfl = hd.pwm(s._PFL, 333) s._pwmbr = hd.pwm(s._PBR, 333) s._pwmbl = hd.pwm(s._PBL, 333) # Calculate quiescent sensor values s.nominal_f = s.current[_FF] s.nominal_b = s.current[_BB] s.error["last_action"] = "init"
def __init__(s, pd): """ initializer """ # Get object instance of necessary data s.current = pd.current s.position = pd.position # Setup pin positions hd.setup(s.DFR, hd.OUT) hd.setup(s.DFL, hd.OUT) hd.setup(s.DBR, hd.OUT) hd.setup(s.DBL, hd.OUT) s.pwmfr = hd.pwm(s.PFR, 490) s.pwmfl = hd.pwm(s.PFL, 490) s.pwmbr = hd.pwm(s.PBR, 490) s.pwmbl = hd.pwm(s.PBL, 490) # Calculate quiescent sensor values s.nominal_f = s.current[_FF] s.nominal_b = s.current[_BB] s.error["last_action"] = "init"
def __init__(s, pd): s.current = pd.current #this has to be a reference, not a value s.brakeposition = pd.sensors.brakes.position #need to know how this works hd.setup(s.DFR, hd.OUT) hd.setup(s.DFL, hd.OUT) hd.setup(s.DBR, hd.OUT) hd.setup(s.DBL, hd.OUT) s.nominal_f = s.current["front"] s.nominal_b = s.current["back"] s.pwm_fr = hd.pwm(s.PFR, 490) s.pwm_fl = hd.pwm(s.PFL, 490) s.pwm_br = hd.pwm(s.PBR, 490) s.pwm_bl = hd.pwm(s.PBL, 490) s.status = "UNKNOWN" s.disengage()
def __init__(self, pin): self.current_angle = 90 self.pin = pin GPIO.setmode(GPIO.BOARD) GPIO.setup(pin, GPIO.OUT) self.pwm = GPIO.pwm(pin, 50) self.pwm.start(0) self.lock = Lock() self.kill_event = Event() self.thread = ThreadPublisher(self, self.kill_event) self.thread.daemon = True self.start()
def update(): # Make the request try: raw_json = urllib2.urlopen(url).read() except Exception: print('Exception: ' + traceback.format_exc()) sys.exit() # Parse the request and extract the icon id parsed_json = json.loads(raw_json) try: icon_code = parsed_json['weather'][0]['icon'] except Exception: print('Exception: ' + traceback.format_exc()) sys.exit() # Choose the angle of the arrow based on the first 2 chars of the icon ID # Last char is irrelevant as it's 'd' or 'n' for day or night # (See icons at http://openweathermap.org/weather-conditions) angle = { '01': 10, # Sun '02': 30, # Sun behind cloud '03': 50, # Cloud '04': 70, # Cloud with grey cloud '09': 90, # Cloud with grey cloud and rain '10': 110, # Cloud with sun and rain '11': 130, # Cloud with grey cloud and thunder '13': 150, # Cloud with grey cloud and snow '50': 170 # Wavy lines }.get(icon_code[0:2]) # Convert the angle to a number 0-100 then send to the servo pwm = GPIO.pwm(18, 0.5) pwm.start(5) duty = float(angle) / 10.0 + 2.5 # Why does this work? # duty = (angle/180.0) * 100.0 Isn't this more correct?? pwm.ChangeDutyCycle(duty) # Call update() again in an hour s.enter(3600, 1, update, ()) s.run()
import RPi.GPIO as gpio import time gpio.setmode(gpio.BOARD) pwm_obj = gpio.pwm(8, 400) #400 is the frequency pwm_obj.start(100) # argument is the duty cycle from 0 to 100
#check for compatibility of servo with the board #servos are controled using pwm pins #50 Hz control signal #posn of servo depends on pulse width of on part of the cycle #trial and error aproach to find duty(first try 1 for full left , 1.5 for middle or 2 for full right; if doesent work continue) #for experimenting duty values: import RPi.GPIO as gpio gpio.setmode(gpio.BOARD) pin = 11 gpio.setup(pin, gpio.OUT) pwm = gpio.pwm(pin, 50) #servo likes 50Hz duty = int(input("Enter duty value : ")) pwm.start(duty) #trial and error to find the exact duty for perticular angle #when done pwm.stop() gpio.cleanup() #to make the servo work on basis of angle and not duty, #make a function for line joining points for full left (0,duty_for_left) and full right (180,Duty_for_right) #input x= angle and output y= duty #then code to move servo to an input angle: def move(angle): #assuming return ((angle / float(something)) + 2) import RPi.GPIO as gpio gpio.setmode(gpio.BOARD)
import RPi.GPIO as GPIO import math #pin setup GPIO.setmode (GPIO.BCM): led = 27 GPIO.setup(led,GPIO.OUT) gate =16 GPIO.setup(gate,GPIO.OUT) tmotor = 12 GPIO.setup (tmotor, GPIO.OUT) tmotorpwm= GPIO.PWM(tmotor,50) tmotorpwm.start(0) lmotor = 18 GPIO.setup(lmotor,GPIO.OUT) lmotorpwm=GPIO.pwm(lmotor,50) lmotorpwm.start(5) Trig_sr04=23 GPIO.setup(Trig_sr04, GPIO.OUT) GPIO.output(Trig_sr04, False) Echo_sr04=24 GPIO.setup(Echo_sr04, GPIO.IN) #for rotation of turtlebot pub=rospy.Publisher('/cmd_vel', Twist, queue_size=10) rate= rospy.Rate(1) rot = Twist() vel_msg=() # setting the raspberry pi resolution and frame rate camera = PiCamera()