rwaldron / johnny-five

JavaScript Robotics and IoT programming framework, developed at Bocoup.
http://johnny-five.io
Other
13.26k stars 1.76k forks source link

Proposed addition to stepper #1218

Open dtex opened 8 years ago

dtex commented 8 years ago

I'm working on a project that requires getting down into stepper and I have a proposed addition. I want to be able to control the enable pin of a motor controller to shut off a stepper so it's not consuming power when it is not needed (and getting super hot).

I could do this independently of the stepper class by controlling an independent digital pin, or I could integrate it as a parameter on stepper. For example:

Four-Wire

five.Stepper({
  type: five.Stepper.TYPE.FOUR_WIRE
  stepsPerRev: number,
  pins: {
    motor1: number,
    motor2: number,
    motor3: number,
    motor4: number,
    enable: number
  }
});

// or

five.Stepper({
  type: five.Stepper.TYPE.FOUR_WIRE
  stepsPerRev: number,
  pins: [ motor1, motor2, motor3, motor4, enable ]
});

or Two Wire

five.Stepper({
  type: five.Stepper.TYPE.TWO_WIRE
  stepsPerRev: number,
  pins: {
    motor1: number,
    motor2: number,
    enable: number
  }
 });

// or 

five.Stepper({
  type: five.Stepper.TYPE.TWO_WIRE
  stepsPerRev: number,
  pins: [ motor1, motor2, enable ]
}); 

Alternately enable could be a separate param:

five.Stepper({
  type: five.Stepper.TYPE.TWO_WIRE
  stepsPerRev: number,
  pins: {
    motor1: number,
    motor2: number
  },
  enable: number
 });
joepuzzo commented 2 years ago

multi does NOT work but mine does

joepuzzo commented 2 years ago

in other words calling mine([1000, 2000]) works but calling multi() does not

joepuzzo commented 2 years ago

Also while I have your attention @dtex do you know who I can contact to get this merged ? https://github.com/firmata/firmata.js/pull/261 . I cant seem to get in touch with anyone that works on firmata js

dtex commented 2 years ago

I think @rwaldron is the only one able to merge PRs on that repo.

joepuzzo commented 2 years ago

Ok thanks will try to get in touch with him. Also for anyone that attempts to use the methods described above with accelStepper and Johnny five with the latest stepper drivers make sure you check the pulse width settings inside of AccelStepper.cpp read the info about your stepper driver from its manual ( it should say minimum pulse width ). I needed to update mine to be 8.5. If you are using an arduino uno it defaults it to 5. For teensy boards it does not so you may be scratching your head for hours trying to figure out why your motors are not moving and its as simple as changing the pulse width.

joepuzzo commented 2 years ago

Also I would like to add for anyone using a teensy4.1 board you need to add the following code to the Boards.h in the firmatas src/utility directory

// Teensy 4.0 & 4.1
#elif defined(__IMXRT1062__)
#define TOTAL_ANALOG_PINS       NUM_ANALOG_INPUTS
#define TOTAL_PINS              NUM_DIGITAL_PINS
#define VERSION_BLINK_PIN       13
#define PIN_SERIAL1_RX          0
#define PIN_SERIAL1_TX          1
#define PIN_SERIAL2_RX          7
#define PIN_SERIAL2_TX          8
#define PIN_SERIAL3_RX          15
#define PIN_SERIAL3_TX          14
#define PIN_SERIAL4_RX          16
#define PIN_SERIAL4_TX          17
#define PIN_SERIAL5_RX          21
#define PIN_SERIAL5_TX          20
#define PIN_SERIAL6_RX          25
#define PIN_SERIAL6_TX          24
#define PIN_SERIAL7_RX          28
#define PIN_SERIAL7_TX          29
#define IS_PIN_DIGITAL(p)       ((p) >= 0 && (p) < NUM_DIGITAL_PINS)
#ifdef ARDUINO_TEENSY40
  #define IS_PIN_ANALOG(p)        ((p) >= 14 && (p) <= 27)
  #define PIN_TO_ANALOG(p)        ((p) - 14)
#endif
#ifdef ARDUINO_TEENSY41
  #define IS_PIN_ANALOG(p)        (((p) >= 14 && (p) <= 27) || ((p) >= 38 && (p) <= 41))
  #define PIN_TO_ANALOG(p)        (((p) <= 27) ? (p) - 14 : (p) - 24)
#endif
#define IS_PIN_PWM(p)           digitalPinHasPWM(p)
#define IS_PIN_SERVO(p)         ((p) >= 0 && (p) < MAX_SERVOS)
#define IS_PIN_I2C(p)           ((p) == PIN_WIRE_SDA || (p) == PIN_WIRE_SCL)
#define IS_PIN_SERIAL(p)        (((p) >= 0 && (p) <= 1) || ((p) >= 7 && (p) <= 8) || ((p) >= 14 && (p) <= 17) || ((p) >= 20 && (p) <= 21) || ((p) >= 24 && (p) <= 25) || ((p) >= 28 && (p) <= 29))
#define PIN_TO_DIGITAL(p)       (p)
#define PIN_TO_PWM(p)           (p)
#define PIN_TO_SERVO(p)         (p)