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)
def enable_i2c(i2cnum): trik_protocol.write_reg(i2cnum, ictl, i2c_enable + i2c_pull)
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
def brake_motor(motnum): trik_protocol.write_reg(motnum, mctl, mot_enable + mot_brake)
def start_motor(motnum): trik_protocol.write_reg(motnum, mctl, mot_enable + mot_power)
def set_motor_angle(motnum, motangle): trik_protocol.write_reg(motnum, mang, motangle)
def set_motor_period(motnum, pwmper): trik_protocol.write_reg(motnum, mper, pwmper)
def rotate_motor_angle(motnum): trik_protocol.write_reg( motnum, mctl, mot_enable + mot_power + mot_auto + mot_angle + mot_brake)
__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)
def read_i2c_sensor(i2cnum): trik_protocol.write_reg(i2cnum, ictl, i2c_enable + i2c_pull + i2c_sens) return trik_protocol.read_reg(i2cnum, ival)
def set_i2c_sensor_parameter(i2cnum, i2csenspar): trik_protocol.write_reg(i2cnum, ipar, i2csenspar)
def set_i2c_sensor_type(i2cnum, i2csenstype): trik_protocol.write_reg(i2cnum, iidx, i2csenstype)
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)
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)
def disable_i2c(i2cnum): trik_protocol.write_reg(i2cnum, ictl, i2c_disable)
def timer_disable(): trik_protocol.write_reg(timer1, atctl, 0x0000)
def set_timer_period(tmper): trik_protocol.write_reg(timer1, atper, tmper)
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)
def reverse_motor_time(motnum): trik_protocol.write_reg( motnum, mctl, mot_enable + mot_power + mot_auto + mot_back + mot_brake)
def set_sensor_type(sensnum, senstype): trik_protocol.write_reg(sensnum, sidx, senstype)
def set_motor_duty(motnum, pwmdut): trik_protocol.write_reg(motnum, mdut, pwmdut)
def set_pwm_period(pwmnum, pwmper): trik_protocol.write_reg(pwmnum, pper, pwmper)
def set_motor_time(motnum, mottime): trik_protocol.write_reg(motnum, mtmr, mottime)
def set_pwm_duty(pwmnum, pwmdut): trik_protocol.write_reg(pwmnum, pdut, pwmdut)
def reverse_motor(motnum): trik_protocol.write_reg(motnum, mctl, mot_enable + mot_back + mot_power)
def start_pwm(pwmnum): trik_protocol.write_reg(pwmnum, pctl, pwm_enable)
def stop_motor(motnum): trik_protocol.write_reg(motnum, mctl, mot_enable)
def stop_pwm(pwmnum): trik_protocol.write_reg(pwmnum, pctl, pwm_disable)
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)