Exemple #1
0
  def ScanForHW(self):
    global dev_trainer, dev_ant, simulatetrainer
    #get ant stick
    if debug:print "get ant stick"
    if not dev_ant:
      dev_ant, msg = ant.get_ant(debug)
      if not dev_ant:
        self.ANTVariable.set(u"no ANT dongle found")
        return
    self.ANTVariable.set(u"ANT dongle found")


    self.PowerFactorVariable.set(powerfactor)
    if debug:print "get trainer"
    #find trainer model for Windows and Linux
    if not dev_trainer:
      #find trainer
      if simulatetrainer:
        self.trainerVariable.set(u"Simulated Trainer")
      else:
        dev_trainer = trainer.get_trainer()
        if not dev_trainer:
          self.trainerVariable.set("Trainer not detected")
          return
        else:
          self.trainerVariable.set("Trainer detected")
          trainer.initialise_trainer(dev_trainer)#initialise trainer
          
    self.StartAPPbutton.config(state="normal")
Exemple #2
0
    def ScanForHW(self):
        global dev_trainer, dev_ant, simulatetrainer
        # get ant stick
        if debug:
            print("get ant stick")
        if not dev_ant:
            dev_ant, msg = ant.get_ant(debug)
            if not dev_ant:
                if not headless:
                    self.ANTVariable.set(msg)
                return False
        if not headless:
            self.ANTVariable.set(msg)

        if not headless:
            self.PowerFactorVariable.set(powerfactor)
        if debug:
            print("get trainer")
        # find trainer model for Windows and Linux
        if not dev_trainer:
            # find trainer
            if simulatetrainer:
                if not headless:
                    self.trainerVariable.set(u"Simulated Trainer")
                else:
                    print("Simulated Trainer")
            else:
                dev_trainer = trainer.get_trainer()
                if not dev_trainer:
                    if not headless:
                        self.trainerVariable.set("Trainer not detected")
                    else:
                        print("Trainer not detected")
                    return False
                else:
                    if not headless:
                        self.trainerVariable.set("Trainer detected")
                    else:
                        print("Trainer detected")
                    trainer.initialise_trainer(
                        dev_trainer)  # initialise trainer

        if not headless:
            self.StartAPPbutton.config(state="normal")
            if not simulatetrainer:
                self.RunoffButton.config(state="normal")
            self.FindHWbutton.config(state="disabled")

        return True
Exemple #3
0
        def run():
            global dev_trainer, dev_ant
            power = 0
            resistance_level = 0
            save_data = []

            if not dev_trainer:  # if trainer not already captured
                dev_trainer = trainer.get_trainer()
                if not dev_trainer:
                    self.TrainerStatusVariable.set("Trainer not detected")
                    return
                else:
                    self.TrainerStatusVariable.set("Trainer detected")
                    trainer.initialise_trainer(dev_trainer)  # initialise trainer

            # find ANT stick
            if not dev_ant:
                dev_ant, msg = ant.get_ant(False)
                if not dev_ant:
                    self.ANTStatusVariable.set(u"no ANT dongle found")
                    return False
            self.ANTStatusVariable.set(u"ANT dongle found")

            ant.antreset(dev_ant, False)  # reset dongle
            ant.calibrate(dev_ant, False)  # calibrate ANT+ dongle
            ant.powerdisplay(dev_ant, False)  # calibrate as power display

            iterations = 0
            rest = 1
            stop_loop = False

            # ##################DATA LOOP FROM ANT STICK###################
            while self.StartText.get() == "Stop":
                # print iterations
                last_measured_time = time.time() * 1000
                if iterations == 240:  # inc resistance level every 60s (240 iterations)
                    iterations = 0
                    rest = 1  # go into rest mode
                    resistance_level += 1
                    if resistance_level == 14:
                        stop_loop = True
                if stop_loop:
                    self.StartText.set(u"Start")
                    self.InstructionsVariable.set("Test finished. Please exit")
                    break
                if rest > 0:
                    rest += 1
                    self.InstructionsVariable.set(
                        "Rest for %s seconds at a slow spin in an easy gear"
                        % int(round((40 - rest) / 4))
                    )
                    if rest == 40:
                        rest = 0
                else:
                    iterations += 1
                    self.InstructionsVariable.set(
                        "Over next %s seconds gradually increase your power from easy to near maximum"
                        % int(round((240 - iterations) / 4))
                    )

                try:
                    read_val = ant.read_ant(dev_ant, False)
                    matching = [
                        s for s in read_val if "a4094e0010" in s
                    ]  # a4094e0010ecff00be4e000010 #10 power page be 4e accumulated power 00 00 iunstant power
                    if matching:
                        power = int(matching[0][22:24], 16) * 256 + int(
                            matching[0][20:22], 16
                        )
                    # receive data from trainer
                    speed, pedecho, heart_rate, calc_power, cadence = trainer.receive(
                        dev_trainer
                    )  # get data from device
                    if speed == "Not found":
                        self.TrainerStatusVariable.set("Check trainer is powered on")
                        speed = 0
                    # send data to trainer
                    trainer.send(dev_trainer, resistance_level, pedecho)

                    self.PowerVariable.set(power)
                    self.SpeedVariable.set(speed)
                    self.ResistanceVariable.set(resistance_level)

                    if rest == 0 and speed > 0:  # in calibration mode and moving
                        save_data.append([resistance_level, speed, power])

                except usb.core.USBError:  # nothing from stick
                    pass

                time_to_process_loop = time.time() * 1000 - last_measured_time
                sleep_time = 0.25 - (time_to_process_loop) / 1000
                if sleep_time < 0:
                    sleep_time = 0
                time.sleep(sleep_time)
            # ##################END DATA LOOP FROM ANT STICK###############
            # ant.send(["a4 01 4a 00 ef 00 00"],dev_ant, False)#reset ANT+ dongle
            with open("calibration.pickle", "wb") as handle:
                pickle.dump(save_data, handle, protocol=pickle.HIGHEST_PROTOCOL)

            msg = produce_power_curve_file(save_data)
            self.InstructionsVariable.set(msg)
