Esempio n. 1
0
def enable_encoder_in_async(encnum, numwires, pullup, edge):
    encctl = enc_enable + enc_async
    if numwires:
        encctl = encctl + enc_2wires
    if pullup:
        encctl = encctl + enc_pupen
    if edge:
        encctl = encctl + enc_fall
    trik_protocol.write_reg(encnum, ectl, encctl)
Esempio n. 2
0
def enable_i2c(i2cnum):
    trik_protocol.write_reg(i2cnum, ictl, i2c_enable + i2c_pull)
Esempio n. 3
0
def stress_test_writing():
    global testregvals
    devaddr = motor1
    while devaddr <= motor4:
        f1 = open(freport1, "a")
        f2 = open(freport2, "a")
        regaddr = 0x00
        while regaddr <= 0x06:
            stmp1 = "\n----------" + datetime.datetime.now().isoformat(
            ) + "----------\n"
            f1.write(stmp1)
            stmp1 = "----------Device address: 0x%02X---------------- \n" % (
                devaddr)
            f1.write(stmp1)
            stmp1 = "----------Register address: 0x%02X-------------- \n" % (
                regaddr)
            f1.write(stmp1)
            stmp1 = "DEV=0x%02X REG=0x%02X" % (devaddr, regaddr)
            print stmp1
            regval = 0x0000
            while regval < 0xFFFFF:
                stmp1 = "\n Writing... \n"
                f1.write(stmp1)
                stmp1 = "Register value: 0x%08X \n" % (regval)
                f1.write(stmp1)
                stmp2 = stmp1 = trik_protocol.write_reg(
                    devaddr, regaddr, regval)
                rval, daddr, rcode, ecode = trik_protocol.get_reg_value(stmp1)
                # Report only if anomaly is present
                errflg = 1
                if devaddr >= motor1 and devaddr <= motor4 and regaddr <= 0x06 and rcode == 0x03 and rval == 0x00:
                    errflg = 0
                if devaddr >= sensor1 and devaddr <= sensor18 and regaddr <= 0x02 and rcode == 0x03 and rval == 0x00:
                    errflg = 0
                if devaddr >= encoder1 and devaddr <= encoder4 and regaddr <= 0x01 and rcode == 0x03 and rval == 0x00:
                    errflg = 0
                if devaddr >= port1 and devaddr <= portJ and regaddr <= 0x08 and rcode == 0x03 and rval == 0x00:
                    errflg = 0
                if devaddr == a_timer and regaddr <= 0x02 and rcode == 0x03 and rval == 0x00:
                    errflg = 0
                if devaddr == touch and regaddr <= 0x08 and rcode == 0x03 and rval == 0x00:
                    errflg = 0
                if devaddr == bsl and rcode == 0x03 and rval == 0x00:
                    errflg = 0
                if devaddr >= motor1 and devaddr <= motor4 and regaddr > 0x06 and rcode == 0x83 and rval == 0x02:
                    errflg = 0
                if devaddr >= sensor1 and devaddr <= sensor18 and regaddr > 0x02 and rcode == 0x83 and rval == 0x02:
                    errflg = 0
                if devaddr >= encoder1 and devaddr <= encoder4 and regaddr > 0x01 and rcode == 0x83 and rval == 0x02:
                    errflg = 0
                if devaddr >= port1 and devaddr <= portJ and regaddr > 0x08 and rcode == 0x83 and rval == 0x02:
                    errflg = 0
                if devaddr == a_timer and regaddr > 0x02 and rcode == 0x83 and rval == 0x02:
                    errflg = 0
                if devaddr == touch and regaddr > 0x08 and rcode == 0x83 and rval == 0x02:
                    errflg = 0
                if devaddr == bsl and rcode == 0x83:
                    errflg = 0
                if devaddr > maxdevices and rcode == 0x83 and rval == 0x11:
                    errflg = 0
                if devaddr >= motor1 and devaddr <= motor4 and rcode == 0x83 and rval == 0x15:
                    errflg = 0
                if ecode != 0:
                    errflg = 1
                if devaddr != daddr:
                    errflg = 1
                if errflg != 0:
                    if rcode < 0x80:
                        stmp1 = "No error \n"
                    else:
                        stmp1 = "Error flag set \n"
                    f1.write(stmp1)
                    if rval <= 0x15:
                        stmp1 = "Error code: 0x%08X, %s \n" % (
                            rval, testerrors[rval])
                    else:
                        stmp1 = "Error code: 0x%08X, %s \n" % (rval,
                                                               "Undefined")
                    f1.write(stmp1)
                    stmp1 = "Packet error: 0x%02X \n" % (ecode)
                    f1.write(stmp1)
                    f1.write("Received string: " + stmp2 + "\n")
                    stmp1 = "DEV=0x%02X REG=0x%02X SEND=0x%08X RECV=0x%08X PACK=0x%02X STR=%s" % (
                        devaddr, regaddr, regval, rval, ecode, stmp2)
                    f2.write(stmp1 + "\n")
                    print stmp1
                regval = regval + 1
            regaddr = regaddr + 1
        f1.close()
        f2.close()
        devaddr = devaddr + 1
