Show Posts
|
|
Pages: [1]
|
|
2
|
Using Arduino / Motors, Mechanics, and Power / Re: Motor controller
|
on: December 10, 2012, 07:17:57 am
|
|
I think you need a stepper motor library to handle the stepper's speed. Recently I am working on a project that handle four stepper motor. The AccelStepper library works just perfectly. You can control the motor through it not only to set the specified speed, but also the "acceleration" and "deacceleration". But the hardware side I can not much to say.
|
|
|
|
|
3
|
Using Arduino / Motors, Mechanics, and Power / Some really wierd things happened
|
on: December 08, 2012, 04:31:46 pm
|
|
Cause I wanna the Balance to balance as a definite proportion between four different things . So I've changed the motor controller from Adafruit Motor shield to four A4988 Stepper Driver from Pololu. And the result is pretty tricky.Till to three steppers, the Arduino code that written like the above works still well beside the low speed range. But if I defined four "AccelStepper" in the code.they seemed like they just block them from each another,and the motors stay still. I searched Youtube the installation from other Guys. There is mainly two types of solution. One is use something like "A Big Chip, which have so many Pins" and the other changed the Arduino by a Board named ChipKit, which have a 80MHz work frequency.
I thought the Problem over, and decided to try ChipKit. But I'm not sure the circuit wired up right. So please check out the Picture. Thanks!!
|
|
|
|
|
4
|
Using Arduino / Motors, Mechanics, and Power / Re: 2 Stepper Moving Simultaneiously.
|
on: December 07, 2012, 08:44:59 am
|
void loop() { unsigned long currentTime = millis();
// If it's time to step Motor 1... if (motor1Stepping && (currentTime - lastMotor1Time > motor1Interval)) stepMotor1();
// If it's time to step Motor 2... if (motor2Stepping && (currentTime - lastMotor2Time > motor2Interval)) stepMotor2();
// Do other stuff like figuring out which way and how fast to step the motors. }
Thanks!! After reading your codes and some sample, Last night I've really getting startted. Hier is the little sample to share. // AFMotor_MultiStepper.pde // -*- mode: C++ -*- // // Control both Stepper motors at the same time with different speeds // and accelerations. // Requires the AFMotor library (https://github.com/adafruit/Adafruit-Motor-Shield-library) #include <AccelStepper.h> #include <AFMotor.h>
// two stepper motors one on each port AF_Stepper motor1(200, 1); AF_Stepper motor2(96, 2);
// you can change these to DOUBLE or INTERLEAVE or MICROSTEP! // wrappers for the first motor! void forwardstep1() { motor1.onestep(FORWARD, SINGLE); } void backwardstep1() { motor1.onestep(BACKWARD, SINGLE); } // wrappers for the second motor! void forwardstep2() { motor2.onestep(FORWARD, SINGLE); } void backwardstep2() { motor2.onestep(BACKWARD, SINGLE); } // Motor shield has two motor ports, now we'll wrap them in an AccelStepper object AccelStepper stepper1(forwardstep1, backwardstep1); AccelStepper stepper2(forwardstep2, backwardstep2); void setup() { stepper1.setMaxSpeed(300.0); stepper1.setAcceleration(100.0); stepper1.moveTo(240); stepper2.setMaxSpeed(300.0); stepper2.setAcceleration(100.0); stepper2.moveTo(240); } void loop() { // Change direction at the limits if (stepper1.distanceToGo() == 0) stepper1.moveTo(-stepper1.currentPosition()); if (stepper2.distanceToGo() == 0) stepper2.moveTo(-stepper2.currentPosition()); stepper1.run(); stepper2.run(); }
|
|
|
|
|
5
|
Using Arduino / Motors, Mechanics, and Power / 2 Stepper Moving Simultaneiously.
|
on: December 06, 2012, 09:28:39 am
|
Hello, Geeks! I am working on a projekt, that need control two Steppers with two Potis. The Model is something like a balance. Ja as the topic say, the two stepper should work simultaneiously. I look up so much much info. on the site.like the Kritzler( http://tinkerlog.com/2011/09/02/der-kritzler/), accelstepper( http://www.open.com.au/mikem/arduino/AccelStepper/), Interrup( http://www.uchobby.com/index.php/2007/11/24/arduino-interrupts/) Adafruit Motor shield( http://www.ladyada.net/make/mshield/use.html) Some of them really done a perfect deep research. But I can still not get the very idea how to control them. So, is anyone can share a tutorial about how to control two stepper simultaneously with accelstepp library(cause I am not a programmer, the C and C++ code is not that easy for me). Or just make a small sample here. BTW. must I use the Interrupt to control the two motor? gfast
|
|
|
|
|
7
|
Using Arduino / Networking, Protocols, and Devices / Re: Xbee communication Error
|
on: January 15, 2012, 03:21:43 pm
|
|
Thank you so much Pauls. Now my Robot works wirelessly really really sweet! ; )
But some part of the Serial communication I still can't understand. I mean, I just let arduino give a feedback to processing(just character "?" each loop), in oder to tell processing that the process in Arduino is over.if I use a cable, the "arduinoport.read();" can get the number "63",but if I use one pair Xbee. It can be "63","13","10". At the same time, If I turn off the Power of Arduino, Processing can still feed back these numbers, even if I've get off the Xbee from my MAC. What kind of reason can it be?
Thanks
|
|
|
|
|
10
|
Using Arduino / Networking, Protocols, and Devices / Re: Xbee communication Error
|
on: January 12, 2012, 10:24:24 am
|
Wow,for me is that really a great new solution! Pauls, thank you so much. As a program starter I still don't understand the meaning of " inData[index] = '\0'; ", Is that means make the "inData[index]" as the end of the Array,but the value is still the "inChar" or something? and you said I should speed up the Serial port. But I do care about the power consumption of different speed of the Serial port. Cause I just plan to let the Robot take "Time-lapse". So I have to do all you can to save the Batteries.By the way, is there any one can give me a input about the power consumption of the Serial port and the Xbee in different speed? Thank you so much!! 
|
|
|
|
|
11
|
Using Arduino / Networking, Protocols, and Devices / Xbee communication Error
|
on: January 12, 2012, 02:33:17 am
|
I just work on a project that use Processing control a small robot drived by Arduino Dumelianove with 2 Xbee. This robot have 4 steppers, 4LEDs and two relays. Every 5 Second will the Processing send a message "#1001001000", after the beginning '#' every 3 charactor means the info. for each stepper,'1' means direction of the stepper and the following 2 means the steps. The last charactor means the control of two relays. With cable works the robot pretty good. But if I try to use two xbee the Stepper moved weird.most time work each step right, but about each 10 Time will a Error step appear. sometimes moved more sometimes the relays didn't work and so on. I used paar "XBee 2mW Series 2.5 Wire Antenna" and a "XBee Explorer USB" from sparkfun to connect one xbee to my MAC. I think must be something wrong with the xbee part. //Here is the prototype of the Communication between MAC and robot, Processing part
import processing.serial.*; Serial arduinoPort;
long previousMillis = 0;
int i = 0;
void setup(){ arduinoPort = new Serial(this , Serial.list()[0], 9600); delay(2000); }
void draw(){ long currentMillis = millis(); //port.available() can direct store the value when possible //then the value of the port is once more empty // while (arduinoPort.available() > 0){ // int inByte = arduinoPort.read(); // println(inByte); if(currentMillis - previousMillis > 5000){ arduinoPort.write("#0101001001001"); previousMillis = currentMillis; print("Now is "); println(i); i++; } //} // arduinoPort.clear(); }
than Arduino part #define ST1 2 //ST1 means "Steppermotor 1's step number" #define DI1 3 //DI1 means "Steppermotor 1's step direction" #define ST2 4 #define DI2 5 #define ST3 7 #define DI3 8 #define ST4 12 #define DI4 13 int SL1 = A1; //SL1 means "Steppermoto 1's sleep mode" int SL2 = A2; int SL3 = A3; int SL4 = A4;
#define LED1 6 //LED1 is the control Pin of one of four LED that put on the Robot #define LED2 9 #define LED3 10 #define LED4 11
int FOCUS = A0; //the control Pin of the Focus function on the camera int SHUTTER = A5; //the control Pin of the Shutter on the camera
char buffer[14]; //store the Sequence that followed by "#" as the input from the Serial port byte inByte = 0; //detect if the input is the "#" int pointer = 0; //to store the number of the buffers' arrays
int motor1 = 0; //store the move amount for each motor from Serial int motor2 = 0; int motor3 = 0; int motor4 = 0;
///////////////////////////////////////////////////////////////
void setup(){ pinMode(ST1, OUTPUT); pinMode(DI1, OUTPUT); pinMode(ST2, OUTPUT); pinMode(DI2, OUTPUT); pinMode(ST3, OUTPUT); pinMode(DI3, OUTPUT); pinMode(ST4, OUTPUT); pinMode(DI4, OUTPUT); pinMode(SL1, OUTPUT); pinMode(SL2, OUTPUT); pinMode(SL3, OUTPUT); pinMode(SL4, OUTPUT); pinMode(LED1, OUTPUT); pinMode(LED2, OUTPUT); pinMode(LED3, OUTPUT); pinMode(LED4, OUTPUT); pinMode(SHUTTER, OUTPUT); pinMode(FOCUS, OUTPUT); Serial.begin(9600); //Serial.println("OK, all Pins' define are done"); digitalWrite(SL1, 0); digitalWrite(SL2, 0); digitalWrite(SL3, 0); digitalWrite(SL4, 0); digitalWrite(FOCUS,0); digitalWrite(SHUTTER,0); //this part let Smaker warm up for(int k=0; k<256; k+=5){ analogWrite(LED1, k); delay(30); } for(int k=0; k<256; k+=5){ analogWrite(LED2, k); delay(30); } for(int k=0; k<256; k+=5){ analogWrite(LED3, k); analogWrite(LED4, k); delay(30); } }
///////////////////////////////////////////////////////////////
void loop(){ inByte = Serial.read(); if(Serial.available() > 0){ if(inByte == '#'){ //store the info. from Serial //Structure is #0FF0FF0FF0FF, 0s are the direction of each motor, 0 = LOW //FFs are the amount of the steps that stepper should go while(pointer < 13){ buffer[pointer] = Serial.read(); pointer ++; } motor1 = hex2dec(buffer[2]) + hex2dec(buffer[1]) * 16; motor2 = hex2dec(buffer[5]) + hex2dec(buffer[4]) * 16; motor3 = hex2dec(buffer[8]) + hex2dec(buffer[7]) * 16; motor4 = hex2dec(buffer[11]) + hex2dec(buffer[10]) * 16; pointer = 0; //reset the pointer so can be reuse the buffer } }else if(Serial.available() == 0){ //when there is no input, set all value to zero motor1 = 0; motor2 = 0; motor3 = 0; motor4 = 0; buffer[12] = 0; //when there is no Serial input, take no foto } if(buffer[0] == '0'){ //this part can set the direction of each motor digitalWrite(DI1, LOW); }else if(buffer[0] == '1'){ digitalWrite(DI1, HIGH); } if(buffer[3] == '0'){ digitalWrite(DI2, LOW); }else if(buffer[3] == '1'){ digitalWrite(DI2, HIGH); } if(buffer[6] == '0'){ digitalWrite(DI3, LOW); }else if(buffer[6] == '1'){ digitalWrite(DI3, HIGH); } if(buffer[9] == '0'){ digitalWrite(DI4, LOW); }else if(buffer[9] == '1'){ digitalWrite(DI4, HIGH); } //take the Photo first than make the movement if(buffer[12] == '1'){ //cause the structur is not very stable, //so wait a moment till the vibration stop delay(2000); foto(); //write something to tell processing give the next info Data delay(500); //time for the camera's exposure }else if(buffer[12] == '3'){ delay(2000); foto(); delay(500); foto(); delay(500); foto(); delay(500); } go(1, motor1, 1); //this part can give each motor steps number go(2, motor2, 1); go(3, motor3, 1); go(4, motor4, 1); delay(50); //balance the Arduino's speed to save battery Serial.print('?'); led(); //blink the LED on board }
/////////////////////////////////////////////////////////////// int hex2dec(byte c){ if(c>= '0' && c<= '9'){ return c - '0'; }else if(c >= 'A' && c <= 'F'){ return c - 'A' + 10; } }
///////////////////////////////////////////////////////////////
void go(int stNumber,int stAmout,int stSpeed){ int selected = 0; //to assign the StPin's number int i = 0; //to Set the counter variable /* Serial.print("Stepper "); Serial.print(stNumber); Serial.print(" is moving: "); Serial.print(stAmout); Serial.println(" steps"); //show all movements of four motors, println = print+return+newline meaning */ switch(stNumber){ case 1: //digitalWrite(DI1,stDir); //set the direction of the rotation of the Stepper selected = ST1; //assign the ST1 as aimed operate object digitalWrite(SL1,HIGH); //awake the aimed Stepper while(i < stAmout){ //in full step situation, stAmout means how many rotate digitalWrite(selected,LOW); digitalWrite(selected,HIGH); delayMicroseconds(1600/stSpeed); i++; } digitalWrite(SL1,LOW); //let the stepper go to sleep break; case 2: //digitalWrite(DI2,stDir); selected = ST2; digitalWrite(SL2,HIGH); while(i < stAmout){ digitalWrite(selected,LOW); digitalWrite(selected,HIGH); delayMicroseconds(1600/stSpeed); i++; } digitalWrite(SL2,LOW); break; case 3: //digitalWrite(DI3,stDir); selected = ST3; digitalWrite(SL3,HIGH); while(i < stAmout){ digitalWrite(selected,LOW); digitalWrite(selected,HIGH); delayMicroseconds(1600/stSpeed); i++; } digitalWrite(SL3,LOW); break; case 4: //digitalWrite(DI4,stDir); selected = ST4; digitalWrite(SL4,HIGH); while(i < stAmout){ digitalWrite(selected,LOW); digitalWrite(selected,HIGH); delayMicroseconds(1600/stSpeed); i++; } digitalWrite(SL4,LOW); break; } }
///////////////////////////////////////////////////////////////
void foto(){ digitalWrite(LED1,LOW); digitalWrite(LED2,LOW); digitalWrite(LED3,LOW); digitalWrite(LED4,LOW); digitalWrite(FOCUS, HIGH); delay(50); digitalWrite(SHUTTER,HIGH); delay(500); digitalWrite(FOCUS, LOW); digitalWrite(SHUTTER,LOW); }
boolean ledState = LOW; long previousMillis = 0; long interval = 900;
void led(){ unsigned long currentMillis = millis(); if(currentMillis - previousMillis > interval){ previousMillis = currentMillis; if(ledState == LOW) ledState = HIGH; else ledState = LOW; //ledState = LOW ? HIGH : LOW; digitalWrite(LED1, ledState); digitalWrite(LED2, ledState); digitalWrite(LED3, ledState); digitalWrite(LED4, ledState); } }
|
|
|
|
|