Exemple #4
0
        def run():
            global dev_trainer
            self.RunoffButton.config(state="disabled")
            runoff_loop_running = True
            rolldown = False
            rolldown_time = 0
            speed = 0
            self.InstructionsVariable.set(
                """
  CALIBRATION TIPS:
  1. Tyre pressure 100psi (unloaded and cold) aim for 7.2s rolloff
  2. Warm up for 2 mins, then cycle 30kph-40kph for 30s
  3. Speed up to above 40kph then stop pedalling and freewheel
  4. Rolldown timer will start automatically when you hit 40kph, so stop pedalling quickly!
  """
            )

            if not dev_trainer:  # if trainer not already captured
                dev_trainer = trainer.get_trainer()
                if not dev_trainer:
                    self.TrainerStatusVariable.set("Trainer not detected")
                    self.RunoffButton.config(state="normal")
                    return
                else:
                    self.TrainerStatusVariable.set("Trainer detected")
                    trainer.initialise_trainer(dev_trainer)  # initialise trainer

            while runoff_loop_running:  # loop every 100ms
                last_measured_time = time.time() * 1000

                # receive data from trainer
                speed, pedecho, heart_rate, force_index, cadence = trainer.receive(
                    dev_trainer
                )  # get data from device
                self.SpeedVariable.set(speed)
                if speed == "Not found":
                    self.TrainerStatusVariable.set("Check trainer is powered on")

                # send data to trainer
                resistance_level = 6
                trainer.send(dev_trainer, resistance_level, pedecho)

                if speed > 40:  # speed above 40, start rolldown
                    self.InstructionsVariable.set(
                        "Rolldown timer started - STOP PEDALLING!"
                    )
                    rolldown = True

                if speed <= 40 and rolldown:  # rolldown timer starts when dips below 40
                    if rolldown_time == 0:
                        rolldown_time = time.time()  # set initial rolldown time
                    self.InstructionsVariable.set(
                        "Rolldown timer started - STOP PEDALLING! %s "
                        % (round((time.time() - rolldown_time), 1))
                    )

                if speed < 0.1 and rolldown:  # wheel stopped
                    runoff_loop_running = False  # break loop
                    self.InstructionsVariable.set(
                        "Rolldown time = %s seconds (aim 7s)"
                        % round((time.time() - rolldown_time), 1)
                    )

                time_to_process_loop = time.time() * 1000 - last_measured_time
                sleep_time = 0.1 - (time_to_process_loop) / 1000
                if sleep_time < 0:
                    sleep_time = 0
                time.sleep(sleep_time)

            self.CalibrateButton.config(state="normal")
            # if speed > 40 or rolldown == True:
            # if rolldown_time == 0:
            # rolldown_time = time.time()#set initial rolldown time
            # self.InstructionsVariable.set("Rolldown timer started - STOP PEDALLING! %s " % ( round((time.time() - rolldown_time),1) ) )
            # rolldown = True
            # if speed < 0.1:#wheel stopped
            # running = False#break loop
            # if time.time() - rolldown_time > 7.5 :
            # msg = "More pressure from trainer on tyre required"
            # elif time.time() - rolldown_time < 6.5 :
            # msg = "Less pressure from trainer on tyre required"
            # else:
            # self.CalibrateButton.config(state="normal")
            # msg = "Pressure on tyre from trainer correct"
            # self.InstructionsVariable.set("Rolldown time = %s seconds\n%s" % (round((time.time() - rolldown_time),1), msg))

            # time_to_process_loop = time.time() * 1000 - last_measured_time
            # sleep_time = 0.1 - (time_to_process_loop)/1000
            # if sleep_time < 0: sleep_time = 0
            # time.sleep(sleep_time)
            self.RunoffButton.config(state="normal")
Exemple #5
0

def nice_exit():
    print "\nBye!!!\n"
    sys.exit(0)


while True:
    try:
        dev = trainer.get_trainer()
        if not dev:
            print "Waiting for Tacx next 5s."
            time.sleep(5)
        else:
            print "Found initializing"
            trainer.initialise_trainer(dev)
            break
    except KeyboardInterrupt:
        nice_exit()
while True:
    try:
        trainer.send(dev, 3, 0)
        time.sleep(0.3)
        speed, pedecho, heart_rate, force_index, cadence = trainer.receive(dev)
        if speed is None:
            print "No output"
            break
        else:
            print "SPEED: " + str(speed) + "\tPECHO: " + str(
                pedecho) + "\tHR: " + str(heart_rate) + "\tFORCE: " + str(
                    force_index) + "\tCADENCE: " + str(cadence)