Example #1
0
def standby(state):
    if state:
        pwmExp.setupDriver(pins.STBY, 100, 0)
        print("Standby Activated!")
    else:
        pwmExp.setupDriver(pins.STBY, 0, 0)
        print("Standby Disabled!")
def ws_on_message(ws, message: str):
    ignore_list = ['{"type":6}', '{}']
    for msg in message.split(chr(0x1E)):
        if msg and msg not in ignore_list:
            print(f"From server: {msg}")
            jmsg = json.loads(msg)
            print(jmsg["arguments"][1])
            # orientation read from signar message
            lrangle = float(jmsg["arguments"][1])
            #converting the orientation to a PWM signal
            x = (lrangle + 90.0) / 180.0
            dutycycle = 3.0 + x * (13.5 - 3.0)
            pwmExp.setupDriver(0, dutycycle, 0)
Example #3
0
def robot_init():
    print("I/O Initialization")
    print("PWM Starting")
    pwmExp.driverInit()
    pwmExp.setupDriver(pins.ALL, 0, 0)
    pwmExp.setVerbosity(-1)

    print("Setting I/O")
    ain2.setOutputDirection(LOW)
    ain1.setOutputDirection(LOW)
    bin2.setOutputDirection(LOW)
    bin1.setOutputDirection(LOW)
    print("Ready!")
Example #4
0
    def setDutyCycle(self, duty):
        """Set duty cycle for pwm channel"""
        ret = pwmExp.setupDriver(self.channel, duty, 0)
        if (ret != 0):
            print 'ERROR: pwm-exp setupDriver not successful!'

        return ret
Example #5
0
	def setDutyCycle(self, duty):
		"""Set duty cycle for pwm channel"""
		ret 	= pwmExp.setupDriver(self.channel, duty, 0)
		if (ret != 0):
			print 'ERROR: pwm-exp setupDriver not successful!'

		return ret
Example #6
0
def SetLeftRight( speed_left, speed_right):
   "This moves the robot forward with speeds for left and right"
   pwmExp.setupDriver(7, speed_left, 0)
   pwmExp.setupDriver(8, speed_right * STEERING_ADJUST, 0)
   return
Example #7
0
def Stop():
   "This stops the robot"
   pwmExp.setupDriver(-1, 0, 0)
   return
Example #8
0
def Stop():
    "This stops the robot"
    pwmExp.setupDriver(-1, 0, 0)
    #   print "Stopped."
    return
Example #9
0
import OmegaExpansion.pwmExp as pwm
import sys

status = pwm.driverInit()

if pwm.checkInit() == 0:
    print("PWM Init failed")
    exit

lr = float(sys.argv[1])
ud = float(sys.argv[2])

pwm.setFrequency(50)
pwm.setupDriver( 0, lr, 0)
pwm.setupDriver(15, ud, 0)
Example #10
0
print "driverInit return: ", ret
if (ret != 0):
    exit()
ret = pwmExp.setFrequency(50)
print "setFrequency return: ", ret
if (ret != 0):
    exit()

# check initialization
#	should return 1 since the Expansion was initialized above
ret = pwmExp.checkInit()
print "checking if initialized: ", ret
time.sleep(1)

# set channel 0
ret = pwmExp.setupDriver(channel, 9, 0)
print "setupDriver return: ", ret
if (ret != 0):
    exit()
time.sleep(2)

# set channel 0
ret = pwmExp.setupDriver(channel, 5, 0)
print "setupDriver return: ", ret
if (ret != 0):
    exit()
time.sleep(2)

# change the frequency
ret = pwmExp.setFrequency(60)
print "setFrequency return: ", ret
Example #11
0
	with open ('/tmp/pid.conf', 'r') as f:
		config = f.readline().split(',')
		pid.SetPoint = float(config[0])
		targetT = pid.SetPoint
		pid.setKp (float(config[1]))
		pid.setKi (float(config[2]))
		pid.setKd (float(config[3]))

def createConfig ():
	if not os.path.isfile('/tmp/pid.conf'):
		with open ('/tmp/pid.conf', 'w') as f:
			f.write('%s,%s,%s,%s'%(targetT,P,I,D))

createConfig()

while 1:
	readConfig()
	#read temperature data
	a0 = adc.read_voltage(0)
	temperature = (a0 - 0.5) * 100

	pid.update(temperature)
	targetPwm = pid.output
	targetPwm = max(min( int(targetPwm), 100 ),0)

	print "Target: %.1f C | Current: %.1f C | PWM: %s %%"%(targetT, temperature, targetPwm)

	# Set PWM expansion channel 0 to the target setting
	pwmExp.setupDriver(0, targetPwm, 0)
	time.sleep(0.5)
Example #12
0
print("I/O Initialization")

# Instantiate

ain2 = onionGpio.OnionGpio(pins.AIN2)
ain1 = onionGpio.OnionGpio(pins.AIN1)
bin2 = onionGpio.OnionGpio(pins.BIN2)
bin1 = onionGpio.OnionGpio(pins.BIN1)

# All Outputs, low default

print("PWM Starting")

pwmExp.driverInit()
pwmExp.setupDriver(pins.ALL, 0, 0)

print("Setting I/O")

ain2.setOutputDirection(LOW)
ain1.setOutputDirection(LOW)
bin2.setOutputDirection(LOW)
bin1.setOutputDirection(LOW)

print("Ready")

# 1. Set Standby to HIGH

pwmExp.setupDriver(pins.STBY, 100, 0)

################################# A
Example #13
0
if (ret != 0):
	exit()
ret 	= pwmExp.setFrequency(50)	
print "setFrequency return: ", ret
if (ret != 0):
	exit()

# check initialization
#	should return 1 since the Expansion was initialized above
ret 	= pwmExp.checkInit()
print "checking if initialized: ", ret
time.sleep(1)


# set channel 0
ret 	= pwmExp.setupDriver(channel, 9, 0)
print "setupDriver return: ", ret
if (ret != 0):
	exit()
time.sleep(2)

# set channel 0
ret 	= pwmExp.setupDriver(channel, 5, 0)
print "setupDriver return: ", ret
if (ret != 0):
	exit()
time.sleep(2)

# change the frequency
ret 	= pwmExp.setFrequency(60)
print "setFrequency return: ", ret
Example #14
0
def set_speed(pwm, speed):
    pwmExp.setupDriver(pwm, speed, 0)
Example #15
0
def safe():
    pwmExp.setupDriver(pins.ALL, 0, 0)
    ain1.setValue(LOW)
    ain2.setValue(LOW)
    bin1.setValue(LOW)
    bin2.setValue(LOW)