elbow_dir = 6 #elbow direction pin swivel_continuous = 1 #pin for swivel motor ppin_shoulder = 5 #pin number for shoulder potentiometer ppin_elbow = 6 #pin number for elbow potentiomenter ppin_swivel = 7 #pin number for swivel potentiomenter print "shoulder_pul", shoulder_pul print "shoulder_dir", shoulder_dir print "elbow_pul", elbow_pul print "elbow_dir", elbow_dir print "swivel_continuous", swivel_continuous print "ppin_shoulder", ppin_shoulder print "ppin_elbow", ppin_elbow print "ppin_swivel", ppin_swivel RPL.pinMode( shoulder_pul, RPL.PWM) #set shoulder_pul pin as a pulse-width modulation output RPL.pinMode( shoulder_dir, RPL.OUTPUT) #set shoulder_dir pin to an output and write 1 to it RPL.pinMode(elbow_pul, RPL.PWM) #set elbow_pul pin as a pulse-width modulation output RPL.pinMode(elbow_dir, RPL.OUTPUT) #set elbow_dir pin to an output and write 1 to it except: print 'Motors unrunnable: unable to reach RoboPiLib_pwm' def motor_runner( ): #sends signals to all the motors based on potentiometer readings
def DT_PWM_Speedrange(): ServoR = int(raw_input(0)) RPL.pinMode(ServoR, RPL.PWM) ServoL = int(raw_input(1)) RPL.pinMode(ServoL, RPL.PWM)
from bsmLib import RPL RPL.init() sensor_pin = 5 RPL.pinMode(sensor_pin, RPL.INPUT) def analogRead(pin): putPacket(ANREAD, bytearray([5]), 1) buff = getPacket() return int(buff[3][1]) | (int(buff[3][2]) << 8) import RPL RPL.init() import time f_reverse = 1000 neutral = 1500 f_forward = 2000 #anglepersecond = 30 def DT_PWM_Speedrange(): ServoR = int(raw_input(0)) RPL.pinMode(ServoR, RPL.PWM) ServoL = int(raw_input(1)) RPL.pinMode(ServoL, RPL.PWM) # analogRead(1) = side slant left # analogRead(2) = side slant right # analogRead(3) = front left
from bsmLib import RPL RPL.init() import curses, time screen = curses.initscr() curses.noecho() curses.halfdelay(1) elbow_dir = 6 elbow_pul = 5 swivel_pin = 1 speed = 500 key = '' key_hit = time.time() RPL.pinMode(elbow_pul, RPL.PWM) RPL.pinMode(elbow_dir, RPL.OUTPUT) RPL.pinModw(shoulder_pul, RPL.PWM) RPL.pinMode(shoulder_dir, RPL.OUTPUT) while key != ord('1'): key = screen.getch() screen.clear() if key == ord('w'): screen.addstr('Moving elbow up') RPL.digitalWrite(elbow_dir, 0) RPL.pwmWrite(elbow_pul, speed, speed * 2) key_hit = time.time() if key == ord('s'): screen.addstr('Moving elbow down') RPL.digitalWrite(elbow_dir, 1)
from bsmLib import RPL RPL.init() import post_to_web as PTW RPL.pinMode(1, RPL.INPUT) RPL.analogRead(1) frana = 1 rfana = 2 rbana = 3 brana = 4 blana = 5 lbana = 6 lfana = 7 flana = 8 while True: PTW.state['FRanalog'] = FRanalog PTW.state['BRanalog'] = BRanalog PTW.state['LFanalog'] = LFanalog PTW.state['FLanalog'] = FLanalog PTW.state['RFanalog'] = RFanalog PTW.state['BLanalog'] = BLanalog PTW.state['LBanalog'] = LBanalog PTW.state['RBanalog'] = RBanalog PTW.post()
R = 1 # PWM PERIOD = 3000 ###################### ## 0. Setup ###################### # Create tcp connection and listen t = tcpServer(HOST, PORT) t.listen() RPL.init() # Init RoboPi hat connection # Set to PWM pin mode RPL.pinMode(L, RPL.PWM) RPL.pinMode(R, RPL.PWM) ###################### ## 1. drive ###################### def drive(): d = t.recv() if d == "stop": RPL.servoWrite(L, 0) RPL.servoWrite(R, 0) t.stop() exit() d = d.split(' ') l = int(map(float(d[0]), -1, 1, MIN, MAX))