def __init__(self):
        rospy.init_node('controller')

        rospy.Subscriber("cmd_vel", Twist, self.twist_callback)
        rospy.Subscriber("joy", Joy, self.joy_callback)

        self.volt_it = 0.009375
        self.volt_min = 4.8
        self.volt_max = 7.2

        self.adc = ADS1x15(ic=0x01)

        self.set_reference()

        self.dac_spd = MCP4725(0x062)
        self.dac_dir = MCP4725(0x063)
        scale = self.middle
        scale = scale / 4095 * 9.9
        scale = scale - 0.25
        scale = scale / 9.9 * 4095

        self.dac_spd.setVoltage(int(scale))
        self.dac_dir.setVoltage(int(scale))

        self.safe = False
        self.num_unsafe = 0
        self.N = 5
        self.old_axes = 0
        #rospy.Timer(rospy.Duration(0.1), self.runstop_callback)
        rospy.spin()
Ejemplo n.º 2
0
#!/usr/bin/env python

from Adafruit_MCP4725 import MCP4725
import SocketServer
import sys
import RPi.GPIO as GPIO
from math import fabs
from threading import Thread

HOST = ''
PORT = 31092
BUFFERSIZE = 4096
dac = MCP4725(0x60)

GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)


class TCPHandler(SocketServer.BaseRequestHandler):
    def handle(self):
        while True:
            try:
                data = float(self.request.recv(4096))
            except:
                pass
            print str(data)
            if (data < 0):
                data = -data
                GPIO.output(18, GPIO.HIGH)
            else:
                GPIO.output(18, GPIO.LOW)
Ejemplo n.º 3
0
    def __init__(self):
        self.LightSensor = TSL2561b.Adafruit_TSL2561()
        self.LightSensor.enableAutoGain(True)

        # Initialise the DAC using the default address
        self.dac = MCP4725(0x62)
Ejemplo n.º 4
0
    if val < 0: val = 0
    if val > 100: val = 100

    volts = BASE_SPEED + int(SPEED_RANGE * val / 100)

    # stop if val==0
    if val == 0: volts = 0

    if __last_volts != volts:
        print(f'fan level: {volts}/4096')
        DAC.set_voltage(volts)
        __last_volts = volts


if __name__ == "__main__":

    DAC = MCP4725(address=0x61, busnum=1)

    temp = sense_temp()
    print(f'temp: {temp}')

    if len(sys.argv) < 2:
        print(f'USAGE:\n\t{sys.argv[0]} fanspeed_out_of_100')
        sys.exit()

    speed = int(sys.argv[1])

    fan_speed(speed)

    exit()
Ejemplo n.º 5
0
  2048, 2148, 2248, 2348, 2447, 2545, 2642, 2737,
  2831, 2923, 3013, 3100, 3185, 3267, 3346, 3423,
  3495, 3565, 3630, 3692, 3750, 3804, 3853, 3898,
  3939, 3975, 4007, 4034, 4056, 4073, 4085, 4093,
  4095, 4093, 4085, 4073, 4056, 4034, 4007, 3975,
  3939, 3898, 3853, 3804, 3750, 3692, 3630, 3565 ]

# SETUP THE LIBRARY FOR THE 1015 (12-bit ADC)
ADS1015 = 0x00

# FIRE UP THE ADCS
adc1 = ADS1x15(address=0x49, ic=ADS1015)
adc2 = ADS1x15(address=0x48, ic=ADS1015)

# FIRE UP THE DACS
dac1 = MCP4725(0x60)
dac2 = MCP4725(0x61)

# NAP TIMINGS
nap1 = 1
nap2 = 5

# SET BOTH DACS TO FULL TO GET MAX OUTPUT VOLTAGE
print "----Calibrating----"
dac1.setVoltage(4095)
dac2.setVoltage(4095)
time.sleep(0.5)
maxV1 = adc1.readADCSingleEnded(0, gain, sps) / 1000
maxV2 = adc2.readADCSingleEnded(0, gain, sps) / 1000

print "DAC 1 Max = %.3f" % (maxV1)
import os, sys
import time
import datetime
import sys

sys.path.append(
    '/home/pi/cloned/Adafruit-Raspberry-Pi-Python-Code/Adafruit_I2C')
sys.path.append(
    '/home/pi/cloned/Adafruit-Raspberry-Pi-Python-Code/Adafruit_MCP4725')
sys.path.append('/home/pi/raspberrypi')
sys.path.append('/home/pi/raspberrypi_python')

from Adafruit_MCP4725 import MCP4725
import time

DAC_RESOLUTION = 12

# Initialise the DAC using the default address
dac = MCP4725(0x62)

if len(sys.argv) == 0:
    print 'Must supply a value 0->5 V'
    sys.exit(1)

# make sure input is between 0 and 5 V
value = min(float(sys.argv[1]), 5)
value = max(value, 0)
print "Output %.1f V" % value
val = int((value / 5.0) * 2**DAC_RESOLUTION)
dac.setVoltage(val)
Ejemplo n.º 7
0
# 2x Sapphire epoxy x center 2-26
centerY = 2.3458
#

#EXPANDED
#centerY = 2.956;
#centerX = 2.53;

voltageToPositionX = 4.12
# mm/V
voltageToPositionY = 3.52
# mm/V
laserSpotRadius = 0.949
#mm unexpanded

dac = MCP4725(0x62)
dacY = MCP4725(0x63)
x = 0

try:
    if mode == 1:
        # Goes from 0,0 to a point (x,y) in one move, then waits, then moves back

        #1) generate list of points (this will change depending on what we want to do)
        #xlist
        #xlist=[lev(centerX-0.50),lev(centerX-0.25),lev(centerX),lev(centerX+0.25),lev(centerX+0.50)]
        xlist = []
        for b in range(-4, 5):
            xlist.append(lev(centerX + b / 2.0))
            print(centerX + b / 2.0)
        #ylist
Ejemplo n.º 8
0
	def getError(self):
		return self.error

	def getIntegrator(self):
		return self.Integrator

	def getDerivator(self):
		return self.Derivator


#breakout board addresses

adc_address1 = 0x6A #address of ADC CH1-CH4
adc_address2 = 0x6B #address of ADC CH5-CH8
dac = MCP4725(0x62) #address of DAC board
DAC_RESOLUTION = 12 #DAC Resolution

# create byte array and fill with initial values to define size
adcreading = bytearray()

adcreading.append(0x00)
adcreading.append(0x00)
adcreading.append(0x00)
adcreading.append(0x00)

varDivisior = 64 # from pdf sheet on adc addresses and config
varMultiplier = (2.4705882/varDivisior)/1000

# detect i2C port number and assign to i2c_bus
for line in open('/proc/cpuinfo').readlines():