arduino = serial.Serial( port='COM7', baudrate=256000, #parity=serial.None, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS) #arduino.open() motor = motor_control.get_motor_instance() motor_control.set_forward() print("Serial opened") motor_running_state = True motor_control.rev_up(30, speed, 0.1) for k in range(25): i = arduino.readline() i = arduino.readline() time.sleep(1) arduino.flush() i = arduino.readline() print("start loop") for k in range(1000): motor_control.set_speed(speed) arduino.reset_input_buffer() #first line may be gimped
import serial import time import motor_control #speed = 100 max_speed = 110 #120 & 110 & 100 had no problems with simple testing in forward and reverse motor_string = 'M1R' lowest_speed = 27 * 2 #best value = 27 """ message = 'M1F'+chr(speed)+'\r\n' print("string out: " + message + " speed is: " + str(speed)) motor.write(message.encode()) time.sleep(3) """ """ for count in range(10): motor_control.rev_up(lowest_speed, max_speed, 0.1) motor_control.rev_down(max_speed, lowest_speed, 0.1) print("Count is: " + str(count + 1)) for num in range(20): print(count + 1) """ motor_control.rev_up(lowest_speed, max_speed, 0.1) for i in range(10): motor_control.set_speed(max_speed) time.sleep(2) motor_control.stop()
import motor_control, time import numpy as np motor_control.rev_up(40, 80, 0.02) recorded_rpm = [] for i in range(500): recorded_rpm.append(motor_control.get_rpm()) time.sleep(1) print("Mean: " + str(np.mean(recorded_rpm))) print("Stddev: " + str(np.std(recorded_rpm))) print("Min: " + str(np.min(recorded_rpm))) print("Max: " + str(np.max(recorded_rpm))) motor_control.stop()