diff --git a/movearm/game_stencil.py b/movearm/game_stencil.py new file mode 100644 index 0000000..3c7a671 --- /dev/null +++ b/movearm/game_stencil.py @@ -0,0 +1,78 @@ +import threading +import time + + + + + +startTime = time.time() +nowTime = 0; + +currentMotor = 0 +motorcfg = [0] * 10 +motorcfg[1] = {"positive":1, "negative":2, 'speedslot':2} +motorcfg[2] = {"positive":3, "negative":4, 'speedslot':4} +motorcfg[3] = {"positive":5, "negative":6, 'speedslot':6} + +friction = 0.99 +movement_time = 5 +max_movement_time = 10 +min_speed = 1 +max_speed = 50 + +speed = 0 +stopTime = 0 +isRunning = False + +def adjustSpeed(motor, adjustment): + global nowTime, stopTime, currentMotor, speed, motorcfg, movement_time, max_speed, max_movement_time + + if currentMotor==motor: + speed += adjustment * (abs(speed)/max_speed) + stopTime += movement_time/2 * max_movement_time/(stopTime - nowTime) + else: + currentMotor = motor + speed = adjustment + stopTime = nowTime + movement_time + if(speed>0): + print("JOG command {}".format(motorcfg[currentMotor]['positive'])) + else: + print("JOG command {}".format(motorcfg[currentMotor]['negative'])) + + +def stopMotorFunctions(): + global currentMotor, speed + currentMotor = 0 + speed = 0 + print ("JOB command stop all motors") + +def updateLoop(): + global nowTime, stopTime, currentMotor, speed, friction, min_speed, motorcfg + nowTime = (time.time() - startTime) + threading.Timer(0.2, updateLoop).start() + + if currentMotor != 0: + if nowTime > stopTime: + stopMotorFunctions() + return + else: + speed *= friction + if abs(speed) < min_speed: + stopMotorFunctions() + return + print("JOG parameter {} to {}".format( motorcfg[currentMotor]['speedslot'], abs(speed)) ) + + +def rt(): + adjustSpeed(1, 5) + +def lt(): + adjustSpeed(1, -5) + +def up(): + adjustSpeed(2, 5) + +def dn(): + adjustSpeed(2, -5) + +updateLoop(); \ No newline at end of file diff --git a/scale/HX711-master.zip b/scale/HX711-master.zip new file mode 100644 index 0000000..75146af Binary files /dev/null and b/scale/HX711-master.zip differ diff --git a/scale/scale.ino b/scale/scale.ino new file mode 100644 index 0000000..a9b171a --- /dev/null +++ b/scale/scale.ino @@ -0,0 +1,59 @@ +#include "HX711.h" + +HX711 scale; + +void setup() { + Serial.begin(38400); + Serial.println("HX711 Demo"); + + Serial.println("Initializing the scale"); + // parameter "gain" is ommited; the default value 128 is used by the library + // HX711.DOUT - pin #A1 + // HX711.PD_SCK - pin #A0 + scale.begin(2, 3); + + Serial.println("Before setting up the scale:"); + Serial.print("read: \t\t"); + Serial.println(scale.read()); // print a raw reading from the ADC + + Serial.print("read average: \t\t"); + Serial.println(scale.read_average(20)); // print the average of 20 readings from the ADC + + Serial.print("get value: \t\t"); + Serial.println(scale.get_value(5)); // print the average of 5 readings from the ADC minus the tare weight (not set yet) + + Serial.print("get units: \t\t"); + Serial.println(scale.get_units(5), 1); // print the average of 5 readings from the ADC minus tare weight (not set) divided + // by the SCALE parameter (not set yet) + + scale.set_scale(2280.f); // this value is obtained by calibrating the scale with known weights; see the README for details + scale.tare(); // reset the scale to 0 + + Serial.println("After setting up the scale:"); + + Serial.print("read: \t\t"); + Serial.println(scale.read()); // print a raw reading from the ADC + + Serial.print("read average: \t\t"); + Serial.println(scale.read_average(20)); // print the average of 20 readings from the ADC + + Serial.print("get value: \t\t"); + Serial.println(scale.get_value(5)); // print the average of 5 readings from the ADC minus the tare weight, set with tare() + + Serial.print("get units: \t\t"); + Serial.println(scale.get_units(5), 1); // print the average of 5 readings from the ADC minus tare weight, divided + // by the SCALE parameter set with set_scale + + Serial.println("Readings:"); +} + +void loop() { + Serial.print("one reading:\t"); + Serial.print(scale.get_units(), 1); + Serial.print("\t| average:\t"); + Serial.println(scale.get_units(10), 1); + + scale.power_down(); // put the ADC in sleep mode + delay(500); + scale.power_up(); +}