Esempio n. 4
0
def brake_motor(motnum):
    trik_protocol.write_reg(motnum, mctl, mot_enable + mot_brake)
Esempio n. 5
0
def start_motor(motnum):
    trik_protocol.write_reg(motnum, mctl, mot_enable + mot_power)
Esempio n. 6
0
def set_motor_angle(motnum, motangle):
    trik_protocol.write_reg(motnum, mang, motangle)
Esempio n. 7
0
def set_motor_period(motnum, pwmper):
    trik_protocol.write_reg(motnum, mper, pwmper)
Esempio n. 8
0
def rotate_motor_angle(motnum):
    trik_protocol.write_reg(
        motnum, mctl,
        mot_enable + mot_power + mot_auto + mot_angle + mot_brake)
Esempio n. 9
0
__author__ = 'Rostislav Varzar'

import time, os, thread
import trik_protocol, trik_stty, trik_power


# Init Serial TTY device
trik_stty.init_stty()

# Init 12 V power in ARM controller
trik_power.enable_power()

# Clear screen
os.system("clear")

thread.start_new_thread(trik_protocol.thread1_read_device, ())
time.sleep(5)

while True:
    print trik_protocol.write_reg(0x00, 0x00, 0x00)
    time.sleep(0.01)








Esempio n. 10
0
def read_i2c_sensor(i2cnum):
    trik_protocol.write_reg(i2cnum, ictl, i2c_enable + i2c_pull + i2c_sens)
    return trik_protocol.read_reg(i2cnum, ival)
Esempio n. 11
0
def set_i2c_sensor_parameter(i2cnum, i2csenspar):
    trik_protocol.write_reg(i2cnum, ipar, i2csenspar)
Esempio n. 12
0
def set_i2c_sensor_type(i2cnum, i2csenstype):
    trik_protocol.write_reg(i2cnum, iidx, i2csenstype)
Esempio n. 13
0
def write_i2c(i2cnum, i2cdev, i2creg, i2cdat):
    trik_protocol.write_reg(i2cnum, idev, i2cdev)
    trik_protocol.write_reg(i2cnum, ireg, i2creg)
    trik_protocol.write_reg(i2cnum, idat, i2cdat)
    trik_protocol.write_reg(i2cnum, ictl, i2c_enable + i2c_pull + i2c_write)
Esempio n. 14
0
def read_i2c(i2cnum, i2cdev, i2creg):
    trik_protocol.write_reg(i2cnum, idev, i2cdev)
    trik_protocol.write_reg(i2cnum, ireg, i2creg)
    trik_protocol.write_reg(i2cnum, idat, 0x00)
    trik_protocol.write_reg(i2cnum, ictl, i2c_enable + i2c_pull + i2c_read)
    return trik_protocol.read_reg(i2cnum, idat)
Esempio n. 15
0
def disable_i2c(i2cnum):
    trik_protocol.write_reg(i2cnum, ictl, i2c_disable)
Esempio n. 16
0
def timer_disable():
    trik_protocol.write_reg(timer1, atctl, 0x0000)
Esempio n. 17
0
def set_timer_period(tmper):
    trik_protocol.write_reg(timer1, atper, tmper)
Esempio n. 18
0
def enable_sensor_in_async(sensnum, pullup):
    sensctl = sens_enable + sens_read + sens_async
    if pullup:
        sensctl = sensctl + sens_pull
    trik_protocol.write_reg(sensnum, sctl, sensctl)
Esempio n. 19
0
def reverse_motor_time(motnum):
    trik_protocol.write_reg(
        motnum, mctl, mot_enable + mot_power + mot_auto + mot_back + mot_brake)
Esempio n. 20
0
def set_sensor_type(sensnum, senstype):
    trik_protocol.write_reg(sensnum, sidx, senstype)
Esempio n. 21
0
def set_motor_duty(motnum, pwmdut):
    trik_protocol.write_reg(motnum, mdut, pwmdut)
Esempio n. 22
0
def set_pwm_period(pwmnum, pwmper):
    trik_protocol.write_reg(pwmnum, pper, pwmper)
Esempio n. 23
0
def set_motor_time(motnum, mottime):
    trik_protocol.write_reg(motnum, mtmr, mottime)
Esempio n. 24
0
def set_pwm_duty(pwmnum, pwmdut):
    trik_protocol.write_reg(pwmnum, pdut, pwmdut)
Esempio n. 25
0
def reverse_motor(motnum):
    trik_protocol.write_reg(motnum, mctl, mot_enable + mot_back + mot_power)
Esempio n. 26
0
def start_pwm(pwmnum):
    trik_protocol.write_reg(pwmnum, pctl, pwm_enable)
Esempio n. 27
0
def stop_motor(motnum):
    trik_protocol.write_reg(motnum, mctl, mot_enable)
Esempio n. 28
0
def stop_pwm(pwmnum):
    trik_protocol.write_reg(pwmnum, pctl, pwm_disable)
Esempio n. 29
0
def timer_enable():
    trik_protocol.write_reg(timer1, atctl, at_en)
def init_spwm_5():
    trik_protocol.write_reg(0x33, 0x02, pwmper)
    trik_protocol.write_reg(0x33, 0x01, pwmdut)
    trik_protocol.write_reg(0x33, 0x00, 0x8000)