Hello all-
I would like to mimic pendular motion with a stepper motor.
I have wired up and am successfully controlling a NEMA17 bipolar stepper, suncor SC42STH38-1304AF
http://www.suncormotor.com/Products/1468325853.html
with this motor shield: Motor Shield V1.0 | Seeed Studio Wiki using the rudimentary code contained in aforementioned wiki.
SEEED Studio Stepper Motor Control - one revolution
Adapts the Stepper example for use with the SEEED STUDIO motor shield.
This program drives a unipolar or bipolar stepper motor
by using the included Stepper library of the Arduino.
The motor is attached to the Seeed Studio motor shield and an Arduino.
The digital pins 8,11,12,13 drive the L298N and are used when creating the stepper object
Digital pins 9 and 10 must be high to enable the chip.
The motor should revolves one revolution in one direction, then
one revolution in the other direction.
Created 11 Mar. 2007
Modified 30 Nov. 2009
by Tom Igoe
Modified 4 July 2012
By R. Dumouchelle
*/
#include <Stepper.h>
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
// for your motor
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8,11,12,13);
void setup() {
// set the speed at 60 rpm:
myStepper.setSpeed(60);
// initialize the serial port:
Serial.begin(9600);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
digitalWrite(9,HIGH);
digitalWrite(10,HIGH);
}
void loop() {
// step one revolution in one direction:
Serial.println("clockwise");
myStepper.step(stepsPerRevolution);
delay(500);
//step one revolution in the other direction:
Serial.println("counterclockwise");
myStepper.step(-stepsPerRevolution);
delay(500);
}
I would like to use the stepper motor to control the motion of a swinging pendulum about 4' (125cm) long with a weight of around 5lb.
I have no problem with the mechanical aspects of the project (I run a fabrication shop).
My current approach is to measure the period and angle of the swing, and then use that as a reference for controlling the motion- the stepper's motion will mimic the systems natural tendency within some reasonable degree of accuracy.
Here is some code that contains an angular momentum algorithm. Is there a way to use this algorithm or something like it to inform the stepper's motion?
Pendulum p;
void setup() {
size(640,360);
We make a new Pendulum object with an origin location and arm length.
p = new Pendulum(new PVector(width/2,10),125);
}
void draw() {
background(255);
p.go();
}
class Pendulum {
Many, many variables to keep track of the Pendulum’s various properties
PVector location; // Location of bob
PVector origin; // Location of arm origin
float r; // Length of arm
float angle; // Pendulum arm angle
float aVelocity; // Angle velocity
float aAcceleration; // Angle acceleration
float damping; // Arbitrary damping amount
Pendulum(PVector origin_, float r_) {
origin = origin_.get();
location = new PVector();
r = r_;
angle = PI/4;
aVelocity = 0.0;
aAcceleration = 0.0;
An arbitrary damping so that the Pendulum slows over time
damping = 0.995;
}
void go() {
update();
display();
}
void update() {
float gravity = 0.4;
Formula we worked out for angular acceleration
aAcceleration = (-1 * gravity / r) * sin(angle);
Standard angular motion algorithm
aVelocity += aAcceleration;
angle += aVelocity;
Apply some damping.
aVelocity *= damping;
}
void display() {
Where is the bob relative to the origin? Polar to Cartesian coordinates will tell us!
location.set(r*sin(angle),r*cos(angle),0);
location.add(origin);
stroke(0);
The arm
line(origin.x,origin.y,location.x,location.y);
fill(175);
The bob
ellipse(location.x,location.y,16,16);
}
}
So, we need to control the rate of change of velocity with a variable...
something like this?
aAcceleration = (-1 * gravity / r) * sin(angle);
aVelocity += aAcceleration;
angle += aVelocity;
There then need to be two variables associated with velocity: V and △V (acceleration).
als, these:
PVector location; // Location of bob
PVector origin; // Location of arm origin
float r; // Length of arm
float angle; // Pendulum arm angle
float aVelocity; // Angle velocity
thats all I got.
I can't think in c++ abstractly or succinctly enough to make this work. But its possible and easy, right?
Please give me a pointer,
-R