فهرست منبع

basic stepper machine

eLandon 6 سال پیش
والد
کامیت
99c0c876ab

+ 18 - 8
HTequi-firmware/src/Atm_lien/Atm_stepper.cpp

@@ -15,9 +15,11 @@ Atm_stepper& Atm_stepper::begin(int stepPin, int dirPin) {
   };
   // clang-format on
   Machine::begin( state_table, ELSE );
-  _motor = new AccelStepper(1, stepPin, dirPin);
-  _motor->setMaxSpeed(2000);
-  _motor->setAcceleration(2000);
+  AccelStepper _motor (1, stepPin, dirPin);
+  // Stepper _motor(stepPin, dirPin );
+  // StepControl _controller;
+  // _motor.setMaxSpeed(20000);
+  // _motor.setAcceleration(1000);
   //_controller = new StepControl;
   pinMode(0, OUTPUT);
   digitalWrite(0, HIGH);
@@ -33,7 +35,8 @@ int Atm_stepper::event( int id ) {
     case EVT_IDLE_TIMER:
       return 0;
     case EVT_ON_TARGET:
-      return 0;
+
+      return _motor.distanceToGo()== 0 ;
   }
   return 0;
 }
@@ -55,11 +58,12 @@ void Atm_stepper::action( int id ) {
       return;
     case ENT_RUNNING:
       digitalWrite(0, HIGH);
+      // _controller.moveAsync(*_motor);
       return;
     case LP_RUNNING:
-      _motor->run();
-      // _controller.moveAsync(_motor);
-      Serial.println(_motor->distanceToGo());
+      _motor.run();
+
+     Serial.println(_motor.currentPosition());
       return;
     case ENT_STOPPING:
       return;
@@ -94,7 +98,13 @@ int Atm_stepper::state( void ) {
  */
 
 Atm_stepper& Atm_stepper::gotoStep(long int targetStep ) {
-  _motor->moveTo(targetStep);
+  // _motor->setTargetRel(targetStep);
+
+  _motor.move(targetStep);
+  _motor.run();
+  Serial.println(_motor.distanceToGo());
+  _motor.setMaxSpeed(5000);
+  _motor.setAcceleration(6000);
   trigger( EVT_GOTO );
   return *this;
 }

+ 2 - 2
HTequi-firmware/src/Atm_lien/Atm_stepper.h

@@ -18,8 +18,8 @@ class Atm_stepper: public Machine {
   Atm_stepper& gotoStep( long int targetStep );
 
  private:
-  AccelStepper *_motor;
-  // Stepper _motor;       // STEP pin: 2, DIR pin: 3
+  AccelStepper _motor;
+  // Stepper *_motor;       // STEP pin: 2, DIR pin: 3
   // StepControl _controller;
   enum { ENT_IDLE, ENT_READY, ENT_RUNNING, LP_RUNNING, ENT_STOPPING, EXT_STOPPING }; // ACTIONS
   enum { ON_ONCHANGE, CONN_MAX }; // CONNECTORS

+ 13 - 10
HTequi-firmware/src/blobcnc_low/main.cpp

@@ -145,10 +145,13 @@ void setup() {
   stepper.trace( Serial );
   Serial.println("Started");
   stepper.begin(2,1);
-  //stepper.trigger(stepper.EVT_GOTO);
+  stepper.cycle(1000);
+  Serial.println("Started");
   stepper.gotoStep(16000);
-  pinMode(00, OUTPUT);
-  digitalWrite(0, HIGH);
+  Serial.println("Started");
+  // stepper.trigger(stepper.EVT_GOTO);
+  // pinMode(00, OUTPUT);
+  // digitalWrite(0, HIGH);
 }
 
 void loop() {
@@ -166,13 +169,13 @@ void loop() {
       led.onOSC(msgIn);
  }
 
- OSCMessage msg("/analog/0");
- msg.add((int32_t)analogRead(0));
-
- Udp.beginPacket(ipMulti, portMulti);
-   msg.send(Udp); // send the bytes to the SLIP stream
- Udp.endPacket(); // mark the end of the OSC Packet
- msg.empty(); // free space occupied by message
+ // OSCMessage msg("/analog/0");
+ // msg.add((int32_t)analogRead(0));
+ //
+ // Udp.beginPacket(ipMulti, portMulti);
+ //   msg.send(Udp); // send the bytes to the SLIP stream
+ // Udp.endPacket(); // mark the end of the OSC Packet
+ // msg.empty(); // free space occupied by message
 
  // led.cycle();