DC motor closed-loop control software

By misan

434
37
Free
It's free to download

Comments

You need to be signed in before commenting.
misan
misan
almost 3 years
I have been using brushless motors with a built-in driver, so for that, I only need direction and speed digital signals.
Hllrsr
Hllrsr
almost 3 years
First, well done sir. Been following this for a while, and while the brushed version I've done is working very well, when I saw it was now brushless, I got VERY excited. BUT, as the arduino I/O pins are limited to 40 mA, what driver are you using for the BLDC ? Even the smallest motors I've found to be useable need 2-3 A. Or am I missing something? Cheers.
misan
misan
almost 5 years
Hi @keyvin_23, Ten en cuenta que las expresiones tipo "PIN* & *" tienen que cambiar de unas placas a otras. El ESP8266 es mucho más rápido que el arduino y se puede emplear digitalRead o digitalWrite en vez de lo anterior, pero no dispone de PWM por hardware, lo que puede generar pequeños movimientos erráticos de cuando en cuando. El codificador de 5000ppr genera muchas interrupciones por segundo a elevadas revoluciones y eso puede ser un problema que limite la máxima velocidad de operación.
keyvin_23
keyvin_23
almost 5 years
Hola Misan, es probable que ya te hayan preguntado, pero mis disculpas soy nuevo en esto, tengo un codificador de alta resolución 5000ppr ( https://www.datasheets.com/details/2rmhf-5000-d-1-4-64-01-b-scancon-28277576 ) y me gustaría usarlo. El problema es que con Arduino Promini no he logrado sincronizarlo Para las pruebas utilicé una similar a la de tu proyecto y funciona. ¿Un ESP8266 de mayor capacidad aún no funcionará con mi codificador 5000ppr?
Making with Luke
Making with Luke
about 5 years
Hello Miguel. I am very new to this, so be lenient. How do you power the motor/arduino/hbridge. Are some powered seperately? how much power does it need? can it be powered through the ramps 3d printer board? Thank you, I will also post on your youtube to increase your chances of seeing it.
misan
misan
almost 6 years
Hi @naj_tan, This is a position control on one axis. Driving a car may require one position control for the driving wheel and a second control for the car speed (this latter may be done with a position control too). If you want your car to go straight and then turn you will need to change the reference for each one of the two control loops in a sequence that satisfies your needs (ie reaching a certain speed when going straight ahead and rotating where you need it to). No code changes are needed if both axis are position control loops.
naj tan
naj tan
almost 6 years
very nice work i ask if you can convert the code to drive a car straight ahead and rotating 90 deg angle
Khalid Khattak
Khalid Khattak
about 6 years
Thanks Miguel, You are inspiration to all of us. I would be hgappy if you can make Autotune wizard. Such a wonderful job you have done so far. Thanks
misan
misan
about 6 years
I like to try things. That includes commercial brushless servos and hybrid (stepper) servos. The reason is that you need to know where the inflection point is: like the bread, there are things that your cheaper way to the product is to buy a commercial unit (a few people I know still bake their own bread, but they are a minority). Tinkering is fun but only if there is an edge. You can see here some tests with dcservo and s-curve motion http://fightpc.blogspot.com/2018/04/testing-sinusoidal-s-curves.html
Khalid Khattak
Khalid Khattak
about 6 years
Thanks Miguel, I am working on independent project of embroidery controller where i think i shall be required a builtin function of S-Profile or Trapezoidal trajectory control. I love your programming skill. I will be happy if you keep continue this project. I saw you purchased servo motor with drivers and now dont use the Arduino based DC servo Control you have designed. Any reason?
misan
misan
about 6 years
@Khalid, If you use GRBL/Mach3/etc you do not need dcservo to have more features. S-curve on dcservo can perform a motion pattern by itself without the need of an additional motion controller. Not useful if you already have one.
misan
misan
about 6 years
A 192 CPR will cause 192*4=768 interrupts per revolution. You can meter a movement and check how long did it take and the initial and final location. The <difference in the encoder counts>/768 will tell you the number of revolutions. That divided by the elapsed time of the move will tell you the number of average RPS. Multiply that by 60 to get the RPM. Of course, that is an average value. Peak RPM is probably double than that. RPM depends on motor voltage, load, and motor Kv constant.
Khalid Khattak
Khalid Khattak
about 6 years
i wish you continue this project and introduce autoPIDtune wizard. Meanwhile you are working on Trapezoidal and Scurve. Can you please tell why we need as if we are using GRBL/MACH3/LINUXCNCetc they have builtin .
Khalid Khattak
Khalid Khattak
about 6 years
@jimf, i think its 31khz, my motor driver is cool but the motor becoming hot..now all ok after tuning of servo
Jimf
Jimf
about 6 years
When I did a project with the 7960 Driver, I noticed it also got hot. Found out the PWM frequency used was to high for the Driver. 25khz is the rated switching frequency for the chip. I lowered it and temps dropped. I don’t recall what timer PWM frequency used for Misan’s PID code. You might want to check.
Khalid Khattak
Khalid Khattak
about 6 years
Thanks , The graph appeared when i increased all delays to 1200. You are a genius man. i wish you continue this project and introduce SCURVE and autotune wizard
misan
misan
about 6 years
I was not concerned about braking but that may be needed for some use cases. You can enable a brake pin when error is below a given threshold.
Khalid Khattak
Khalid Khattak
about 6 years
Thanks, i shall try and comeback to you. Meanwhile i m using dc motor driver BTS7960 43A. when my motor jitter its getting hot. The motor enable pin has given externally 5VDC supply. is it ok that your code not apply breaking....
misan
misan
about 6 years
Hi, @Khalid There are several delays in Processing code. These values worked ok for me, but they may be too short for your use case, thus preventing the data to be gathered and printed. Try make them longer to see if it helps.
Khalid Khattak
Khalid Khattak
about 6 years
Hi Miguel, The motor is getting command from Arduino UNO as desired. However, I want to tune the motor further. When I open the PIDtunningTool and run the processing sketch. I get a screen with Red lines and my motor start running. The console shows Setpoint encoder and error value. However no curve shown on the screen. I am using quadrature encoder with 192PPR. please can you help me why the curve is not drawn ...
misan
misan
over 6 years
It is a position control, motor speed is only limited by the error magnitude and the proportional gain.
stewart13wolf
stewart13wolf
over 6 years
Hi Misan Please how to set the maximum motor speed in the firmware, because for me it a little bit slow to use. thank very much Best regards Stewart
misan
misan
over 6 years
The faster the board the more motors you can handle. El 18 mar. 2018 4:44, "YouMagine - Supercomputer" < supercomputer@youmagine.com> escribió:
misan
misan
over 6 years
The UNO can handle a single motor, maybe two if they are not very fast. But the e coder you mentiob seems a resolver. I have not coded for that though it can do the job too. El 18 mar. 2018 4:44, "YouMagine - Supercomputer" < supercomputer@youmagine.com> escribió:
Eugene Alfaro
Eugene Alfaro
over 6 years
ok so i have a KFB2.0, 1 L298N, 2 DC motors with encoder attached (ElePrint CP200 data sheet here: http://www.servotrade.it/documenti///CP200.PDF), Arduino Uno, Power Supply for 3D Printer, and wires to hook it all up. looking at it, it looks like i can only control only one of them with the uno? is that right? I have a Duo on the way (monday) would that work better to handle the inputs from encoders?
misan
misan
over 6 years
@Eugene Nothing available at the moment. Connection info is listed on the source code. It is usually four signals, two for the encoder and two for motor controller (sometimes three depending on the controller).
Eugene Alfaro
Eugene Alfaro
over 6 years
any chance of a fritz of the arduino pin wire up?
misan
misan
over 6 years
I have found a piece of Mega code for a particular setup but I guess you will easily find out how to adapt it to yours https://github.com/misan/dcservo/blob/master/cdservoMega_magneticEncoder_brushlessMotor.ino
misan
misan
over 6 years
I do not have a dcservo suitable for Mega 2560 at the moment but the changes are just minimal, but depend on which pins you want to connect the encoder pins.
Gennady Yakubovich
Gennady Yakubovich
over 6 years
Thanks for suggestion, Miguel. I am getting into Matlab as it provides lots of means to simulate and tune PID systems. Moreover Simulink has capabilities to "talk" to Arduino Mega compile and load models and collect data. Here is my question - do you have, by chance, your servomotor implementation ported to Mega 2560 ? Thanks a lot
misan
misan
over 6 years
Hi Gennady, I did use a program written in Processing language to help me tune the PID (but tunning was still a manual process). I attempted to create an auto-tune but failed. Most likely it can be done using Using Ziegler-Nichols should be one possible choice you may want to explore https://www.youtube.com/watch?v=nvAQHSe-Ax4
Gennady Yakubovich
Gennady Yakubovich
over 6 years
Thanks Miguel. I will check it out regarding noise. My setup right now is just DC motor with rack/pinion gear and with some brake force applied to the shaft to simulate load. The goal is to equip my antique lathe with CNC power feed based on servo. Another question if you don't mind - did you use or using SW package like Matlab/Simulink to simulate and tune PID?
misan
misan
over 6 years
I am afraid it might be due to noise in the step input pin. Position can be changed by both, serial port commands and pulses om step pin. If you are controlling your gear using serilal port only connect a 4K7 resistor from step input to GND to make sure it is not detecting any noise. Great to know it is working for you. Feel free to share your application case.
Gennady Yakubovich
Gennady Yakubovich
over 6 years
Hello Miguel. I had great success with your DC closed loop control system. I built a test rig with printer motor Arduino Pro Micro and H=bridge. Everything works great - I was able to tune PID to fast response with no oscillations. I have one question though - I noticed that set point (position) is often changes by itself (??) . I am checking position by calling with "?" and see that it becomes , say, 999 or 998 instead of 1000 what I've entered. Is that calculation error ?, may be rounding ?
yalfeny
yalfeny
over 6 years
greeting miguel sanchez as this miguel excuse me to use your page but I am an electronica student and I have a program that is giving me some flaws to see if you can give me some suggestions since you have extensive knowledge in programming if you can give me your whatsapp or mail where I to write to you like this I do not use this space many thanks beforehand and sorry my english is not my native language .......
misan
misan
over 6 years
Hi Luis, First of all, let me explain that my project focuses on motor control only. My assumption is you devote an entire Arduino for controlling a motor (maybe it can handle two motors if low speeds are used). Any higher level function like g-code interpreting has to be handled elsewhere (at another processor) and commands are sent by means of direction and step pulses. At least step signal *needs* an interrupt input so none of the pulses are lost, that is why I have used a Pro Micro that has 4 external interrupts. A nano can do it if you use interrupt on pin change though. So you need another board to handle motion control, like another nano or UNO with GRBL or a Mega with Marlin or Repetier.
Luis Olivet (Robótica Hi-Tech)
Luis Olivet (Robótica Hi-Tech)
over 6 years
Hola Miguel Sanchez, Mucho gusto, te saludo desde Guatemala. Fijate que estoy contruyendo una maquina CNC pero utilizando el carrete de impresoras epson, las cuales usan motor DC de 12V y lineal strip encoder para su movimiento. yo escribi un codigo funcional con el cual puedo manualmente controlar los ejes X, Y, pero lamentablente no tengo ni idea de como hacer que mi codigo trabaje con GRBL por ejemplo. o como poder mandarle un Gcode con otro programa... no se si tienes algun correo o alguna forma en que te pueda mandar mi codigo y lo puedas checar o bien recomendarme tu codigo como implementarlo a mi sistema. Yo estoy utilizando arduino NANO para hacer esto y utilizo los attachInterrupt 0 y 1 (solo uno para cada encoder PIN 2 para eje X y Pin 3 para eje Y). Otra cosa que no entiendo muy bien, es si tu codigo, se puede usar con GRBL o con el Proccessing para mandarle el codigo G... PD... en un futuro pienso adaptarle un eje Z, pero para este quiero utilizar un servo motor. o bien un stepper con su chasis sacado de una lectora de DVD. PD2.... Perdon por escribir en español, pero mi ingles no es muy bueno, lo entiendo casi bien, pero escribirlo me cuesta muchisimo. Muchisimas Gracias por tu excelente labor, espero sigas trabajando en este proyecto muy interesante. Saludos Amigo.
misan
misan
almost 7 years
Same as any other time using W command. El 14 sept. 2017 17:50, "YouMagine - Supercomputer" < supercomputer@youmagine.com> escribió:
Francisco Antonio Casas Garcia
Francisco Antonio Casas Garcia
almost 7 years
How do you store the variables kp, ki & kd to eeprom the first time in your last dcservo.ino sketch?
misan
misan
almost 7 years
Read the instructions here https://github.com/misan/dcservo
mohamed amine
mohamed amine
almost 7 years
How to set the PID value
misan
misan
almost 7 years
Please note that PID needs to be tuned for your specific needs. If proportional gain is too high, the motor will oscillate around the set point.
mohamed amine
mohamed amine
almost 7 years
Hello I made a robot and I used the card to control the position of the robot Shaper that the robot does not work well I found that the robot swings when you reach the end point I think the problem is in the program
Manuela Cerón
Manuela Cerón
almost 7 years
Thanks, it works but actually i have my printter with stepper motor and is not possible to replace them by dc motors, my problem is how to modify the firmware x_x Thanks for help again
misan
misan
almost 7 years
You may try this https://github.com/neuroprod/ClosedLoopDriver
Manuela Cerón
Manuela Cerón
almost 7 years
Do you know how a control can work for stepper motors? or if something in your project can help? Thanks!!
misan
misan
almost 7 years
@stewart13wolf, No, you can not. My code is intended for DC motor and it is of no use for stepper motors.
stewart13wolf
stewart13wolf
almost 7 years
Hi Misan With the V05 i can use it to control a stepper motor with a normal driver that has Step and Dir input? Thank Best regards Stewart
misan
misan
almost 7 years
Hi Stewart, You can handle two motors per Arduino if the motor speed is not too fast (or the encoder very high resolution). More than 40.000 interrupts/second may start to be problematic (it means it will work sometimes but it may do weird things from time to time).
stewart13wolf
stewart13wolf
almost 7 years
Hi Misan Thank again you have help me, ok it work fine now, i put 2 pull up resistor 10k ohm on the encoder pin AB to 5V, because my encoder is a NPN output. how many axis i can use on one uno?? Thank Stewart
misan
misan
almost 7 years
Please have a look at the instructions on the github link for the serial commands. https://github.com/misan/dcservo "?" command will show the current location that should change when you move by hand the encoder. If not, check its wiring.
stewart13wolf
stewart13wolf
almost 7 years
Hi Misan No when i turn the encoder i have no changing value on the serial display port, i get on this at end ("*** Bad checksum. I use pin2 and pin8 for AB encoder. Thank Stewart
misan
misan
almost 7 years
Hi Stewart, I am afraid something is wrong then. Could you try the encoder is doing its job: Do no connect the motor and check if moving the encoder by hand you get different position values over the serial port.
stewart13wolf
stewart13wolf
almost 7 years
Hi misan i swap the motor wire, the motor start spinning without i touch any axis on my controller, i have to edit something in the code before? Thank for your help. Stewart
misan
misan
almost 7 years
@Daniel Hawkins, That was servostrapv05 program. Please note I was using brushless motors in that case.
Daniel Hawkins
Daniel Hawkins
almost 7 years
Hi Misan, In your pictures it shows a setup where there are two motors connected to a single arduino? Do you have a sketch prepared to operate as such? Thanks!
misan
misan
almost 7 years
@stewart13wolf, swap the two wires of the motor and try again.
stewart13wolf
stewart13wolf
almost 7 years
Hi misan, i have a problem with my uno i use a 600P/R incremental quadrature encoder, the problem when i connect the uno with my cnc controller that is a 25khz pulse output frequency, and i click on X axis the motor start spinning and won't stop and to stop it i have to press reverse two time to stop, this i the same problem on all axis, and when i turn the motor shaft with my finger he turn freely without return to the exact position, can you help me please? Thank Stewart
misan
misan
almost 7 years
Hi @ifmr, It has to work with the Mega too, but the devil is in the details.
ifmr
ifmr
almost 7 years
hi Miguel I'm grateful to you for helping me worked excellently on Uno but Mega did not work thank you very much
misan
misan
almost 7 years
When migrating code, you need to make sure interrupt number and pin number work as expected (as they usually are not a match) https://arduino-info.wikispaces.com/file/view/Mega2-900.jpg/421499040/Mega2-900.jpg
ifmr
ifmr
almost 7 years
attachInterrupt(0, doEncoderMotor0, CHANGE); // encoder pin on interrupt 0 - pin 2 attachInterrupt(1, countStep, RISING); //on pin 3 The entry pin value in the previous code is changed to attachInterrupt(3, doEncoderMotor0, CHANGE); // encoder pin on interrupt 3 - pin 18 attachInterrupt(5, countStep, RISING); //step oninterrupt 5 pin 3 To be compatible with pins for interrupt port in arduino MEGA 2560 ??
misan
misan
almost 7 years
Just try swapping motor wires.
ifmr
ifmr
almost 7 years
thanks guys I changed Encoder pin to pin 18 and pin 19 (interrupt-pin) its connection encodr cable A & B in arduino mega 2560 . and change code to in dcservo.ino file to: #define encoder0PinA 18 // PD2; #define encoder0PinB 19 // PC0; #define M1 9 #define M2 10 // motor's PWM outputs Unfortunately, the dc motor moves in one direction only, without stopping. i use gbrl with arduino Uno R3 for Control Step An Dir
misan
misan
almost 7 years
For Arduino UNO you can use https://github.com/misan/dcservo/blob/master/dcservo.ino and it can be easily migrated to the Mega if, as you mention, you adapt the pins that are interrupt-related so they can also fit on the Mega in an interrupt-enabled pin.
Francisco Antonio Casas Garcia
Francisco Antonio Casas Garcia
almost 7 years
@ifmr As it is only works properly on arduino no, needs to be modified because the interrupts ports are different on these boards
ifmr
ifmr
almost 7 years
hi Miguel What file is compatible with arduino mega 2560 And UNO? I tried the files of the legislator but unfortunately the engine stays in motion always and does not respond to the direction. I am sorry for not perfect English.
misan
misan
about 7 years
Hi @Naveen100, The comments state v05 is for controlling two brushless motors and the pins used. What board and what pins to use is usually mentioned in the comments section on the top the file.
Naveen100
Naveen100
about 7 years
Haii I have uploaded servostrapvo5 but how can I control the motor
misan
misan
about 7 years
You can disable one of the encoder pin's interrupt for reducing resolution by two. You can change the interrupt cause in the remaining interrupt pin from CHANGE to RAISING. That will halve the resolution again. Or ... You can change the line input = encoder0Pos; for input = encoder0Pos/scale; and set the value of scale to the number of your choice (so you can divide resolution for a factor different than 2 or 4). Let me know how that goes.
jordean firmino
jordean firmino
about 7 years
Hi missan where in the code i could change the encoder's resolution? I
misan
misan
about 7 years
that is not an encoder suitable for a motor but it works with my code.
jordean firmino
jordean firmino
about 7 years
Tnks for your reply, so... it works with an Ky-040 encoder?
misan
misan
about 7 years
No, that is a speed sensor not an incremental encoder.
jordean firmino
jordean firmino
about 7 years
Hi misan, does it works with lm393 encoder?
misan
misan
about 7 years
You can use srm32duino to get this done. Or use maple mini code. El 20 may. 2017 11:57 p. m., "YouMagine - Supercomputer" < supercomputer@youmagine.com> escribió:
Adrian Dumitrascu
Adrian Dumitrascu
about 7 years
would be nice if we can run this code on STM32F103C8T6, chap 2$, compact and powerful 72MHz :D
Adrian Dumitrascu
Adrian Dumitrascu
about 7 years
I modify this line myPort.write('X'); String out = "" + targetVal; in to myPort.write('X'); String out = "" + targetVal*100; and this increase motor rotation. on console i get dots everywhere, but i guess i need more tuning or i am doing something wrong i find some value for "kp" "kd" "ki" that prevent movement and wired sound when the system was idle, i mean now is quite and works if i turn motor by hand one direction after release go to initial position
misan
misan
about 7 years
Hi Adrian, You can do as you please: you can just add a multiplier so when you command a certain target position it is always multiplied by a certain factor you chose. Alternatively, you could reduce the encoder resolution so motion will cover more angular displacement for a certain number than before. Current encoder code has four counts by line, you can reduce that to two or to one... so it will turn four times more than before. On the other hand, if you are able to change the scale on your motion controller, you just can tell more pulses/mm are needed with the new setup and change nothing in the servo code.
Adrian Dumitrascu
Adrian Dumitrascu
about 7 years
I mean right now only move 1/4 of full rotation
Adrian Dumitrascu
Adrian Dumitrascu
about 7 years
i tried to use with arduino mini pro and look ok, fist time i used mega2560, now how i make motor to run longer, my encoder has very fine division and display points on console, if i grab him still move but draw a line on the console
misan
misan
about 7 years
Servostrap code is not compatible with PIDTunnigTool nor it uses digital pin 10.
Adrian Dumitrascu
Adrian Dumitrascu
about 7 years
i tried dosnt work pin 10 send no signal to l289n
misan
misan
about 7 years
I mean swapping them.
misan
misan
about 7 years
Could you try swtiching the two motor wires?
Adrian Dumitrascu
Adrian Dumitrascu
about 7 years
hello, i am trying to run your code "servostrap" and use PIDtunningTool. problem is when i run PIDtunningTool i get "*** Bad checksum" in console graphic display nothing and motor run one direction stop then start in same direction. has no signal on pin 10, try switch motor and encoder pins and nothing happened i try to run a scanner assembly from a hp printer, i already test encoder and it work, cont in one direction + in the other - For motor i use L298N. With code loaded arduino and motor powered (gdn is connected) if i rotate motor by hand start spinning and sometime it stop sometime dont
misan
misan
about 7 years
Most CNC machines are 3 axis at least. So even if you control 2 motors with one Arduino, plus another one for GRBL you still will need at least another one for Z axis ... but I guess it all can be handled together with a 32 bit processor (and the right software :-)
Reena Gibson
Reena Gibson
about 7 years
Sorry forgot to mention, I'm also using the Servostrapv05 for the arduino connected to my cnc setup.
Reena Gibson
Reena Gibson
about 7 years
More than 1 axis = more than 2 arduinos? But I thought your current setup controls 2 dc motors, each one in control of 1 axis. Are you saying all of this work can only control 1 axis? Seems an awful lot of work if it is. I've managed to set up my second arduino to the first. I've got the one installed with GRBL connected to my laptop running cncjs. On a simple piece of g code it's sending data to the 2nd arduino running your software. I've checked with a multimeter and the cnc software is making changes to two of the outputs to one of the axis controls. I'm just building a H bridge now for the rest of it to see what results I get from it. btw, I'm using a nano v3, not the pro mini.
misan
misan
about 7 years
Exactly, but for more than 1 axis it will be more than two Arduinos :-)
Reena Gibson
Reena Gibson
about 7 years
Firstly thanks for such a quick response. So if I've got this right then we need to have 2 Arduino's. The first Arduino with your software directly connected to the linear encoders, H bridge and DC motors with your dcservo code, and then connected to that we have the second Arduino with the GRBL software which is the bridge between the CNC software and the first Arduino.
misan
misan
about 7 years
@Reena, If controlled through step/dir signals, this controller obeys the commands of an external motion controller which would have a different processor and software. A simple one could be GRBL firmware that using another Arduino UNO would provide step/dir signals for three axis.
Reena Gibson
Reena Gibson
about 7 years
I'm really confused over all of this and how it's all supposed to work. I've downloaded the dcservo code for the arduino and it's all working as it should. Serial monitor shows that it's picking up both the X & Z axis that I've got set up. I'm struggling to figure out how I'm supposed to use any sort of cnc software to tell the arduino what to do and what I'm to do with pins A0 & D2 for the direction and step. I think what you've done here is amazing, i just need to get help on the next stage if you could help at all.
HyGy
HyGy
over 7 years
Hi Miguel, Can U provide more detailed description about the driver parts, maybe some links from ebay? is this type of L298N is good for this project? http://www.ebay.com/itm/1-5A-Mini-Dual-Channel-DC-Motor-Driver-Module-L298N-PWM-Speed-Control-NEW-/381658326259?hash=item58dc9be4f3:g:VrcAAOSwnFZXUVgD What is the type of the rotary encoder? Or can I put it from optical encoders and a disc? What is the type of the optical sensor? regards, HyGy
Joachim
Joachim
over 7 years
Hello Miguel, to be honest, I hevend been at the Make Munic myself, but a friend of mine told me, that it hase been quite good last year - No doupt, it is not the leading MAKER_FARE. Anyway, If you will find any reasons to go, you are welcome. Sincerely Joachim
misan
misan
over 7 years
Those bridges with PWM and direction are just keeping your pin count low and make more sense . You can use them with my code but only set one pint (direction, instead of in1 and in2). I haven't heard yet about Munich's faire but I will appreciate your kind offer. Another good reason to go :-)
Joachim
Joachim
over 7 years
HI Miguel, thanks for the support, now, I understand ;-)) Because, I am challenging my leraning courve quike well, I will focus on your non-trapezoidal sketches. It is just to much for me right now. Tomorrow night, i will try to make my fist speedtests with the Wemos D1 Mini and let you know, when I have results ---- hopefully One last question. There are H - Bridges, which have no enable Pin - Just PWM and Direction Are those usable as well, with your work or is it just something else??? I just read about the make Munich. https://www.messen.de/de/15414/muenchen/make-munich/info http://make-munich.de/ If you are interested to come, and need a place to stay let me know. We have a guestroom in our house - nothing fancy but OK Just in case All the best Joachim
misan
misan
over 7 years
Hi Joachim, There are several ways of controlling a DC motor with an h-bridge. 1) You can use PWM on the enable pin and use In1 and in2 to select the path current will follow when bridge is enabled. 2) You can set on of the sides of the bridge in1 or in2 to GND and use the other pin for PWM (while enable is always on). While three microcontroller pins are needed for (1) only two are needed for (2) but what happens with both approaches is no the same for the off periods. Without getting too technical I am afraid I may have used one or another approach in different cases without a proper explanation. Please note that trapezoidal sketch adds two additional commands 'V' and '@' to set max velocity and ramp up/down acceleration.
Joachim
Joachim
over 7 years
Hi Miguel, I forgot to say thank you for your trapezoidal explanation. Very intersting. All the best Joachim
Joachim
Joachim
over 7 years
Hello Miguel, it took me some time, till i was able, to get the ESP8266 sketch to work - But unfortunately it does not what I expected??? For my Test ia am using a L298 N - H bridge, which worked fine with your scservo-sketch and a Arduino NANO Now I am trying to get the dcservo ESP Wifi -sketch to work with the same h-bridge to compare your sketches, i wrote dcservo ESP on the lefthand side and // dcservo on the right hand side ___________________________________________________________________ const int encoder0PinA = 13; // #define encoder0PinA 2 // PD2; const int encoder0PinB = 12; // #define encoder0PinB 8 // PC0; const int Step = 14; // Digital input 3 is the STEP input. const int M1 = 16; // #define M1 9 const int M2 = 5; // #define M2 10 // motor's PWM outputs const int DIR = 4; // Analog input 0 is the DIR input. const int PWM_MOT = 15; // ?????? What is that for? Does the dcservoesp sketch has two PWMOuts for the H- Bridge, too or does it work with direktion (M1 and M2) and a PWM signal? => Int PWM MOT = 15 ??? Thanks for advice All the best Joachim
misan
misan
over 7 years
The trapezoidal function is somehow experimental feature. Instead of doing the motion as fast as possible to the target position it uses a trapezoidal speed profile, which limits acceleration and max speed. http://www.technosoftmotion.com/ESM-um-html/index.html?tml_trapezoidal_position_profiles.htm
Joachim
Joachim
over 7 years
HI Miguel, Thanks again, I was so focused on the servo-funktion, that I did not expect that you made a LED blink. OK I,ll see it as an other of my "Newby-errors"... The filenames, you choose are easy to get, but as I understood, the trapezoidal speed motion pattern is something different from the former way, you managed to programm the servo-funktion. Is that faster? more correct? more stable? or just and other way to reache the same results? I am feeling a little bit like an old car which wont to go up a steep road. And every time, the motor is to weak for a further motion, I have - Thank Good!!- the possibility to puss the "Hello-Miguel-Help-Button" I really apprechiate your patience, you knowledge and your help. Sincerely Joachim
misan
misan
over 7 years
Hi Joachim, I tried to use filenames that explained what each version was about: wifi, brushless, magnetic encoder were keywords attached to processor name if different than arduino UNO. toggle() function makes the built-in led blink. (it just changes from on to off or viceversa, depending on previous state of led. Again, the variety of ESP devices makes it difficult to answer which pin does the LED use. Plus that pin is used by wifi library too, so that may make my blinking not to work at times or on certain board. It was not a key feature anyway. A static variable is one whose value is kept between different function calls http://stackoverflow.com/questions/572547/what-does-static-mean-in-a-c-program
Joachim
Joachim
over 7 years
Hello Miguel, may be it will never happen, but I really want to understand your work, because it is such an fantastic miracle for me. And of corse, I am working on using it with my mill. I found that it`s, for a binner like me, hard to understand the differences between your numerous sketches. Therefore I would really apprechiate your advice, which one would be the best for my purposes. The one with the trapezoidal speed motion pattern or the "normal ones"? Currently i keep myself busy to understand dcservoESP_wifi.ino, because it it working with th ESP 8266. I tried my best, but i do not understand the void toggle lines. void toggle() { static int state = 0; state = !state; digitalWrite(BUILTIN_LED, state); } Does this has something to do with the CHANGE Interrupt? in void setup, says something about toggle() but I do not find a link to the encoderin Which Pin is connected to the BUILDIN_LED ? is it Pin 4 ? It is really not urgend, and just if you feel OK I would apprechiate your answer. I know, you have more important things to do, than teaching a newby our code. But anyway, I though it is OK to ask.... hoping not to bother you All the best Joachim
misan
misan
over 7 years
Hi Joachim, My experience is that a ESP8266 is fast enough for most encoder/motor setups (unless you run above 10.000 RPM) and if not fast enough at 80Mhz you can run it at 160Mhz. Because your code is running without the encoder there is no way you can know what speed motor was running at. Of course you could measure the pulses using an external device and then you would be able to figure out the speed but I am not sure how that could be useful for other than determining the no-load speed (which you can do with just a variable power supply and a tachometer). I am not sure how can I help you.
Joachim
Joachim
over 7 years
Hello Miguel, I now made my homeworks, and wrote an Arduino-Programm which make it possible, to run my DC motor for a preceise amount of time (lets say 10 or 60 seconds) with a certain speed. (PWMout 0-255) The problem is, that the programm stopps after the given time, but the encoder wheel is running further for a little time, because the motor just gets no power anymore, but no force is stopping it - so it rolls on for 1/5 round and more - depence on the speed ot spinning before. I think I chose the wrong possibility - Instead I schould have told the encoder counter just to count steps for a preceise time interval. Because, I am not a Computerguy (see my code below) I am not convinced, to mess arround in your code - this is pretty complex and I am just starting. Do you have a suggestion for me? I could try to do the speedcomparison ( first of the nano with the ESP8266) with my old Chillipeppr-TinyG method, but i do not understand your ESP8266 code, althogh I can upsoad it to the board.. const int encoder0PinA = 13; const int encoder0PinB = 12; const int Step = 14; const int M1=16; const int M2=5; const int DIR=4; const int PWM_MOT=15; What is M1 =16 and M2= 5 ( the two pwm-outputs like #define M1 9 #define M2 10 // motor's PWM outputs in the Nano sketch? But what is const int PWM_Mot =15 ??? than? Here is my code to run the DC Motor with a given speed for a given amount of time _____________________________________________________ int MotorPwmPin=6; //Declare MotorPin an int, and set to pin 3 int MotorOnTime=10000; //Declare MotorOnTime an int, and set to 6 000 mseconds int MotorOffTime=3000; //Declare MotorOffTime an int, and set to 3 000 mseconds int Motorspeed; // Speedvalue 0-250 should be defined via Seriel Monitor String MotorSpeedMessage= "The Motor runs with the following speedvalue: "; //Declaring a String Variable void setup() { Serial.begin(115200); // Turn on the Serial Port pinMode(MotorPwmPin, OUTPUT); // Tell Arduino that MotorPwmPin is an output pin } void loop() { Serial.println("Welcher Wert von 0 bis 250 soll Motordrehzahl bestimmen? "); //Prompt User for Input while (Serial.available()==0){ } //Wait for User Input Motorspeed = Serial.parseInt(); //Read User Input Serial.print(MotorSpeedMessage); Serial.println(Motorspeed); analogWrite(MotorPwmPin, Motorspeed); delay(MotorOnTime); //Leave on for MotorOnTime analogWrite(MotorPwmPin, 0); Serial.println("Motorlaufzeit zu Ende" ); delay(MotorOffTime); //Leave off for MotorOffTime Serial.println(" "); } The programm is doing, what I expected - What a surprise (it is my first programm ever....) Thanks for helping my again all the best Joachim
misan
misan
over 7 years
Without load a DC motor will run at certain speed for a given voltage. If instead of a fixed voltage you supply a PWM signal to the motor (through your h-bridge) you can see that for a given output %ON, you get a certain motor speed too. The way you can measure the speed is by counting the pulses of the encoder over a fixed time interval. As you increase the PWM value the count of pulses over the same fixed interval should grow. A second way of sensing the motor speed is by the sound it creates. It is easy to tell whether or not the motor is speeding up just by listening to the sound. My point is that you can determine when the processor is overwhelmed by the encoder interrupt rate when a PWM increase no longer translates into an increase in the pulses counted over the sample interval. (A condition that won't happen if processor is fast enough though). Please note that bitmap operations associated with ports are board dependent, which means they won't work if using a different processor. What you mention about the PCI (interrupt on pin change) is a feature of ATmega processors but I do not think it is available on the Due so watch out. (Not really needed as any digital I/O of the Due can act as an interrupt).
Joachim
Joachim
over 7 years
Hi Miguel, No, I have not, but thanks a lot, - I`ll try it out as soon as possible and let you know what I achieved.... I would like to follow your suggestion of a simple way to test whether or no the boards are coping with the motor is to run motor at a know RPM: Here is my dumm question - How ? OK you explained it - I shuld create an approximated RPM to PWM value table - but unfortunately I hav not even understand what that mean and how I could do it. THe only way I could think of a speed-management of my motor is through Chillipeppr & TiniyG and send a certain amount of steps per second. If you would give me further advice to follow your suggestion, I will do so, Run the Motor with full Speed ect.... as you told me. I am sure, your though is as smart as always.... Regarding the Due, for the first step, I deleted everything in your code, which has somesing to do with EPPROM - I thought I could concern myself with that issue, if everything else is funktioning. Now i am hanging at this part of your code { *digitalPinToPCMSK(pin) |= bit (digitalPinToPCMSKbit(pin)); // enable pin {PCIFR |= bit (digitalPinToPCICRbit(pin)); // clear any outstanding interrupt PCICR |= bit (digitalPinToPCICRbit(pin)); // enable interrupt for the group } But i will try my best so solve this problems..... For now thanks again all the best Joachim
misan
misan
over 7 years
Have you seen the code in here https://github.com/misan/dcservo/blob/master/dcservoESP_wifi.ino ?
misan
misan
over 7 years
Look for my esp code for esp. It is working with PID library. The reason of trouble is the order of declaratioon of methods and not the code itself. El 20 ene. 2017 11:19 AM, "YouMagine - Supercomputer" < supercomputer@youmagine.com> escribió:
Joachim
Joachim
over 7 years
Hi Miguel, in view of the PId Library I found the following https://github.com/br3ttb/Arduino-PID-Library/pull/26 Proper c++ -Style / could that be a startingpoint to get the PID Library from Brett working on an ESP 8266? Another project http://www.sheffieldhardwarehackers.org.uk/wordpress/2015/08/sous-vide-cooking-with-esp8266/ uses Arduino PID Library with an ESP 8266 ......." The logic is managed by a popular Arduino PID library, based heavily on their example code for relay-controlled systems."........... so, may be i could, too. I will will ask these cooking hardware-hackers how they implement the PID-library - and come back with the results, If i will understand them.... All the best Joachim
Joachim
Joachim
over 7 years
Hello Miguel, I forgot to mention, that I am not able to do reasonalbe code changes - But i am convinced, I am getting there ;-)). So I startet with the Wemos D1 (ESP 8266) and found out a) The EEPROM.h Library from my Arduino Nano is not compatible. (see http://esp8266.github.io/Arduino/versions/2.0.0/doc/libraries.html#eeprom =EEPROM This is a bit different from standard EEPROM class. You need to call EEPROM.begin(size) before you start reading or writing, size being the number of bytes you want to use. Size can be anywhere between 4 and 4096 bytes. but here i found a changed EEPROM.h. Library https://github.com/esp8266/Arduino/blob/master/libraries/EEPROM/EEPROM.h Later, I found our, that the PID Library from brett beauregard is not funktioning on the ESP 8266 here is a * An ESP8266 port of: * Arduino PID Library - Version 1.0.1 * by Brett Beauregard <br3ttb@gmail.com> brettbeauregard.com See : https://github.com/eadf/esp8266_pid/blob/master/pid/include/pid/pid.h But it is not testet jet??? The next Problim with ESP8366 would be the different handling of interrupts..... So I deceided to take a break an start with the DUE. There at least the PID.h Library should work. If you have a suggestion, where to find hints, how I could change your code and use the Flash memory as a replacement from EEProm I would be happy, But anyway I will try my best - (Could it be possilbe, that your Servocode and yout great work for the community has a potential to infect normal "noncoders" like me with somthing like pashion and curiosity about stuff I did not think about for years - It was just neardstuff for me and now - I am full of respekt and thankful, that guys like you are opening doors ...... Thank you sincerely Joachim
misan
misan
over 7 years
Please note that if input voltage is >=20V the 5v voltage regulator inside L298N board should not be used. That means you had to provide 5v to the board, for example from the Arduino or you risk damaging the regulator.
digitalvoice45
digitalvoice45
over 7 years
Motor temperature is fine. Motor has its own cooling fan. Looking at the data sheet tells me my motor is usable from 12-30V
misan
misan
over 7 years
Then it means motor is underpowered. You can raise the voltage but 20V might be a bit extreme. If possible try with 15 or 16V. Not sure but 20V might be too much for your motor. If you only have 20V watch closely motor temperature.
digitalvoice45
digitalvoice45
over 7 years
Seems to work with 20V 3.25A , but the motor only does response to one direction during the print and the extruder carriage, goes after a normal position change in the same direction as before... until the end of the carriage and the motor still keeps trying to go further... Steps in my Marlin firmware also seems to be ok. The motor does move the carriage as many mm it should move. Any idea?
digitalvoice45
digitalvoice45
over 7 years
thanks Miguel Raising P gain does not have any positive effect on my problem. I use a L298N Dual H-Bridge with a single motor. Under the board is a mark with 12v+. Can i simple plug-in a 20V power supply?
misan
misan
over 7 years
Two possible cases: 1) motor is underpowered or 2) P gain is low You can try raising P gain to see if it helps (without making your axis to vibrate). If motor is not poweful enough you can try raising motor voltage.
misan
misan
over 7 years
Hi Joachim, You approach seems plausible (though failure mode here is missing encoder pulses it may well look as missing steps on a stepper motor). Due or Wemos D1 do not have EEPROM but you can use the Flash memory as a replacement (some code changes required though). I am curious about the max rpm each board can handle. I have not tested my code with a Due but it should work once the right interrupt pins are selected for the encoder inputs (remember just 3.3volts). On the Due any digital input can act as an interrupt. Maybe a simple way to test whether or no the boards are coping with the motor is to run motor at a know RPM (once you have created an approximated RPM to PWM value table). If you run motor full speed and then you count how many encoder pulses you get over a sample time period, you know pulses are lost when the count is below what is expected, you mark that speed as too fast with that board. Reduce the PWM(speed) and repeat the test until you detect no more missed pulses. Just a thought.
digitalvoice45
digitalvoice45
over 7 years
hi I have problems with layer shifting. It seems as if the motor does not come after it. Just like the Motor does not have enough power. Did you have such a problem ever, misan?
Joachim
Joachim
over 7 years
Hi Miguel, As I told you, I would like to make some speedtests with different boards. My controller is a tinyG2 with Chilipeppr and I have an encoderwheel with a small DCmotor from an old Inkjetprinter. I counted the lines per revolution = 2880 Now I configured the stepangle (360 / 2880 = 0,125 deg) and a max traveling speed for my x achis for example 3300 mm / min (My ballnutspindle has 4 mm pitch per revolution) though i calculated 3300 mm / 4 mm Pitch = 825 revolutions per minute) => 825 / 60 sec = 13,75 revolutions per second. Now i multiplicate this number with ther 2880 Steps per revolution which gives me 39600 Steps per second. In my test I am sending my X achis several times to different targetpositions with the configured maximum speed and then back to zero. If Zero is hit, I raise the maximum speed until the system is not able to hit 0 in the end. Als long as it is able to find 0 I am guessing, that there is no step lost. With my Arduino Nano I made 39600 Steps per second without loosing a step Now i wanted to test the Arduino due, but due to my absent computerskills, i was not able to get your code to work with it. I always had problems with the EEPROM.h library Could it be possibel, that the Due has no EEProm???? (http://sebastiannilsson.com/en/blogg/ersattare-for-eeprom-pa-arduino-due/) Or do you have a sugestion, what I could have made wrong? I would like to do my Speedtest with 1 NANO 2 MEGA 3 Due 4 Maple Mini (i just ordered) 5 Wemos D1 mini ( i just ordered, too) 80 Mghz and if possible with 160 Mghz 6 Teensy 3.6 (I guess 180 Mghz) Do you think my speedtest-idea isworth a try? and hov could i get your code work with Arduino Due?? Thanks a lot and please don`d feel bugged, because I am just learning, not really knowing what i am doing. It is not an issue of time, because i will build my mill with your technologie anyway. with 3300 mm / minute or if possible mor lets see Have a good day sincerely Joachim
misan
misan
over 7 years
I meant the so-called NodeMCU or Wemos D1 mini.
misan
misan
over 7 years
Hi Joachim, I reckon you could use an Arduino DUE or a Teensy 3.6 without much problem, that is just something I have not tested myself but it should work ok. Just remember to power the encoder at 3.3v or to use a level shifter for the encoder signals. I used the Maple Mini because of its low cost. But now that I think about low cost you could also use the ESP8266 which was tested too and it can run at 80 or 160Mhz giving you plenty of speed too maybe cheaper than Maple Mini.
Joachim
Joachim
over 7 years
Cool, i will order a maple mini and will let you know how fast I will get. Would it be possible, to use the Teensy 3.6 as well? It is because I am thinking about powering my millspindle with a extra arduino due and TinyG2 If I could use the full 200khz step puls just for it (with chilipeppr and Jsonserver it might be possible to use two TiniyG sort of paralell) I should be able to reach a spindlespeed of over 4000 rpm/ with a strong Misanservo and a beltdrive it should be possible to reach this speed. At the same time I could use this Spindle as an "deliver" achis (A) for a second spindle (from China) which could be mounted on the Millingtable - But for now, it is just thoughts no real plan jet. Let me know, what your are thinking Thanks Joachim
misan
misan
over 7 years
Please note TinyG and TinyG2 use different processors therefore have a different limit in the max step frequency. I have not done a stress test of my Arduino code, so I do not have an exact figure but Maple Mini should give you a significant speed-up over Arduino.
Joachim
Joachim
over 7 years
Hi Miguel, i am using TinyG2 with chilipeppr. https://github.com/synthetos/g2/wiki/What-is-g2core And there they are talking about 200 khz jitter-free step generaton?????? with 50 khz step generation it would be clear, that I reached already the sky. But maybe my steppersecond-calkulation is wrong? so just for doubblecheck I configured my TinyG2 as followed stepangle 0,125 deg (360/2880 = 0,125) pitch 4 mm 720 steps per mm Vmax X-achsis 3300mm/minute 3300mm per minute / 4 mm pitch = 825 rounds per minute 825*2880 Steps per revolution = 2376000 Steps per minute 2376000 / 60 seconds = 39600 steps / second Do you think for example your marple mini code could be worse a try, or would it be smarter just to use 1440 steps per revolution Than my accuracy is at 0,027 mm still much better than the accuracy of my minimill. And even if my "MisanDCservo" would miss the targetposition by 20 steps (which would be a lot) then i am still with 0,05mm accuraca much better of, than the minimill is able to be correct. What do you think? Thanks in advance Joachim
misan
misan
over 7 years
Hi Joachim, You did not mention what type of motion controller you use (grbl, tinyg, smoothieware, etc). In my servo project, the interrupt rate may be an issue when you try your DC motor to rotate faster as than increases the encoder pulses frequency and once you reach the Arduino limit (you mentioned 40,000 pulses per second) it is game over. That limitation can be overcome with a faster processor. Bet there is the limit of the motion controller itself: grbl can generate up to 36Khz step pulses, Marlin can reach 40Khz, TinyG can do 50Khz and I reckon Smoothieware can do up to 100Khz. Some commercial units may even reach 200-400Khz. This limit is by design and you need a faster controller to increase the speed over the limit. (Or to migrate the code to a faster processor if you manage to do the port).
Joachim
Joachim
over 7 years
Dear Miguel, i needed a little time to go on with my "MisanServo-mill-project". I have quadrature encoder, which make 2880 steps per revolution and i am usind a China Arduino nano as my "Misan servo brain" I spended a lot of time to underständ chilipeppr, to control my servo. That`s because i am a almost 50 year old journalist and not a techfreak.... But thats another stora. Chilipepper works really good and now I found out, that my nano is able to control the MOtor without loosing steps, as far the velocity is unter aoorixemately 40 000 Steps per second. With my ballnutspindle (4 mm / relolv) i am able to go as fast as 3300mm per minute. That`s ok, but at the same time i am thinking, weather an other bord (MapleMini 72 Mghzoder Teensy 3.6 with 180 Mghz) could speed the system up? And if it is worth a try? I saw, you did a work on the maple mini as well? - How much faster can you operate with it? My mill is still "in parts" and i am working on the longest X achsis - As far as I have something to show, I will sent you a video Thanks for your great work, it gives me a lot of fun All the best Joachim
misan
misan
over 7 years
Hi Daniel, Thanks for your kind words. You have the code linked above as Servostrap_mm I expected you'll have plenty of room for higher speed. If you find the upper limit, please let us know.
Daniel Hawkins
Daniel Hawkins
over 7 years
Hi Misan! AWESOME project. I got it working last night. However, I'd love to squeeze some more speed out of my motors (had to limit the output to keep from overloading the arduino, my application has a very accurate encoder). You mentioned code for a Maple Mini? I'd love to give that code a try. Thanks again! Daniel
invitro
invitro
over 7 years
Okay thanks a lot Misan, never crossed on my mind the solution is really simple,I just have to reverse the wires polarity for correcting the rotation direction :). You're really helpful and I really appreciated. Keep the good work :)
misan
misan
over 7 years
Do not worry about the encoder direction, if the servo goes mad, just reverse the two motor wires for correcting the rotation direction.
invitro
invitro
over 7 years
Hmmmm the mechanical design is similar with http://www.thingiverse.com/thing:811271 and I'm currently build this printer but I have an idea to change the belt transmission to direct drive because I read a lot of cases about lost step when using the belt transmission if the belt is not tight enough. that's why I want to try to use the direct drive. And I have an idea to use magnetic encoder behind the double shaft motor so the motor can drive directly the shaft. But I think I have to reverse the direction if I have to put the magnetic encoder behind the motor.
misan
misan
over 7 years
Hi, I understand now. The direct drive of the shaft will make the motor to protrude a lot outside of the printer frame. Alternatively, and also UM-like is to use two pulleys and closed belt to transfer the motor torque to the 8mm shaft, if you do it this way motor may not protrude much or not at all. You can get the idea from this printer http://www.thingiverse.com/thing:513955 And it is easy to find pulleys with bore sizes 3mm or 8mm. You can find motors like this built in encoder https://www.aliexpress.com/item/1120-4470RPM-MITSUMI-545-Permanent-Magnet-DC-Motor-Grating-Speed-6-24V/32692592755.html
invitro
invitro
over 7 years
Pardon me for duplicate posting because the website very slow on my site. Anyway, back to the topic, what I want to do is using this DC servo motor on UM gantry style directly attach to the shaft so I don't have to use belt to drive the gantry. And yes, I've been looking those coupler before but the coupler a little bit big for my design but I will look at it again later. And I also found the 775 motor with 5mm D-Shaft and this is really good, the thing is the overall size is bigger than nema 17 stepper motor, so this is not my option for now. And okay, so the only solution using that coupler. Btw do you have experience using double shaft motor and put the encoder behind the motor? if you have an experience, do we have to reverse the direction? because I think the direction will be different when we put on behind shaft. Thanks before.
misan
misan
over 7 years
Hi Invitro, you do not mention why one would want to do that. There are DC motors that are beefier and have thicker shafts, even 8mm diameter. At any rate you can find shaft adapters here http://www.ebay.com/itm/2-3-4-5-6-7-8mm-Aluminum-Flexible-Shaft-Coupling-Rigid-Coupler-Motor-Connector/291882575832?_trksid=p2047675.c100005.m1851&_trkparms=aid%3D222007%26algo%3DSIC.MBE%26ao%3D2%26asc%3D38530%26meid%3Dbc6ddd7fbc68467292a45c0ce250eab1%26pid%3D100005%26rk%3D1%26rkt%3D2%26sd%3D272452697607 and make the 7mm thicker with a drill.
invitro
invitro
over 7 years
Hi Misan, great job!!! But one thing that I'm trying to solve with this motor DC is about the shaft dimension, do you have any idea how to attach the motor shaft (around 3mm) and smooth rods (around 8mm or more) because the gap between those dimension quite a huge, thanks
Jimf
Jimf
over 7 years
I used this version which has standard quadrature encoder ABI outputs. AS5134 http://techref.massmind.org/techref/io/sensor/pos/enc/ENC1.htm
Salam Siddique
Salam Siddique
over 7 years
ok thank you sir...........
misan
misan
over 7 years
Optical incremental encoders can be used too. I have used motors with those built-in but you can buy them as an add-on (these are usually expensive though). http://www.ebay.com/itm/DC-motor-With-AB-Phase-Encoding-Encoder-334-Lines-/252583268555?hash=item3acf22d0cb:g:PvQAAOSwMNxXaVhC
Salam Siddique
Salam Siddique
over 7 years
can we use photoelectric encoder???
misan
misan
over 7 years
Do you mean magnetic encoder AS5600? http://ams.com/eng/Products/Magnetic-Position-Sensors/Angle-Position-On-Axis/AS5600
Salam Siddique
Salam Siddique
over 7 years
hey misan, can you please give a online link (where to buy) of that encoder you used???
misan
misan
over 7 years
Declaring every pin used is definitely the way to go. I might have got away without doing it in my tests, but it was a mistake that might cause trouble other people using a more modern version of development tools.
Moises Fuentes
Moises Fuentes
over 7 years
Hi Miguel on https://github.com/misan/dcservo/blob/master/dcservo.ino#L57 , is not nesesary to declare the inputs pins 3 and 0 ? (step and direction) I do not see it in the declaration pins Thank You for your help
digitalvoice45
digitalvoice45
over 7 years
Tried the step noise Test. Motor does move a little bit.
misan
misan
over 7 years
Usually if you touch with your finger the step input (while input is not connected to anything else) you can create enough noise to produce motor motion. This line enables step input interrupt https://github.com/misan/dcservo/blob/master/dcservo.ino#L57
digitalvoice45
digitalvoice45
over 7 years
GND Pins are tied all together. Also, did adjust the steps in my marlin Firmware. Can you maybe tell me how do I try the square wave test? And how can i check if the interrupts Are disabled? And as I said. With your PID tuning tool everything works fine. Motor Moves, stops, changes directions, all as it suppose to be.
misan
misan
over 7 years
First and foremost question: are Ramps and Motor controllers GND pins tied together? Second: you will need to tune the new value of axis/mm with the new motors so you have the proper scale. Anyway, you can try whether a square wave in the step input pin makes the motor rotate or not before connecting it to the RAMPS board. If that does not work maybe the step pin not the one you think it is or its interrupts are disabled.
digitalvoice45
digitalvoice45
over 7 years
Hello sir, ive wired everything together and the test works fine so far. Now i have implemented the motor into a reprap printer. PID settings looks good and testing with your PID tuning tool (connecting the Arduino) and under load works great. The Axis is moving and do what it supposed to do. But i have a super problem. When I tried to control the motors over Repetier host(ramps 1.4), almost no movement. With the PID tuning tool the movement works like charm. Step and DIR are wired correctly. Any idea? And what about Homing? Will your system work with normal Mech. endstops? Thanks
misan
misan
over 7 years
https://github.com/br3ttb/Arduino-PID-Library
Manmen Men
Manmen Men
over 7 years
PID_v1 ????
misan
misan
over 7 years
Yes you can
Moises Fuentes
Moises Fuentes
over 7 years
I mean arduino pro mini
Moises Fuentes
Moises Fuentes
over 7 years
Hi Miguel. Can I use the latest arduino IDE version to program the arduino pro micro Thank in advance for your help
misan
misan
over 7 years
Hi @Ye, interface between main controller and motor controller uses two signals: step and direction. Source code is provided so you can change anything you want. Motor controller uses one Arduino, depending on the user, motion main controller may use an Arduino or a more powerful processor.
Ye Naung
Ye Naung
over 7 years
Great project! Sir, I want to know how to connect the main controller to motor controller and how to change step and direction.In this project uses 2 Arduino or 1 Arduino board . please explain me! Thank sir.
misan
misan
over 7 years
Not that I can think of. El 24 nov. 2016 2:38 PM, "YouMagine - Supercomputer" < supercomputer@youmagine.com> escribió:
digitalvoice45
digitalvoice45
over 7 years
any other ideas? :(
digitalvoice45
digitalvoice45
over 7 years
yeah sure . But nothing changes :(
misan
misan
over 7 years
just one change only (motor wires swap) if you change both motor and encoder wires no change is actually made.
digitalvoice45
digitalvoice45
over 7 years
did already swap motor wires and also encoder wires. no changing at all
misan
misan
over 7 years
Non-stop motion is usually caused by a motor/encoder mismatch. Could you swap the two motor wires to see if that fixes it?
digitalvoice45
digitalvoice45
over 7 years
Hello Miguel, I've wired everything and it works very well. But I have a problem with the second axis. As I said, everything works fine with the first. The second is wired in the same way. With the same components. except the microcontroller. At the first axis I use an arduino nano with DCservoProtection and at the second axis an arduino uno with the same firmware. maybe there is the the issu? But the secondary axes have a rather strange behavior. I have checked the encoder and it works fine. I have checked the voltage and GND. all good. The secondary motor rotates faster than the motor in the first setup. Also tested with many diffrent PID values. I get the motor also in a relatively quiet movement and holds, but the motor spins almost 4 times faster then the first one. when I connect 12V current to the half L298, the motor tries to start without commands. If I touch the pully a little bit, the motor starts to spinning and does not stop. Any ideas?
misan
misan
over 7 years
Assuming you already have set the steps/mm properly on your 3D printer firmware you can rise the voltage of the DC motor power supply.
jordean firmino
jordean firmino
over 7 years
Hello again missan... I was trying to make the carriage move properly conected to a 3d printer but it is too slow. Is there any way on boost" the movement?
misan
misan
over 7 years
Hi, my project runs on an Arduino, whether it is additional or not depends on what you had initially. It is designed to replace a stepper motor driver. Yes, my h-bridge driver has a 5V supply too. On gihub you will find implementations for various boards, each one is different.
jordean firmino
jordean firmino
over 7 years
Another question sorry, i have to use an arduino uno or a pro mini? (is the same config.?
jordean firmino
jordean firmino
over 7 years
Hello misan i was reading ur project , and its really nice.. but is there any way not using an adicional arduino for the motor control ? do you conect an extra 5v to de hbrigde? sorry about my english
misan
misan
over 7 years
Great job!
Myp
Myp
over 7 years
https://www.youtube.com/watch?v=IyJIqiB6rhw continuous rotation servo + AS5040
misan
misan
over 7 years
Several motors I have used with built in encoders allowed the encoder to work at 3,3v as well as 5v. Try that first before building a level converter. I do not have a Zero to try it out, but it worked in the MKR1000 which is similar to the Zero (they have no EEPROM so I use flash for configuration storage then) https://www.hackster.io/misan/control-the-position-of-a-continuous-rotation-servo-via-wifi-270e64
Ron Horn
Ron Horn
over 7 years
Couldn't get the Logic level converters to work... I guess I will have to keep using the Lm339n buffers with the resistors
Ron Horn
Ron Horn
over 7 years
I was wandering if the Arduino Zero could be used with this code. I would use a 4 channel 5 volt to 3.3 volt I2c logic converter for the encoder inputs to deal with the voltage problem.
Ron Horn
Ron Horn
over 7 years
Thx for the link regarding encoder resolution.... however, I think my encoder makes 1600 ticks per revolution because when I test it with my DR0 setup.... adds and subtracts the position value... that is the reason for quadrature encoders
Ron Horn
Ron Horn
over 7 years
Thx..... I was just curious.... Is there anyway you could utilize the TI MS430 processor to deal with the encoder end of the driver.... It seems to have no problems counting the encoder at high speeds... This would be a cheap solution. One TI 430 could handle 3 channels of encoder counts.
misan
misan
over 7 years
Thanks Ron. You can reduce the encoder resolution by two or by four. That will put less work to the Arduino and it will reduce the count of counts per revolution accordingly. http://www.motioncontroltips.com/faq-what-do-1x-2x-and-4x-position-encoding-mean-for-incremental-encoders/ That can be achieved by only using one encoder signal as interrupt (not attaching the other to an interrupt) and only taking into account one edge of the signal first signal to cause an interrupt. (Instead of any change of the signal to cause an interrupt, just use the RISING edge to cause an interrupt). Very interesting the use of a digital read out app on a phone for knowing the position of an encoder. Thanks. Miguel
Ron Horn
Ron Horn
over 7 years
http://www.yuriystoys.com/ - use the quadrature encoder diagram and the LM339n chip. This might make some encoders outputs more stable as well. Sincerely; Ron
Ron Horn
Ron Horn
over 7 years
Sorry; I forgot to mention that I used the dcServoprotection code in my previous posting. Also, here is the link to Yuri's Toys Website to add a DRO to help setup or for a readout on your Android phone. You say... You like to see what people do....
Ron Horn
Ron Horn
over 7 years
Note: I had to add a PWM motor enable line in your code. Changed encoder0b to pin 4. Put PWM pin on 10. Put analogWrite (10,180) first line in Void Loop. This is the only way I could get the steps from Universal G-code sender to make it move... Sincerely; Ron
Ron Horn
Ron Horn
over 7 years
Just checked my motor encoder.... I getting a readout of 4000 per revolution on Yuri's Dro setup... on my phone. Is there anyway to use a multiplier in the circuit or firmware??? I did get the motor to work.... but, I can scale the revolutions down to get a factor of 0.1 per revolution to calibrate my lead screw.??????
misan
misan
over 7 years
Hi Ron, I think you could use that chip for faster motors. But you'll need to handle the communication with that chip for reading the encoder position. Depending on the cost and availability it might be cheaper to use a faster microcontroller if you need it.
Ron Horn
Ron Horn
over 7 years
There also is an Encoder Shield (3 axis board) available with these Ls7366r encoder interpreter chips.... designed to relieve the Arduino processor from all the movement calculations...??? Would this work with your programming???? Ron
Ron Horn
Ron Horn
over 7 years
Thx for the reply regarding my compiling issue. I was wandering if you have done any programming around the LSI-LS&366r encoder interpreter chip to deal with the Arduino read/write issues????? Below is the Link... http://www.anaheimautomation.com/products/ics/lsi-csi-item.php?sID=270&serID=17&pt=i&tID=159&cID=55
misan
misan
over 7 years
Hi Ron, Please follow this instructions to install a library on your Arduino IDE https://www.arduino.cc/en/Guide/Libraries
Ron Horn
Ron Horn
over 7 years
Hello: I downloaded the files plus the PID_v1.h file (adaptive Example) from the Arduino website.... I tried both a Uno and a Pro... I get this message when I try to compile....... avr-g++: error: Create Process: No such file or directory Your help would be much appreciated... Ron
misan
misan
over 7 years
That code needs you to add a library to your ArduinoIDE. I reckon that is no longer needed if you use the code from github linked above.
Miroslav Marjanovic
Miroslav Marjanovic
over 7 years
C:\Users\kuremalo\Downloads\servostrapv02\servostrapv02.ino:18:28: fatal error: PinChangeInt.h : No such file or directory #include < PinChangeInt.h > ^ compilation terminated. exit status 1 Error compiling for board Arduino Nano. How to fix ? I am new whit arduino and I dont know. Please help :)
misan
misan
over 7 years
You need a speed control loop for that. This project is not providing that but position control. But you may modify it for the reference to be the speed instead of the position.
Bhonjol
Bhonjol
over 7 years
I want to learn to make pid control of dc motor gearbox with close loop system like a conveyor speed which remains stable even given load.. With arduino uno code. Would you please help me? Pls
Bhonjol
Bhonjol
over 7 years
I want to learn to make pid control of dc motor gearbox with close loop system like a conveyor speed which remains stable even given load.
misan
misan
over 7 years
Yeah, besides the Interrupts on Pin Change there are two regular interrupts (the ones we use attachInterrupt with) that are treated differently. Pro Mini and UNO are quite similar and use the same processor. However, do always check the docs. Do no assume that a digital I/O is the same just because of the number on the silk screen is the same.
tomado
tomado
over 7 years
OK. Think I get it. Anything with the same first two characters belongs to the same port. So, given that the port assignments are the same on pin 8 and pin 2 between the Uno and Pro Mini, I should be ok to use the same code between the two without changing anything. Also, PD2 corresponds to Pin 2, and PB0 corresponds to Pin 8. These appear to be on different ports (right?), so should I change to two pins that are on the same port? The code appears to work on the Uno as is...
misan
misan
over 7 years
Watch out, Pro Mini and Pro Micro are both small but use different processors. Pinout is usually available online like this one http://www.auctionzealot.com/members/rkellyp/promini.png PD* PC* ... show the different ports
tomado
tomado
over 7 years
I see. So on point 2, is the port layout on the pro mini the same as the uno? I'm not sure where to look to find that info...
misan
misan
over 7 years
1. You can use a closed-loop motor for Z without a problem. Specially if DC motors is what you can get easily and cheaply. 2. There is a reason, interrupts. The interrupt on pin change is the same code for each port. So you want the two encoder pins to be in the same port.
tomado
tomado
over 7 years
Hey Miguel, another few questions: 1. You use Closed Loop DC for X and Y axes. Do you recommend using this for the Z axis as well? I'm building a 3D printer from old printers and basically, this is what I have available. I'm thinking my Z axis will be a geared closed loop dc motor. 2. Is there a reason you separate the encoder signals by a few pins? Is noise a problem? Or is that just how it worked out for you. I'm thinking of placing them together.
Jimf
Jimf
over 7 years
Ok that worked. "Both NL & CR" is required Thank you very much.
Jimf
Jimf
over 7 years
This was last week so I haven't had a chance to revisit it. I thought I had tried both options. I'll see if I can get it to work tonight. I bought a bts7960 dual h-bridge that I want to try out. The last time i tested this, I used a l298. It worked great but was current limited. The 7960 handles much more current.
tomado
tomado
over 7 years
Miguel, by my understanding, in serial communication /r is interpreted as "carriage return" and /n is interpreted as "new line". These characters 'should' send the CR+LF characters and not a literal "/" and "r" or "n". But I don't know if the serial monitor is set up to use these. Must not be if it doesn't work :). Thanks for your quick response! Jimf, have you changed the option at the bottom of arduino's serial monitor (assuming that's what you're using) to send "Both NL & CR"? That's the only way it will work.
Jimf
Jimf
over 7 years
I have the same problem you are seeing. Using a real arduino Uno and latest arduino compiler. I also tried it on a plain '328 with a external USB serial adapter. Both do the same. This was last week and I haven't had a chance to look into the problem more. I have tried the initial version when it was first released couple years ago and worked just fine. I wanted to try out the newer serial "menu" version but doesn't seem to work. The board hangs after the first serial command is issued.
misan
misan
over 7 years
ok, you should not get any answer unless lines are terminated properly. I do not understand how you could get your Q or ? commands answered if failing to provide an end of line. Go figure.
tomado
tomado
over 7 years
Funny enough, it worked when I stopped manually adding /r/n and changed the option at the bottom of the Serial Monitor from "No Line Ending" to "Both NL & CR". Seems to be working as it should now.
misan
misan
over 7 years
It looks like a stack problem. Could you try with another UNO board?
tomado
tomado
over 7 years
Hey Miguel, Thanks for all your hard work. Quick question. I have an UNO (knock off). I've compiled/uploaded dcservo.ino, as well as dcservoprotection.ino and both seem to have the same issue. Only the "?" and "Q" will work (through Arduino Serial Monitor), and they will only work once. Setting P, I, D, or setting T dont do anything, and once I issue either ? or Q, neither will work a second time (nor will the other work after one has been issued). I'm typing them in like this (no quotations): "Q\r\n" and "?\r\n" "Q/r/n" and "?/r/n" also seems to work ok. But again, the commands only work once until I reset the device by unplugging and plugging back in. Any thoughts on why this might be?
misan
misan
almost 8 years
That is correct. Pro Mini is powered by an atmega328p, similar than Arduino UNO.
tvr3000
tvr3000
almost 8 years
Well, I am embarrassed... I don't even have a Micro Pro, but a Mini Pro... In that case I think I should use the regular dcservo.ino ? At least it compiles and uploads without a problem! Now lets setup a motor and H-bridge and see how its going to work. Thanks for your help.
misan
misan
almost 8 years
Yes, available ports change from one microcontroller model to another. Pro Micro uses 32u4, same as Arduino Leonardo and different than atmega328p used by Arduino UNO. http://www.robotmaker.ru/wp-content/uploads/2013/08/32U4PinMapping.png
tvr3000
tvr3000
almost 8 years
Thanks. i Will double check. So PINF should work on a micro pro (clone) ?
misan
misan
almost 8 years
Remember to switch the Arduino IDE to the right board type BEFORE trying to compile code for it. If let's say Arduino UNO is select, code for Pro Micro will give you a compile error.
tvr3000
tvr3000
almost 8 years
Yes, thank you, I found some more info on google... As I understand it PIND reads all the pins of port D at once. But I can't find any reference to PINF. The line "void countStep(){ if (PINF&B10000000) target1--;else target1++; } // pin A0 represents direction == PF7 en Pro Micro" in the dcservoProMicro file gives the error: 'PINF' was not declared in this scope... Changing it for example to PIND works. Thanks for your help and the sharing of your work!
misan
misan
almost 8 years
They are not defined, but they are part of Arduino plumbing. A given I/O pin belongs to a certain port of the AVR chip, you can see the relationship here http://pighixxx.com/unov3pdf.pdf PDx means that pin belongs to PIND (port D)
tvr3000
tvr3000
almost 8 years
Thank you for your quick response. May I ask one more question? Where are these macros like PIND, PINB and PINF(?) defined in the project?
misan
misan
almost 8 years
Yes, you pick the .ino file that you one (just one) and reply yes to the Arduino IDE request of saving the file onto a folder with the same name. Of course you are encourage to modify the source to fit your needs. Please note, however that some of the code uses macros like PIND or PINB with binary masks instead of much slower digitalRead, so if you change any pin try to update the related code. Initially try to get it working with the initial pins so you get it working before adapting it to your desired pinout.
tvr3000
tvr3000
almost 8 years
Great project. How do you use the github version? Do you copy the file you want (like dcservoProMicro.ino) and compile it in a separate folder? When I do, I get the error "PINF" was not declared in this scope. Do I need to edit the file and change it to the appropriate dir pin? A0? Sorry if these are stupid questions, I have not had much experience with Arduino so far...
yalfeny
yalfeny
almost 8 years
ok, thanks miguel is already well the only thing is the small position error will continue to jousting to put it well thanks again where it was you learned so give me the key jejejej :)
misan
misan
almost 8 years
@yalfeny If your motor is slow then encoder counts should not be missed. You can check that out with "?" command that will printout current location. First thing you need to make sure is encoder is working as expected(you can do that by disconnecting motor wires and moving the motor shaft by hand only). Once you are sure about it, you can connect power back to the motor and try to adjust P value only (I would forget for the moment about I and D). Finally, once motor goes back and forth well (though you might have some small position error), you may try to adjust I & D values.
yalfeny
yalfeny
almost 8 years
have if I understand first start with the P vibrate when I reduce it a bit and then move to I and then the D .. I also clarified that I am using a motor and encoder Rotary printer which commonly bring and the engine is quite slow.
misan
misan
almost 8 years
For setting the PID you use commands P, I, and D together with a number. I would start with P0.1 and I would increase the number little by little testing if moving from X0 to X200 is working consistently or not. You will reach a point where motor will vibrate, that's a sign you need to scale down the P value like half or so.
misan
misan
almost 8 years
First thing is, if your motor runs very fast or the encoder has many counts per revolution the arduino may not be able to count all the pulses and therefore it might miss counts (which is unfortunate and will render the closed-loop useless.
yalfeny
yalfeny
almost 8 years
another thing is that I can not set the correct motor with the PID and there is a formula for carcular well for me ... thanks
yalfeny
yalfeny
almost 8 years
hello miguel sanchez eeh been trying to do this project but I have a small donot inconvenient because when I give advance such x200 and when I give back x0 not exatas back where you start, it's like will jump steps or lose steps have any idea that it is doing. thank you very much in advance excuse my English is not my native language ...
misan
misan
almost 8 years
Hi Blaise, Feel free to share your application. What I like the most is to see what other people are using the project for :-)
Blaise Mibeck
Blaise Mibeck
almost 8 years
SO COOL!!! You ROCK!!!
misan
misan
almost 8 years
You're welcome. Glad that you've got it working.
digitalvoice45
digitalvoice45
almost 8 years
Hi Misan, Yeah, I was using the Stock. But it Doesn't matter anymore. The Problem was the fried encoder sensor. With your PID values, it seems to work really well without load. Thank you Miguel :) really good work.
misan
misan
almost 8 years
You want to get a fast response but without much ringing. For that motor without load P=3 I=1 D=0.01 works for me.
misan
misan
almost 8 years
Forget about the graph for now. You want the motor to follow the target. If T command is not achieving its desired result the rest does not matter. Are you using the stock dcservo.ino code?
digitalvoice45
digitalvoice45
almost 8 years
Hi Misan, Really appreciate your answers and attemts to help. Ive found the error. My controllable power supply had a problem and the encoder sensor was fried. With another motor, finally i get displayed a graph :) The graph, how should it look like when the Motor is adjusted optimally? Thank you so much :)
digitalvoice45
digitalvoice45
almost 8 years
Have tried the dcServoProtection.ino . Same problem :( not any change in the graph.
misan
misan
almost 8 years
It does not seem to be working. While Target changes, position does not. I am afraid there is something wrong in the dcservo.ino as position should follow target values.
digitalvoice45
digitalvoice45
almost 8 years
Hi Misan, Unfortunately no success. :( Have tested out Delays 100-1900 . Unfortunately no effect on the graph. Motor response is delayed when I increase the delays. What should be normal,i think. Have tried out the Arduino IDE Serial monitor. Pressing: T Pressing: A Getting this Values: https://jpst.it/NxYI Thank you :)
misan
misan
almost 8 years
Ok, so port is ok as motor is reacting to X0 and X100 commands. What appears not to be working is "S" command that dumps the sequence of encoder values of last X command. There are a few delays within the code. It issues S command and it waits for a possible answer, later it parses all what is pending on the serial port. Please try expanding that delay to see if it helps getting an answer. You can try S command after an X command over Arduino Serial Monitor to see if it works too.
digitalvoice45
digitalvoice45
almost 8 years
Hi Misan, really appreciate your fast answer. Currently I am use port 10 with 115200 rate. I can Connect via the processing tool, even I can adjust the PID Values via p i D or to Increase P I D . The Motor also responds. But i just can't see any Blue graph within the Tuning tool. Setup: Arduino Nano, L298N bridge, Mabuchi 448 Motor, wired to a Ramps 1.4. with Marlin. Arduino Nano Firmware: dcservo.ino Hope you can help me. Thanks and have a nice week
misan
misan
almost 8 years
Hi, when the tuning tool seems not to work may be because it is choosing the wrong serial port. Please note that in your system a different number might be needed in line 26 String portName = Serial.list()[3]; Number 3 works for me, but try others to see if you get it working (assuming that is the problem).
digitalvoice45
digitalvoice45
almost 8 years
Hi Misan, I really would like to try your system but i have some problems with the PIDTuning tool. :( When i try to adjust the PID values with the PIDTuningTool, i got no response from the Graph. Its even possible to change the PID values and the Motor also stops spinning with 0 But can you help me please to bring the Tuning tool running properly? thanks a lot :)
misan
misan
almost 8 years
You can see dcServoProtection.ino is sanchosk's code that deals error ir a different way, in his case it changes target location to minimize the error and so reduce the output and avoid burning a motor. But if an ALARM signal is all you need it can be as simple as (in the main loop): if(abs(target-encoder0Pos)> THRESHOLD) digitalWrite(ALARM_LED, HIGH); else digitalWrite(ALARM_LED, LOW);
Khalid Khattak
Khalid Khattak
almost 8 years
Miguel Sánchez @ add it please and try to lit an error LED at specific pin :)
misan
misan
almost 8 years
I have been testing several commercial servos and they use to offer an ALARM output that is raised when position error is above a certain (adjustable threshold). While my software is trying to reach the commanded position no matter the error, this approach may end up burning the motor if the error persist for a long time. Because of this, commercial systems limit control's persistency, so it will give up after a limited time (besides raising the ALARM output). I think adding both features to existing code base is quite simple if someone needs such a behavior. Anyway, what you need to happen when a position error happens may me different depending on your application.
cristianmori
cristianmori
almost 8 years
I hove both, but the latter still do not work properly. I modified Marlin so that it send some GCode direcly to the position controllers and both have the same start and ending points, but the path is not sinchronized. Not sure what way to proceed so was looking around
Khalid Khattak
Khalid Khattak
almost 8 years
cristianmori .. appreciated your feedback. I hope you will share the new improvement in Miguel work.
penelopeblue330
penelopeblue330
almost 8 years
@cristianmori what is your setup? still step-dir control? or direct position control?
cristianmori
cristianmori
almost 8 years
Khalid, its part of this forum to comment and throw out ideas to improve, not just take passively what is kindly given. I appreciate a lot Mr Miguel works but I already have a similar setup and looking for different way to approach it since, as per my previous post, I think that keeping the motion planner per step reduce the potential of using dc motor.
Khalid Khattak
Khalid Khattak
almost 8 years
cristianmori ... Mr. Miguel has provided as a low cost solution in the form of Step/Dir DC servo control. Motion planning is not included in his release and its the part of Motion Control software or the advanced Marlin etc. firmware.
cristianmori
cristianmori
almost 8 years
So if there is no synchronization then the motion planning is not taken care by the motor plus encoder but still by the grbl or Marlin or whatever by modulating the steps with the acceleration profile. But I think that in this way the dc motor emulate the stepper and each step is a small start and stop on its own, and therefore it does not fully use the torque that the motor can provide. Isn't it? I was hoping for a synchronized motion where the system send the target and the controller knowing max accel plan the motion in a seamless way and had retroaction with the encoder to modulate if one lags behind and self tune its parameter. Or am I missing something?
penelopeblue330
penelopeblue330
almost 8 years
As far as I observe (https://youtu.be/L-_5KsAOVko?t=37s), there is no attempt of synchronization. the extruder continues to do its job because the firmware thinks itself is on the right track. That's why you see side-tracked filaments and missing infills in the printed object. But in realm of 3D printing, seldom will you see so drastic a missing step (that's not a step! alright, a leap then..). So (hopefully) the momentary mis-printing is not so criticial to the print quality. Pretty much the servo helps a print with (1) preventing accumulative positioning errors and (2) improving max possible print speed associated with 1.
Damien Robertson
Damien Robertson
almost 8 years
Since motor synchronization would be a task of the motion planning, how do you deal with a missed step (ie stepper driver error, and not sending the command to the system)
misan
misan
almost 8 years
Not at all. Motor synchronization would be task of motion planning. El 28 ago. 2016 6:18, "YouMagine - Supercomputer" < supercomputer@youmagine.com> escribió:
cristianmori
cristianmori
almost 8 years
Do this library provide also coordination of axis? how do you make sure they don't get out of sync? You are giving them target and speed profile or just small increment to mimic a stepper?
penelopeblue330
penelopeblue330
almost 8 years
That's pretty much the answer I asked for. Thanks for your kind help and great project.
misan
misan
almost 8 years
GRBL or Marlin both are ok.
RuiZivO
RuiZivO
almost 8 years
Thanks for your quick reply, Miguel and Khalid all grounds are connected. arduino nano -> Arduino pro mini -> H-bridge 1/2 L298N also I tried to comment all Serial.println but not succeeded. Does it not work with GRBL? or only with Marlin firmware?
misan
misan
almost 8 years
These should only be trigeered when using the Serial port. If you use dir/step interface they will not happen. For sure code can be sped up, but critical one is interrupt code that it is now kind of good (though coding it in assembler might shave a few microseconds. Serial comms is intended to be used for loop configuration initially.
misan
misan
almost 8 years
Are the grounds (GND) pins of both boards wired together too? That is a the most common mistake.
Khalid Khattak
Khalid Khattak
almost 8 years
I will suggest to speedup the code //comments all the Serial.Println function in the sketch...
RuiZivO
RuiZivO
almost 8 years
Hi Michael, first great work. I have a problem trying to replicate your work. I can control the motor using Arduino IDE Serial Monitor to send the X200 command and the motor walk 200 steps. But when I send commands through the pins step / dir, the motor does not walk. I have a Arduino Nano with GRBL and Arduino pro mini with DC closed-loop control motor. What is wrong? already checked all the links and it's all right. Regards
misan
misan
almost 8 years
4000 steps per revolution would be for a 1000 PPR encoder. Other than that I used to think 40K pulses/second was Marlin's maximum output frequency. Given that you have a 1000 PPR encoder it causes 4000 interrupts/second and that will easily become burden as you ran at more than a few rev/second. The problem being that Arduino will spend all the timeserving interrupts without having a chance to control the motor. The forum you link states a maximum of 72K interrupts /second. That will mean your max speed might be 18 rev per second or 1080 RPM if my code was real short which it is not. So your speed limit will be most likely below 600RPM. Which translates to 320 mm/second max speed. Not sure there was a questionon your message though. El 12/08/2016 18:42, "YouMagine - Supercomputer" < supercomputer@youmagine.com> escribió:
penelopeblue330
penelopeblue330
almost 8 years
Thank you! Can't imagine how familiar you are with Marlin. Futhermore, by using 1 Arduino on 3 servos with 2GT 16T pulleys, the maximum XY velocity (in real space, not steps space) would be (72kSteps/s) / (4kSteps/rev) * (2mm/teeth) * (16teeth/rev) / 3 = 192mm/s. I uses 30mm/s for my delta, by the way. [The data for estimation comes from http://forum.arduino.cc/index.php?topic=13729.0 and the reply below.]
misan
misan
almost 8 years
It can be done but I do not think it is included https://github.com/MarlinFirmware/Marlin/issues/679 Though a busy wait disabling interrupts could do the trick for a few mements. Longer than that will need temperature loops to be kept running or you will set the printer on fire. El 12/08/2016 17:54, "YouMagine - Supercomputer" < supercomputer@youmagine.com> escribió:
penelopeblue330
penelopeblue330
almost 8 years
I am a bit clumsy with my language. I mean, how about we pause the printer when it has position errors.
penelopeblue330
penelopeblue330
almost 8 years
Thanks for your quick reply. Yes, we will use Arduino Mega + RAMPS1.4 + Marlin as the core. Just that the step-dir pins are fed into the PID position controller of servos, not StepSticks. Am I correct? Although Marlin can synchronize between X,Y,Z,E, it seems to assume quick response of the motor. If, say by hand, the motor is disrupted, Marlin is not well informed and carries on with the extrusion, though the perturbed motor can quickly return to the correct position instructed by GCode (ie accumulated from the step pulses) after it is let go. I am thinking about adding a "position correct" pin, so that before Marlin extrudes, it makes sure the extruder is at the correct position. May I know any concern for which you use one board per motor?
misan
misan
almost 8 years
Hi, Each motor would need an Arduino to control the loop. But there is needed a motion control platform that could be an Arduino Mega with Marlin firmware as you mention a 3D printer. it is this latter the one that will take care of synchronized motion of the several axis. I would used one Arduino (UNO, mini or Pro Micro) per motor.
penelopeblue330
penelopeblue330
almost 8 years
Hi! I was trying to upgrade an old xyz laser engraver (equipped with dc servos) to a 3D printer. 1. I wonder if it would be good to add a pin to sync the movement with GCode? I noticed that when you moved away the carriage, the extruder keeps going leaving a hole/cusp there. 2. Does the whole control process be computationally expensive for an Arduino Uno? I would like to use 1 single UNO to control all three motors coupled to three optical encoders, but is afraid that problem arises from lagging of computation time behind step pulsing rates.
misan
misan
almost 8 years
My project only covers motor control. You need something like grbl rumning on another Arduino to process gcode and to generate the step and dir sigbals that command each motor's controller. El 6 ago. 2016 6:18, "YouMagine - Supercomputer" < supercomputer@youmagine.com> escribió:
secretcharly
secretcharly
almost 8 years
Thanks for the quick reply! I asked because in the video seems like it is following a list of commands. Did you send a list or how did you achieve that? Your project is the best resource that I have found to achieve a 2D pcb CNC with DC motors + encoders but I can't figure the format cause G-code compatible firmwares or libraries are made for stepper motors.
misan
misan
almost 8 years
I am using the Arduino IDE Serial Monitor. El 6 ago. 2016 0:19, "YouMagine - Supercomputer" < supercomputer@youmagine.com> escribió:
secretcharly
secretcharly
almost 8 years
Hi, what interface are you using in the PC to send the commands? Thanks for sharing your job, its very interesting to learn from you.
Khalid Khattak
Khalid Khattak
almost 8 years
Miguel that will be great. My CNC takes S Parameter in gcode to run at specific RPM. For example S400 means 400 rpm. I know that incorporating the same modification in the existing sketch will be very difficult because of the complexity .
misan
misan
almost 8 years
I use Processing 2.2.1 with PIDTunningTool.pde file. Depending on your system you might need to adapt the serial port number. Arduino IDE has no role here (you used it before to download dcservo.ino to your Arduino board). I hope this helps.
Joachim
Joachim
almost 8 years
Hi Misan, I downloaded processing 2.2.1 and the new 3.1 version. Both versions are workung. Unfortunately I am still not able to use your tunigtool..... Which sketch do I have to use via Arduino IDE on my Nano ? Or do I just have to use the processing environment? and how? I tried my best but no success. Help....:-)) Thanks a lot Joachim
misan
misan
almost 8 years
Sorry. You are right, I have been dealing with several projects. I was thinking of a new command that will set a certain RPM value forever. However that may cause serious damage to the people using the project for position control. So I think I will create a different sketch just for that (so the PID this time will deal with speed instead of position). It is not much work really. I hope I can post it soon.
Khalid Khattak
Khalid Khattak
almost 8 years
Miguel, seems you are very busy in your new projects. I wish one day you will add the RPM control in dvservo. I hope soon you will come up with updaye4. Cheerz
Joachim
Joachim
almost 8 years
Hi, and thanks again Joachim
misan
misan
almost 8 years
Hi, The PID tunning program is not for the Arduino environment but for Processing (go to processing.org for downloading it).
Joachim
Joachim
almost 8 years
Hi Misan, I was able to make changes of the Kp, Ki and Kd using the Serial Monitor. Now my System runs sort of OK. To get better results, I tried to use your tuning tool, but I could not make it run..... the Arduino IDE says: "Import does not name a type - and the line import processing.serial.*; is highlited. It would be great, if you could give me a brief advice how to get it work... Thanks in advance, sincerely Joachim
misan
misan
almost 8 years
I have tested several motors but mostly non-geared ones up to 4096 steps per revolution.
Paul J Wolos
Paul J Wolos
almost 8 years
Did you have the motors directly coupled to the pulleys or where they geared down first? How many steps per rotation, 200 or 400?
Khalid Khattak
Khalid Khattak
almost 8 years
Furthermore, I am using BT-2 driver . It is very lowcost can handle upto 50Amp and i think it can sense the current too... Here is the Aliexpress : http://www.aliexpress.com/item/50A-IMS-2B-Single-H-Bridge-Motor-Driver-Module-PID-For-Arduino-intelligent-car/32656592292.html?spm=2114.01010208.3.11.V216L3&ws_ab_test=searchweb201556_10,searchweb201602_4_10057_10056_10055_10037_10049_10033_10059_10032_10058_10017_405_404_407_10040,searchweb201603_2&btsid=9b951ae1-4859-44da-a805-038909b8e397
Khalid Khattak
Khalid Khattak
almost 8 years
Miguel, Thanks for the detailed reply. 1- Can not we use cheap ACS712 circuit for motor current detection. 2- Can you help adding one more parameter say N for motor speed control. I will be happy to have it because i also want my motor to use as a servo spindle for a mini-CNC this command will help me lot. Please do when ever you have time. I will install special 16PPR encoder on the motor for this purpose. Regards
misan
misan
almost 8 years
Running the motor at constant RPM would require a few changes but it is totally doable. However, let me remind you that the faster the motor the more interrupts will cause in the encoder (assuming optical encoder) inputs. Arduino might start to have problems coping with the number of interrupts per second quickly. Two ideas may help here, one is to only use one encoder input and only interrupt on the raising edge (that way the interrupt rate is reduced by four). Another idea is to choose an encoder with fewer pulses per revolution (to lower the interrupt rate too). Speed can be measured by the different in encoder counts within a fixed time interval.
misan
misan
almost 8 years
Current protection is only possible when current is measured in-circuit. That is not the case for the L298 or other H-bridge circuits. If you need that you want to look for Monster Motor Shield that offers current measurement. Once you have that, current may be checked against a maximum threshold within the main loop.
Khalid Khattak
Khalid Khattak
almost 8 years
Also m Is it possible to run the servo at commanded RPM continuously?
Khalid Khattak
Khalid Khattak
almost 8 years
Miguel, can you add high current protection in the Arduino sketch?
misan
misan
almost 8 years
Please note that interrupt pins may change from one Arduino type to another though the numbering being the same might suggest otherwise. Unfortunately DUE lacks of any EEPROM but if you look at the code here https://www.hackster.io/misan/control-the-position-of-a-continuous-rotation-servo-via-wifi-270e64?ref=user&ref_id=44495&offset=0 you can see how I solved it for the MKR-1000 that, like DUE, lacks of EEPROM.
Francisco Antonio Casas Garcia
Francisco Antonio Casas Garcia
almost 8 years
The problem is my arduino board (Freaduino MEGA 2560) =( , I tested it on another and it works properly (Arduino UNO). I have an arduino due board but arduino IDE showed an error because EEPROM library doesn't work with it, it's possible to modify the sketch to use it with it? Regards
misan
misan
almost 8 years
I do not know your hardware. I am not sure what it may need but you can use a 4k7 pull-up on A and B to see if it helps. El 13 jul. 2016 9:23 PM, "YouMagine - Supercomputer" < supercomputer@youmagine.com> escribió:
Francisco Antonio Casas Garcia
Francisco Antonio Casas Garcia
almost 8 years
I used 3.3v supply to test the encoder quadrature, in both outputs i get almost the 3.3v, anyway do I need to use the pull up resistor? The motors I'm using are form a photocopier and it has integrated encoder https://drive.google.com/open?id=0BwUmvT81ekBGY0VZelYxZnlpNEk Regards
misan
misan
almost 8 years
Are the grounds of Arduino and encoder connected together? Some encoders might need a pull-up resistor too. Your assumption is right, moving the shaft by hand should show increasing location (or decreasing when moving in the other direction). If you cannot reach that condition there is something wrong that needs to be fixed.
Francisco Antonio Casas Garcia
Francisco Antonio Casas Garcia
almost 8 years
I made a test, I just connected the arduino with this sketch: https://github.com/misan/dcservo/blob/master/dcservo.ino and conecting the encoder pins A to arduino 2 and pin B to pin 8, and power respectly, spinning manually the shaft no matter the sense always increase the value of target value (wouldn't be the position value instead of?) Regards
misan
misan
almost 8 years
Not sure what's wrong with your setup. If motor does not move at all make sure Enable jumper is present on the 298. If motor moves non-stop try inverting the motor wires. If other problem, let me know. And yes, for best performance you will need to tune PID values. But just playing with P should give you a reasonable result when set right (not too much not too little).
Francisco Antonio Casas Garcia
Francisco Antonio Casas Garcia
almost 8 years
I'm using a 100 ppr encoder. How to calculate th PID values for my setup? Regards
Francisco Antonio Casas Garcia
Francisco Antonio Casas Garcia
almost 8 years
I'm conecting as in this picture https://drive.google.com/open?id=0BwUmvT81ekBGQ0w0ckVKZmRhdEk Is it something wrong or I need to setup the PID values to get right function of the setup? Regards
misan
misan
almost 8 years
I mean to connect step input pin to ground if not used.
Francisco Antonio Casas Garcia
Francisco Antonio Casas Garcia
almost 8 years
Grounding the step pin meaning to conect it to ground right o join grounds between boards? Khalid Khattak could you post your pid values please? Regards
misan
misan
almost 8 years
Great job.
Khalid Khattak
Khalid Khattak
almost 8 years
https://youtu.be/xFekXLbzyJQ
Khalid Khattak
Khalid Khattak
almost 8 years
Wow... 16PPR 3d printed encoder worked like a charm... Thanks Misan :)
Joachim
Joachim
almost 8 years
HI Misan, thanks a lot for your answer I will try my best - And honestly - it is fantastic what you are doing. Charing your work an bringing technic an "know how" to the people - I am not realy young anymore, but I still like to learn different things - and an important requirement is someone to learn from.... You are such a guy - not only for me - Thank you joachim
Khalid Khattak
Khalid Khattak
almost 8 years
Misan, the grounding of step worked like a charm. Thanks... Now i am searching for a good servotune software. Can you guide how i set PID?...
misan
misan
almost 8 years
@Khalid: you're welcome.
misan
misan
almost 8 years
Joachim, you can change values in the source code or using the Arduino Serial Monitor. You can save the new values to EEPROM memory too.
Joachim
Joachim
almost 8 years
Mi Misan, Just great, I took an Arduino Mega for the GRBL, downloaded the universal G code Sender and took another Arduino nano an put your work on it. I am a total idiot regarding all that stuff - but it worked - with an old Ink-printer with an encoderstrip and a DC motor..... Now i am wondering, if it is possible to convert my Minimill into a CNC machine? the only problem I have, is that I am not able to change the KP KI and KD values..... I would be very thankful, if you could give me a hint because under load I the achis is mooving about 1.5 millimeter - I guess that has something to do with this KP KI and KD values??? Thanks a lot for your help, sincerely Joachim
Khalid Khattak
Khalid Khattak
almost 8 years
Misan, Thanks for reply :).. I am using command over the USB as you have mentioned sending X100 means send 100 steps... I didn't grounded the STEP pin :)... Thanks Misan for your valuable feedback on this..for months i was trying to run your code via USB serial only and i was getting random motion..i think now by Groundng the STEP pin i will be able to resolve the issue :)..Thanks again...
misan
misan
almost 8 years
@yalfeny: you do not need an account for accessing my code in github, just go to https://github.com/misan/dcservo/ and select the version you need.
yalfeny
yalfeny
almost 8 years
Hi miguel I have entendigo according I must take into account hithub and not have it if you can please send the code to my correo.tengo an Arduino one, I will use optical encoding so if you can send the code to my mail so you agradeceria..franyer1 @ hotmail.com
misan
misan
almost 8 years
Hi, I am not sure how are you driving the controller. Step and Direction pins? or using commands over the USB-serial connection? If the latter, make sure step pin is grounded so you are not getting any noise in the step input that might trigger random pulses that would change the target location. If using the step input, make sure it is not getting noise that might trigger random movements.
Khalid Khattak
Khalid Khattak
almost 8 years
Here is the link of my setup: https://www.dropbox.com/s/j1xg6qbqowuifmg/123.jpg?dl=0 Do you think these optocoupler encoder can work with the motor?... http://www.aliexpress.com/item/Free-Shipping-3-3V-5V-Slot-Type-Optocoupler-Module-LM393-Comparator-Slot-Type-For-Arduino-New/32546732590.html?spm=2114.13010608.0.84.a2MB9d
Khalid Khattak
Khalid Khattak
almost 8 years
Misan, I am in trouble and want your help. I am using 8-slotted disc as encoder wheel with Optocoupler module with LM393 comparator. I am running the Arduino and using command from computer like X100 to run the motor. The motor run and stop at the target value but after little time the target value itself changes and motor start to rotate to get new target value. I tried lot to resolve the problem but could not..How can i share the pictures of my setup with you and what to do..
misan
misan
almost 8 years
hi, It is difficult to keep adding more choices to a project without making it confusing, I am sorry about that. The code in github is the most recent. But there you have to look at the filenames to see what each fille is intended for and for what board. Brushless with built-in driver and brushed motors are supported with magnetic or optical encoders. Feel free to ask any question you might have.
yalfeny
yalfeny
almost 8 years
Hello Miguel sanchez one more than join the community I want to highlight for your great work and effort, had much looking for a project to eliminate this step hoists can my cnc now I wonder how I can get the code that is more updated for Arduino one thanks eye "" "I do not have much programming conocimiendo" "" ... excuse my English is not my native language
Francisco Antonio Casas Garcia
Francisco Antonio Casas Garcia
almost 8 years
Ok, thanks now everything has sense.
misan
misan
almost 8 years
No no, we have two Arduino boards here: one has Marlin already installed and is the one you use to control your printer. A second board, maybe an UNO, you use it for the control loop of a motor. This second board may receive the signals for step and direction from your printer controller (first Arduino running Marlin). It is the second board where you would upload dcservo.ino
Francisco Antonio Casas Garcia
Francisco Antonio Casas Garcia
almost 8 years
How do you upload the dcservo.ino after uploading marlin? Could you explain it? Regards
misan
misan
about 8 years
Yes, I am using a Mega with Marlin in most of my printers.
vleud101
vleud101
about 8 years
Miguel, Are u using also a Arduino Mega + Marlin software to control your 3d printer? Or do you prefer other kind of software?
vleud101
vleud101
about 8 years
For everyone who are searching for cheap but professional encoders, i just bought 4 of them from this guy on ebay: http://r.ebay.com/a5GL9Q Delivering took to the Netherlands like 2 weeks. More info: https://www.ia.omron.com/product/item/2382/
misan
misan
about 8 years
You are welcome.
vleud101
vleud101
about 8 years
Ha i overlooked the ino dcservoESP_magencoder_brushless.ino from github. Thanks a ton Miguel for your hard work on it.
misan
misan
about 8 years
Yes, that line defines the type of the PID and the relationship between error at the input and control action. It is common that you start your PID and motor starts spinning forever. That usually happens because the output polarity is making the motor turn "the wrong way" increasing the error instead of making it smaller. Just swapping the two motor wires is the simplest way of fixing that. Alternatively you can change DIRECT constant by REVERSE to achieve the same result. (There is not any pull up associated with it though).
vleud101
vleud101
about 8 years
Hello Miquel, Sorry for the noob question but you mean the line: PID myPID(&input, &output, &setpoint,kp,ki,kd, DIRECT); And use the "Direct" as a variable to pull up pin x? This is what i changed so far, #include <DualVNH5019MotorShield.h> #include <EEPROM.h> #include <PID_v1.h> DualVNH5019MotorShield md; #define encoder0PinA 12 // PD2; #define encoder0PinB 8 // PC0; #define M1 5 #define M2 10 // motor's PWM outputs byte pos[1000]; int p=0; double kp=0.9,ki=0.08,kd=0.001; double input=0, output=0, setpoint=0; PID myPID(&input, &output, &setpoint,kp,ki,kd, DIRECT); volatile long encoder0Pos = 0; boolean auto1=false, auto2=false,counting=false; long previousMillis = 0; // will store last time LED was updated
misan
misan
about 8 years
Please note that there are versions for one and for two motors in youmagine, and for DC motor and for brushless motors too. CWCCW is the direction signal of a bruhsless motor driver. I you visit the github link you will find versions for a more descriptive title for only one motor with encoder.
vleud101
vleud101
about 8 years
How i understand its now only for 1 encoder? Because i see only encoder0 And you mean to look at pos or negative and send that to pul up a pin for CWCCW?
misan
misan
about 8 years
You can use the words DIRECT or REVERSE when PID is declared to change the direction of motion. Or you can swap A and B pins of the encoder one the define code.
vleud101
vleud101
about 8 years
Hello Miguel, I see you have a lot of progress in your project! I have a question about the sketch dcservo.ino, how do you give a direction to your h-bridge i only see pwm: #include <EEPROM.h> #include <PID_v1.h> #define encoder0PinA 2 // PD2; #define encoder0PinB 8 // PC0; #define M1 9 #define M2 10 // motor's PWM outputs
misan
misan
about 8 years
Yes Alex, that would be cool. Not difficult to do and a thoughtful addition. I'll have a look at it.
Alex Mech
Alex Mech
about 8 years
Thanks so much for your good work here. One question, I noticed using processing for tuning the servo that when changing P,I or D it always starts from the default values. I wondered if it could be possible to load the saved values by pressing 'W' first and then changing the pid values would start from the saved values?
misan
misan
about 8 years
dcservo.ino works with an Arduino UNO or nano or Pro Mini. I have realized the Pro Micro (or Leonardo) has more external interrupts. That is why you see several versions around Arduino Pro Micro. We want to see more about this giant printer if possible!!
Chad N
Chad N
about 8 years
Thank you so much for all you are doing for the community. And I am very impressed how much time and dedication you are adding to this project! I am working on a giant 20' x 20' ( yes feet) 3D printer. This project is enabling me to use large DC motors to control it. Will the dcservo.ino code work with the arduino nano v3.0? Or is this specific to the Pro Mini?
misan
misan
about 8 years
This is a work in progress. Features are being added as people are suggesting them, but none of the versions of the github is enabled for two motors. I have tried to put the connection details in the comments above for each case supported. You are right that step/dir should be connected to GND if not used to avoid spurious steps. If using RAMPS you do not need to change anything but remember now you have an addtional motor controller that is connected replacing the Pololu of this particular motor, so wires to STEP & DIR have to come from RAMPS to your motor controller Arduino. (To keep things simpler use one Arduino per motor). I am working on a trapezoidal motion pattern command (look for the only filename with the word trapezoidal on it if curious). But you are right, if using the interface STEP/DIR the motor is following blindly the plan the RAMPS is asking for (which is what we want). At any rate, PID is still needed in that case. Over time, my plan is to remove the planning from Marlin and let each motor do its own speed/position planning where Marlin would only set the parameters for each motor and the go signal to all of them. But that is still far in the pipeline.
Chad N
Chad N
about 8 years
Miguel, Thanks for the answer. I wanted to possibly save other people some heartache. . I had been having a issue with multiple attempts where I would have the motor take off on its own if I would turn it or bump it. I think I narrowed it down to two things, I was not connecting the step pin to anything(just to test it) If you are testing serial motion, you may want to tie the step pin to ground. It is also possible that my laptop wasn't supplying enough power via USB to power the encoder and the nano? By attaching an outside power source my problems were drastically reduced Miguel, I am using your GIT for source however I am unsure what variant do you think most stable. I have 20-30 arduinos in almost any variant and cost really isn't an issue. 1. What is the most optimal configuration. 2. I see the pro micro circuit with 2 encoders and 2 motors, however I think the code only is setup for one? Am I looking at the wrong version? 3. Is it already setup for ramps using marlin or do I need to change anything? Will it work with GRBL? 4. If this is too many questions, ignore this, however I am confused how PID is effective using a ramps step/dir input. I may be confused however I was thinking PID was most effective if you gave it a target position and it would plan accordingly. However I thought ramps only sets out one pulse at a time, Is the PID only relative from one pulse to the next?
misan
misan
about 8 years
@Chad: there is not a required or defined number of counts per revolution. All units are based on the counts of your encoder. If it provides 600 pulses per revolutions then the code will do 2400 (600x4) counts per revolution. If you ask the motor to go for 2400 units it will perform a full revolution.
Chad N
Chad N
about 8 years
Misan. First thanks so much for laying this out. You have been a great help. I am have been trying to get this to work using a 600p/r Incremental Rotary Encoder from amazon. Perhaps I am not understanding the logic, however where do you define how many increments per rotation is needed?
misan
misan
about 8 years
@Ritterchen I use a printer part superglued to the shaft on chip I glue the magnet. I would say the sensors are pretty tolerant with less than perfect alignment, but running close to 28K RPM may be not ... so for high speed you need to make sure you balance it right so it is not putting a lot of stress on the motor bearings nor in the magnet holder. The fastest read I have achieved with I2C in Arduino is 164 microseconds.
misan
misan
about 8 years
@Shczm1: Yes, it can be done. Look for LoboCNC in RepRap forums for the details or http://jrkerr.com/index.html
Ritterchen
Ritterchen
about 8 years
@Shczm1 Should be possible - instead of target-voltage you output steps and dir, there was a wiki entry on that. @Misan I got my hands on AMS AS5047P (according datasheet up to 28k rpm) which i will test the next weeks, i could run a test and mount one to a CNC-spindle to test it up to 20k rpm. Those sensors also can be configurated to different encoder resolutions. Based on this http://www.gammon.com.au/forum/?id=10918 the SPI Speed of Arduino Uno looks very fast. It's a very good protocol comparison! How do you position the sensor accurate in relation to the axis, is every micrometer important?
Ritterchen
Ritterchen
about 8 years
@Shczm1 Should be possible - instead of target-voltage you output steps and dir, there was a wiki entry on that. I got my hands on AMS AS5047P (according datasheet up to 28k rpm) which i will test the next weeks, i could run a test and mount one to a CNC-spindle to test it up to 20k rpm. Those sensors also can be configurated to different encoder resolutions. Based on this http://www.gammon.com.au/forum/?id=10918 the SPI Speed of Arduino Uno looks very fast. It's a very good protocol comparison! How do you position the sensor accurate in relation to the axis, is every micrometer important?
Shczm1
Shczm1
about 8 years
Hi Misan, you did a great job. I am thinking if it is possible to control a stepper motor use this method. You may need not use a PID, just compare the feedback with the input. Is that possible? Thank you.
misan
misan
about 8 years
Hi Daniel, for better performance you want a decent encoder, either magnetic, capacitive (CUI are affordable) or optical. The magnetic encoder I use is kind of a hack that works at low speeds. You may give it a try if you want but there are other magnetic encoders that guarantee operation up to 20.000 RPM or even above. These are a better choice as the one I am using is intended for measuring the position of the volume control in a hifi equipment :-) The problem with a high-count encoders is that the interrupt rate maybe too much for a 328. That is why I tested a Maple Mini (much faster and cheap too). The magnetic encoder I use is read via I2C. The sensor gives me the absolute position of the shaft (within one revolution). I process that to control when there is a wrap around in the numbers that signals a new revolution. I read the sensor every PID cycle (1 ms) so it should work below 60.000 RPM (unfortunately sensor max speed is unknown).
Daniel Werbin
Daniel Werbin
about 8 years
I want to do some for 3d printing and I also want to retrofit my own cnc machine with a faster drive system. To get the required speed it seems like I'd need to be able to handle about 2500rpm. Is that doable? I'll happily use a 328 because its so much cheaper. Also, how are you not using interrupts for the encoder? Polling them?
misan
misan
about 8 years
I tested the code with ATmega328, ATmega2560, MapleMini (ARM Cortex M-3), Arduino MKR1000, there is a version for ATtiny85 too and for ESP12E (32 bit SoC) . I have not performed a performance analysis on the step rate or encoder pulse rate limit, among other things because the magnetic encoders I ended up using need no interrupts. I would love to learn about limits if you stress test any of these versions (in the linked github above). I have noticed that for my target use, 3D printing, motors do not need to run faster than 1200 rpm and for that speed even the smallest Arduino seems fine. of course my code is no optimized for speed, so I guess assembler interrupt service can improve upon that quite a lot.
Daniel Werbin
Daniel Werbin
about 8 years
This looks exactly like what I was gonna make.. now I don't have to! So this, so far, works pretty well as a drop in replacement for steppers as far as I can tell, yes? What is the max frequency that this thing can run? As in steps/second and how fast does the pid loop keep everything regulated? Have you found that it works pretty well? Also, I know you're probably not looking for another microcontroller platform to use, but have you checked out the teensy 3.2? It has hardware quadrature decoding, it runs at 72mhz, and its only 20 bucks, probably ideal for this kind of thing.
misan
misan
about 8 years
@tandel: Do you have any record of your progress? (a blog or something else).
tandel
tandel
about 8 years
hi engin and misan , engin can you provide your schematic to me as then i know what are you doing actually .... and i also interested to make pcb for you ..let tell me tell you something that i'm not expert or something but i have some experience with ir ic and ir based h briges ...i also itrested to make bldc servo ..and i am developing bldc driver currently to drive with this servo ....i am also afraid of that you are working with high power so if there will something wrong with my provided design that you put in trouble so ...i am not giving any warrrentis or garrntey but.....i am also trying the that you want to achive so this way we can support each other and community ...also thanks misan hi misan if you need any bldc driver that can support your code i will try to make and as i know that you have some experties with this servo stuff so we can know about reasult so endgin and misan i will wait for your reply thanks againt to misan !
engin
engin
about 8 years
hi tandel i made 110 vdc dc servo driver but i try todays 180 vdc driver...thanks for ur support
misan
misan
about 8 years
Hi zxrgreg, I think your plan is totally feasible. Let us know how it goes.
zxrgreg
zxrgreg
about 8 years
hi misan, i have old plotter with a bad board, it has 2 hansen dc motors with encoders. the encoder have 1000 step per revolution. I would prefer to use these motors since they work and are already designed for the machine. will this work for my applicaton, and can i simply use the setup per motor with pro mini to a uno with grbl, or is there something better. each motor is connected to a L6203, I think at 4A
tandel
tandel
about 8 years
hi engin this will be useful http://tahmidmc.blogspot.in/2013/01/using-high-low-side-driver-ir2110-with.html
amg66
amg66
about 8 years
hi how can control DC motor with h- bridge and Arduino Uno and what is the code? and I want motor to move from 0 to 60 degree and when you moved back to 59 degrees back to 60 or if you move it to forward 61 degrees back to 60 closed loop
engin
engin
about 8 years
hi tandel, 220 vdc and 10 amper i using brushed dc motor
Mathys
Mathys
about 8 years
Hi ddv Thanks for your input, yes I am also still building my printer was going to go with normal steppers but I like the smoothness of the dc motors and the possibility of higher printing speeds. I thought the arduino might battle with higher speeds, interrupts are fast but to handle a lot of interrupts and moving the stepper could be a problem. What motors are you using? Would be cool if we can keep in touch heres my email - Mathyskrugel@gmail.com
ddv88334
ddv88334
about 8 years
Hi Mathys, I encountered speed problems with the original setup. I'm using one servo motor with one arduino. The problem is when you sent dir step pulses at a high rate to the arduino the interrupt service routine is called often to update the position of the motor and is missing step dir pulses during this moment. So I developed an additional circuit with a pic16f628 microchip controller to take over the counting of the step/dir pulses and sent them to the arduino by the serial port to the arduino. Now I'm no more missing pulses from Repetier. The principle works but I can't do a real print test for the moment because my 3d printer is still Under construction. I expect to finish the printbed and printhead within some weeks. If the result is OK then I will let it know here in this discussion. Misan did a great job and is one of the pioneers to integrate a servo system in the arduino. Thanks for your effort Misan.
misan
misan
about 8 years
Hi Mathys, Thanks. Github code is much more complete and updated. I tested the use of one Arduino to control two motors and I included the code as servostrapv05. All the other programs are for one motor only. You can use the nano but code designed for the Pro Micro may need to be adapted in order to work properly or at all. Faster speeds are not something I am exploring at the moment as I am working to get smoother operation but that is definitely possible.
Mathys
Mathys
about 8 years
Hi Misan Thank you for your effort and work. I just got a few questions. Which code must I use, the github code under update 3 or this Servostrapv05 under documents, which one is the latest or are they the same? I see you use one arduino to control 2 motors is that to do with the speed of the micro controller, would it matter if I use a Arduino per motor? Then I see you schematic has a pro micro, Could I use Nano's and must I change any pin out puts? What are the advantages in using this closed loop system except the fact that you wont miss steps, you could probably print alot faster than with steppers? Thanks
misan
misan
over 8 years
I have used Inkscape.
tandel
tandel
over 8 years
hi misan what tools have you used to draw that arduino and encoder diagram?as shown on your images
tandel
tandel
over 8 years
ya it will be the same step and dir system how much amps ? how much voltage ? does your motor requires ?
engin
engin
over 8 years
hi tandel, thanks for ur idea..im not sure will be same system coz i drive with use pulse and direction and i will use high kw motors same as 2-3 kw for cnc...lets try if u have codes for this idea
tandel
tandel
over 8 years
edgin if you want drive bldc i have an idea we can deive bldc with misans code with help of this we mke this with work with two arduino if you need high power we need to use ir mosfer driver ic and mosfets so we can hadle good power http://elecnote.blogspot.in/2014/11/cd-rom-3-phase-sensored-bldc-motor.html
engin
engin
over 8 years
i need plenty driver from that i must production myself...
misan
misan
over 8 years
http://www.geckodrive.com/geckodrive-brush-dc-drives.html
engin
engin
over 8 years
example page?
misan
misan
over 8 years
A high-voltage h-bridge is what you will need but I have no idea where can you get one or how much it will cost you. Please be aware that as you venture to industrial power levels the DIY approach may not be the cheapest one.
engin
engin
over 8 years
misan forgot BLDC motors..i found 10 pieces BRUSH motor but 180 vdc so how will i drive? l293 chips just small dc motors..do u have idea?
misan
misan
over 8 years
Hi egin, Driving a BLDC motor is not part of my code nor my expertise. If your motor does not include a driver my project won't work with it.
engin
engin
over 8 years
i found 200 v dc 10 motor but how will i controll thats with this system? l293 small dc motor ok but high voltage motor so do u have circuits?
misan
misan
over 8 years
Hi egin, Glad to know. For BLDC you need a motor with the built-in driver. The ones I have tested have two control signals: speed (pwm input) and direction (digital input). Then it is easy to changed the pwmOut function to feed these the PID output.
engin
engin
over 8 years
hi misan, system working perfect in brush siemens dc motors, but how can i use bldc motors? i need high torque on system
misan
misan
over 8 years
Yes, it is possible but pwmOut code would need to be changed. The BLDC motors are mentioned do include a driver with PWM input for speed and a digital signal for direction. While a regular ESC does include just a PPM input. Anyway please note that most ESCs do turn motor only in one direction and are mostly built for speed control, having a poor response at low speed that would make them not the best choice for a position control.
Cedric Lemle
Cedric Lemle
over 8 years
Hello Misan, is it now possible to hook up a Hobby ESC and a BLDC outrunner to the Arduino output ? I´ve seen that in "servostrapv05" is a "BLDC" mentioned picposter
engin
engin
over 8 years
thanks for answer myall questions..all problem so need controll unit gnd connect also arduino gnd then start worked
engin
engin
over 8 years
i try everythings still same..only normal turning one side..other side turning nonstop until i push again to normal side for turn
misan
misan
over 8 years
Your last test tells me there is something wrong with your setup. Motor should change direction on that test but it does not. Till that is fixed you cannot expect the rest to work properly.
engin
engin
over 8 years
misan if x+ turning right then x- also turn nonstop to right..
engin
engin
over 8 years
misan, when i push to t then normal working and i read all value on serial monitor..but when i gave step and dir signal just one direction shaft normal working, other side nonstop turning
engin
engin
over 8 years
i must remove encoder power and test?
misan
misan
over 8 years
I cannot be sure but it seems there is something wrong with your output circuit. If you disconnect the encoder supply, you can start the controller and send a location for X+ and then issue a location for X-. Is the motor changing the direction of motion then? If not there is something wrong with your h-bridge or wiring.
engin
engin
over 8 years
i using grbl cnc controller and ardiuno uno
engin
engin
over 8 years
how can i fix misan? in auto normal..just one side nonstop, other side turning what i sent postion and speed
engin
engin
over 8 years
on serial monitor show updates to one side normal and i can controll with controll card but when i sent to back axis then show on serial monitor target side nonstop going to up and motor shaft nonstop turning
engin
engin
over 8 years
i noted show in serial monitor when turn to back so target often going to high then motor shaft non stop turning but when i send right side turning to normal..just one side have problem
engin
engin
over 8 years
i forcing turn shaft with myhand but shaft ok so both side
engin
engin
over 8 years
if i test with serial monitor with push to T then ok but when i test with controll unit show also on serial monitor too high target position
engin
engin
over 8 years
motor turning what i set speed and position to one side ( example x+ axis ok) but when turn to other side (example x- axis) then non stop turning
misan
misan
over 8 years
First of all you need to make sure encoder pulses are counted right in both directions. Moving shaft by hand helps you verify that.
misan
misan
over 8 years
If motor is fast it might be a problem but that will have the same effect both ways. Usual position commands will not allow the motor to run at full speed.
engin
engin
over 8 years
i sent command so turning one side not problem but when i sent other side so nonstop turning and monitor show target too much high...
engin
engin
over 8 years
i use 1000 ppr encoder..problem from that?
misan
misan
over 8 years
Hi egin, it seems you're almost there. Resisting forces in one direction but not in the other might be caused by incorrect encoder counts or wrong output (maybe one of the two PWM outputs is not working). Try to make sure encoder counts ok when you turn the shaft manually in each direction (use commnad "?" to query location or command "a" to get auto updates of location value) with the motor unpowered.
engin
engin
over 8 years
hello misan..i just test..right side turning ok when i push to move on controll card..but when left side then turning nonstop..why?
Khalid Khattak
Khalid Khattak
over 8 years
misan,Thank you... You are a genius.. Solved my problem..Now i am tuning :)
misan
misan
over 8 years
@Khalid, have a look at this https://forum.processing.org/two/discussion/5277/serial-port-change
Khalid Khattak
Khalid Khattak
over 8 years
misan, thanks for quick reply. I confirm that your program connect to arduino port (in my case COM10). But now tell how i can send serial data from your tuner?
misan
misan
over 8 years
Hi Khalid, A second posible source of trouble is if Arduino serial port happens to be on a different comm port than my program is looking for it. You may see the list of devices the program prints at the beginning on the black bottom area of Processing and find which one is the Arduino port. In my code that is line String portName = Serial.list()[0]; change the 0 by the order of the entry that matches arduino comm port on your listing.
misan
misan
over 8 years
Hi Khalid, Serial port can only used by a single application. If Arduino IDE has the Serial Monitor open there is no way other programs, Processing included, could use it then. My tuning program tries to connect to the Arduino Serial port, if it fails it won't work.
Khalid Khattak
Khalid Khattak
over 8 years
misan, i run your servo tuner in the PROCESSING. The windows opens only if i disconnect my arduino from COM port. In this case how can i send command like X123 etc to see the response curve. I searched a lot but the processing has no serial terminal i think. Regards
misan
misan
over 8 years
Hi Benson, you're right W is typo and needs to be removed.
misan
misan
over 8 years
Hi, Usually you need to tune the motor for the response to suit your needs. What you describe seems to be a case where too much P gain is used. You can limit the maximum output to a value of your choice, that is the purpose of setoutputlimits call. If you feel P gain is ok but regulator output is too high you can reduce the range out the output.
Khalid Khattak
Khalid Khattak
over 8 years
misan, I have installed 24PPR quadrature encoder on a small dc motor. Your Arduino sketch drives the motor but it is too fast that it generate too much error and it takes lot of time to come to its position. For example when i send X300 it start too fast cross the 300 and end near 700 where Target and setpoints are adjusted and error become zero. I have tuned the PID values but thats too much error .. Is it possible the sketch can change its PWM value when it become near it setpoint/target position?... Also can you please tell what does this mean.. myPID.SetOutputLimits(-255,255);
Benson Hadlock
Benson Hadlock
over 8 years
Hello Misan, When compiling the dcservoProMicroMagneticEncoder.ino Version. On line 113 you have void pwmOut(int out) {W When I remove W it compiles. is this correct This is the Error code I Get. Arduino: 1.0.6 (Windows 7), Board: "Arduino Micro" sketch_feb11a.ino: In function 'void pwmOut(int)': sketch_feb11a:110: error: 'W' was not declared in this scope sketch_feb11a:111: error: expected `;' before 'if' sketch_feb11a:115: error: 'else' without a previous 'if' Thanks Benson
Benson Hadlock
Benson Hadlock
over 8 years
Hello Misan, When compiling the dcservoProMicroMagneticEncoder.ino Version. On line 113 you have void pwmOut(int out) {W When I remove W it compiles. is this correct This is the Error code I Get. Arduino: 1.0.6 (Windows 7), Board: "Arduino Micro" sketch_feb11a.ino: In function 'void pwmOut(int)': sketch_feb11a:110: error: 'W' was not declared in this scope sketch_feb11a:111: error: expected `;' before 'if' sketch_feb11a:115: error: 'else' without a previous 'if' Thanks Benson
Khalid Khattak
Khalid Khattak
over 8 years
Misan, I saw the comments. Thanks for explaination..
misan
misan
over 8 years
It samples the current location every five 5 milliseconds (only once every five loops each loop taking 1 millisecond)
misan
misan
over 8 years
You will find the answer in the github
Khalid Khattak
Khalid Khattak
over 8 years
Misan, Can you please explain what does following code of line do. if(counting && (skip++ % 5)==0 ) {pos[p]=encoder0Pos; if(p<999) p++; else counting=false;}
misan
misan
over 8 years
Hi SingularitySurfer, Thanks for sharing your project and your code.
misan
misan
over 8 years
Hi Robert, the encoder code comes from here http://edge.rit.edu/edge/P13211/public/Senior%20Design%201/Research/Sensors/How%20to%20use%20a%20quadrature%20encoder.pdf And the idea is that values 2 or -2 represent imposible transitions that a better coder will control as errors as they should never happen.
robert_gt
robert_gt
over 8 years
correct table QEM [16] = {0,-1,1,-2,1,0,2,-1,-1,2,0,1,-2,1,-1,0}; ??
SingularitySurfer
SingularitySurfer
over 8 years
I modiefied the Controller so it can get position increments via serial and the PIDtuningTool sends these with delays according to the desired ramp speed. So I had to mess around in both Firmware and PIDtool.
Khalid Khattak
Khalid Khattak
over 8 years
Hi SingularitySurfer, did you implemented the RAMP function in the main DCServo!!! /* new code */ void do_a_Ramp(int Steps, int Speed){ int delaytime=1000/Speed; // delaytime after each Step according to Speed myPort.write('N'); // Stets the 'p' couter that monitors the positions in the Controller Firmware to 0 for(int i=0; i<Steps; i++){ // ofc the rest of the code here takes no time to run and my Speed calculation is absolutely precise! myPort.write('+'); delay(delaytime); //println("Step="+i); } }
SingularitySurfer
SingularitySurfer
over 8 years
Ok, so i've never shared code and with all the stuff I do it's pritty messy. I thought I take the opportunity and finally make a Github account. So heres the stuff: https://github.com/SingularitySurfer/Edited-Closed-Loop-Controller-by-Misan Ok so because as I said the timing of the captured data to match the drawn input is wierd you can do this if your data doesnt make sense: - edit the Controller firmware so it wirtes the Input (target1) in the position vector - try to edit the scaling in the Graph so it matches the ideal Line - then go back and put the Output data back in the position vector yeah i know thats cheating but whatever works :P Good luck! :) btw heres some of my captured data: http://imgur.com/a/ZEPAs first pic is KP2 KD0 KI0.125 second is KP30 KD0.22 KI 16 (I use these for my System) last one is KP3 KD0 KI64 (you can see the System is barely even stable and yeeeah i tried more than that xD)
Khalid Khattak
Khalid Khattak
over 8 years
Dear SingulritySurfer, i was looking for Ramping inputs and happy to see you have implemented . can you please share your code/arduino sketch?
SingularitySurfer
SingularitySurfer
over 8 years
Hello everyone! I've straped a Closed Loop System based on Miguels controller firmware on the "Mostly Printed CNC" which was really cheap and works really well :) Vid if anyone interested: https://www.youtube.com/watch?v=uphXy3URQ6g Also I modified some code so the PID Tuning Tool can now give me a Ramp input response. As most of the controller inputs are Ramps and you cant really see the integral action in the Step response I think this is more interesting that the Step. I could really see how upping the integral feedback braught the steady state error to the Ramp input to zero. :) Because timing the data the controller firmware sends back was kinda akward, the code I wrote is not really pretty..
misan
misan
over 8 years
One more wire?
Khalid Khattak
Khalid Khattak
over 8 years
Thank You misan... Can you tell why you not using Break function?... What is disadvantage of breaking?
misan
misan
over 8 years
You are looking at an old piece of code, so you are missing most of the fun. Code was commented out because I no longer needed to use the break function on that brushless motor.
Khalid Khattak
Khalid Khattak
over 8 years
Why you have commented out following line: // if(abs(out)<10) digitalWriteFast(13,LOW); else digitalWriteFast(13,HIGH); // brake,
Khalid Khattak
Khalid Khattak
over 8 years
Thanks misan, for pointing out :)...
misan
misan
over 8 years
What you seem to be looking for is this http://playground.arduino.cc/Code/PIDLibraryAdaptiveTuningsExample
Khalid Khattak
Khalid Khattak
over 8 years
i can't comments more than 4 lines here..i dont know why? but can you tell the purpose of out<10 in the void pwnout(int out) function?
Khalid Khattak
Khalid Khattak
over 8 years
misan, I am really thankful for providing us such a nice piece of code and hard work. I will try to do my homework. I just need some help in understanding this piece of your code: void pwmOut(int out) what is the value 10? in the expression out<10
Khalid Khattak
Khalid Khattak
over 8 years
misan, thanks for the quick reply. Please can you change how can we reduce PWM value when the motor is just near to reach its setpoint to avoid overshoot and this will make a very smooth stop?
misan
misan
over 8 years
Dear Khalid, I cannot do everyones homework, I hope you understand.
Khalid Khattak
Khalid Khattak
over 8 years
Sorry, English is not my Native language and i am very poor in programming. I want the motor to reduce PWM when it reaches neaar its Setpoint for example... If my setpoint is 40 and the Threshhold value is 10 then i want that when the motor reaches at 30 its reduce PWM to certain limit for example 100PWM value. and from 0 to 30 it runs at full 255PWM.
misan
misan
over 8 years
Hi Khalid, You do not initialize each time Motor_Duty_cycle or set analog_output if error is greater than the limit so "fast speed" when error is larger than STEP_MARGIN won't work for you.
Khalid Khattak
Khalid Khattak
over 8 years
I did somework untested ..Please helpm me correcting. The sketch file is here. I just commented out for only one motor, if you can see the implementation of Soft Start/stop in void pwmOut(int out) function and some declaration of variables at the top. https://www.dropbox.com/s/fkdmvjd1o8uq2by/servostrapv05_modified.ino?dl=0
misan
misan
over 8 years
Hi Khalid, Not sure what you are trying to achieve (you do not explain). Current code can easily limit the maximum control output with myPID.SetOutputLimits(
Khalid Khattak
Khalid Khattak
over 8 years
Misan, Thats a wonderful work. I am interestuing in the new servostrap version in which you will include Soft Start/Stop of motor. I think its doable for the guy like you.
arnav chopta
arnav chopta
over 8 years
hmm, i know - there are many plant configurations... but whats the goal to achieve - 10s, 1s, 0.1s, 0.01s for movement finishing? how fast it is in Your case?
misan
misan
over 8 years
Hi Arnav, Sorry but the right answer is it depends a lot on the configuration.
arnav chopta
arnav chopta
over 8 years
misan, how fast is motion/position establish in Your hardware - how long PID works to be right in declared position?
misan
misan
over 8 years
You would need to change: myPID.SetOutputLimits(-255,255); to myPID.SetOutputLimits(1000,2000); and pwmOut code to just this line: myservo.writeMicroseconds(out); provided you first have defined a servo instances called my servo attached to one output pin where the servo is connected to.
misan
misan
over 8 years
Hi Winter, You definitely can change the pwmOut function so it might may provide an output an RC servo or ESC can understand, that is easy (just use the servo library) https://www.arduino.cc/en/reference/servo You are right that a bidirectional ESC is need or you won't be able to correct position. However, though I see the potential savings of using RC brushless motors I see too, that they are difficult to control sensor-less at low speed. But I am more than interested on the results you might obtain. You may want to have a look to VESC project too.
Winter Tod
Winter Tod
over 8 years
Hello Misan, it's a really nice Project. I had a idea, you could output a servo controll PWM and connect a bi-dirrectional ESC and brushless motor. They are way cheaper, a 700w motor costs 20€ and a esc 10€ -20€. The cheapes brushed DC motor I found was a car motor with 40W for 20€. Do you think its possible to change the output to PWM with the servi library or is it too much work and need much rewrite? have a nice day!
misan
misan
over 8 years
I reckon that is why I coded them https://github.com/misan/dcservo/blob/master/dcservo.ino#L22-L23 which in fact was borrowed from servostrap project.
arnav chopta
arnav chopta
over 8 years
Capitalics in "...PinX" New = ((digitalRead(encoder0PinA)*2) + digitalRead(encoder0PinB));
misan
misan
over 8 years
Yes, that is almost correct. Try this one (only bits 0 and 1 should be set). New = ((PIND & 8 )>> 3) + ((PIND & 4) >> 1);
arnav chopta
arnav chopta
over 8 years
But this: New = (PIND & 8 )+ ((PIND & 4) >> 1); Will be much faster as I understood?
misan
misan
over 8 years
Hi Arnav, Yep, the code for the encoder was borrowed from Let's make robots forum. Let's rewrite the code in more intelligible way (but less efficient): New = digitalRead(encoder0pinA)*2 + digitalRead(encoder0pinB);
arnav chopta
arnav chopta
over 8 years
misan, I am thinking about modifications and improvements :-) INT0, INT1(pin change setup) interrupts are describbed in http://www.atmel.com/images/atmel-8271-8-bit-avr-microcontroller-atmega48a-48pa-88a-88pa-168a-168pa-328-328p_datasheet_complete.pdf on page 71. In Your code is QEM table like this one: http://openhardware.ro/wp-content/uploads/RotaryEncoderSignal-1024x516.jpg IMHO stepper (or encoder) as MPG no need the same priority level as realtime-like servo/motor encoder. Its OK, when You prefer MPG reaction ASAP. If not, better way is to move MPG routine to main program loop. I would like to change B channel pin & interrupt to INT1 and "decrease" MPG read priority. Its important for me to understand whats going on in interrupt routine, in line New = (PINB & 1 )+ ((PIND & 4) >> 1); // Can You explain please - its bitwise operation for QEM table reference? If I change channel B to 3 (PD3) and INT1 code will looks like: New = (PIND & 8 )+ ((PIND & 4) >> 1); // ? And in the end, I am start to think about PID autotuning routine... With Regards, arnav
misan
misan
over 8 years
hi Arnay, That's a bunch of smart questions. Let's see: 0. Only two "regular" interrupts on Arduino INTO ad INT1. I needed three, two for encoder and one for stepper. A previous version of the code used only two, one for encoder and one for the stepper (I did not know about Interrupts on Pin Change then). 1. same reason as 0 (and the impression that interrupt on Pin Change might be slower) so I use it sparingly (only one pin, but I might be wrong on that). Nevertheless, I am moving away from that type of interrupt by using a Pro Micro. 2. Step and direction are inputs connected to your stepper controller (A Mega running Marlin in my case). It might be good to add a "disable pulse input" command in case you do not use it. 3. No use of led at the moment. Silly comment residue :-( 4. I could use an XOR gate to join them together and use a single interrupt, but that will require a pcb, I opted for keeping it simpler. So I have two signals I want to process every time one of them changes, that could be done with two interrupts. BUT ... I moved to the Pro Micro to have more external interrupts and later changed to a magnetic encoder and suddenly I do not need any interrupt to process the encoder :-)
arnav chopta
arnav chopta
over 8 years
Misan, Thank You for gread piece of code! Some questions are appering thru work with: 0. Why You use two different interrupts systems: INT0 on PD2 and PCINT0 on PD8 instead INT0 and INT1 only (if You really need two of them)? 1. Why You divide inputs and outputs between two uC ports? Encoder A is PD2, encoder B is PC0, Step/Dir pins are also with gap between them. Is not so clear for somebody who wants to use free pins. 2. Step/Dir inputs are floating without connected externall encoder/solver. Finally target floats... I was commenting line with interrupt1 enable to avoid this. 3. What means comment "// will store last time LED was updated"? Some info from past/unused feature in code? 4. Finally, why You read A and B signals separatelly instead using INT0 to note/read change on channel A and then check state/change on channel B. Less interrupts means less jumps in code. Regards,
Steven Brace
Steven Brace
over 8 years
Oops didn't see that I had already mentioned my project before since I replied straight from the email notification! Too little coffee.
Steven Brace
Steven Brace
over 8 years
I will give it a go when I next have some time. I am currently working on a custom board with an atmega328, a dc motor driver and also an avago encoder counter, trying to make it as small as I can. It will probably use a slight modifcation of your code. Should be able to get everything needed to control 2 axes on a board smaller than an arduino uno. I'm planning to open source it for anyone interested. I'm actually making it for my pan and tilt camera motion control system, not for a 3d printer though. Information on that here: http://stevenbrace.co.uk/2015/06/new-diy-3-axis-motion-control-for-time-lapse/
misan
misan
over 8 years
Hi Janis, Thanks for chiming in. I kind of discarded the end-of-line cause as Steven claimed that at least one command worked for him. I am not sure what is going on in his case. Maybe Steven will tell us once he figures it out.
Janis Ziemelis
Janis Ziemelis
over 8 years
Steven, if you're using Arduino IDE serial monitor, you might have a setting next to the bitrate set at "No line ending", change it to "Both NL & CR", the code is waiting for those symbols it can go to the next operation, and if they don't arrive, it just keeps on waiting, there is nothing wrong with the code itself, you'll still, as misan said, have to deal with the direct access macros though
misan
misan
over 8 years
Hi Steven, Please bear in mind that Mega has a different processor and pinout. I have used some direct access macros to IO ports (to speed up code) that will need to be rewritten for a different processor. It can be done but if your are going with a 328 you can skip that though. The fact that you send a command and only get one response suggests the program gets blocked somewhere but, again, it has to be due to some non-portable instruction. If you figure it out, please report to this list so other people can learn about it. A command should be getting you position reports twice a second (I reckon). That small PCB may be very interesting for some folks that prefer not to fiddle with wires. But I would consider the 32u4 as it has more external interrupts and a embedded USB port (again some rewrite is needed).
Steven Brace
Steven Brace
over 8 years
Having some problems getting this working. I am using an Arduino Mega. I have only hooked up the encoder and am using ? to check the encoder position. When viewing the serial monitor I can send the ? command, and recieve a response but after that I cannot send another command and no more information is sent back over serial no matter how many requests I make. If I reset and try using the A command, I get no response at all. Any ideas what is going on? I am working on making a PCB with a small surface mount atmega328 and a dual motor driver to miniaturise and make this a little more permanent for my motion controlled camera rig, should be epic! Thanks!
engin
engin
over 8 years
hi scott, yes me too dont knew what u said that system..i use easy and shortcut ways for learn ...if u can explain this system maybe will be more better and who learn will be glad...
engin
engin
over 8 years
hi misan how can i use? pls can u give example? i want use rotary switch with this way i will send motor shaft to different target with push per different button...
misan
misan
over 8 years
Dear Scott, I did not know I have a choice, aka I do not know what I am doing. But a link to educate myself is welcome.
misan
misan
over 8 years
Hi engin, you may use some of the spare inputs to sense the selector position and update the target variable accordingly inside the main loop
Scott Lawson
Scott Lawson
over 8 years
Why did you decide to use PID control instead of state-space control? In my experience, a proper state-space control implementation has superior performance.
engin
engin
over 8 years
Dear misan, i want distance control for linear actuator as dc servo motor..i will write distance then must run motor there distance...how can i do?
misan
misan
over 8 years
gnd should always be common to all circuits involved. Please note you can use the serial port to debug what is happening as ? command will tell you current position, target and output. if output is zero and motor moves you have an electric problem.
engin
engin
over 8 years
i connect l298 gnd to ardiuno gnd then motor start turn very fast then i make down vcc voltage from 12 v to 6 volt coz when very fast encoder cant read pulse....
misan
misan
over 8 years
target only should change with X command or with pulses in the STEP input. If it changes when you move the encoder there is a wiring problem.
engin
engin
over 8 years
encoder connect motor shaft..i reading from monitor 0 position..when i turn shaft with myhand target value change so not stop in zero...how can i set target must be stay 0...when i send pulse then must be change value...how can i do?
misan
misan
over 8 years
Usage in here explains it all: https://github.com/misan/dcservo same as help output. You need to send a command with the new value, for example P10 will set the new P gain to 10.
misan
misan
over 8 years
Rise P gain
engin
engin
over 8 years
motor very slow move for run to target...how can i make strong move?
misan
misan
over 8 years
It seems you already guessed the answer: different motors have different behaviour so you need to adapt PID values so you always obtain the response you want: you can change the values on the fly using the serial monitor. H command will list you the available commands (latest github code only).
engin
engin
over 8 years
hello misan, today i change motor with bursh motor..motor now aslike weak and hard came to position...one day ago i use brushless motor but more stable worked..why? how can i change pid settings?
engin
engin
over 8 years
yeah i saw but i thinking dc motor more cheap from ac servo...i'll try and test that also nexttime and share
misan
misan
over 8 years
I do not, but Mihai does: http://www.cnczone.com/forums/open-source-controller-boards/253254-software.html
engin
engin
over 8 years
i will take video and share when full finish myproject, i'll use in mynew cnc this driver...do u have ac servo project?
misan
misan
over 8 years
You're welcome. Let us know how it works with that beast.
engin
engin
over 8 years
i will test with 40 amper 30 volt dc motor wednesday...motor very hard stop and start..must be softy and ramp stop and start..i cant test with pul and direction coz i dont have tools for that but i'll buy tomorrow for test with pul and dir...again thanks with this ways to u for urhelp...
misan
misan
over 8 years
Great, remember that even if it works ok, you still need to set the PID values properly for your system to obtain the best performance possible.
misan
misan
over 8 years
Some people reported trouble with high-speed motors (or high-resolution encoders). If you can, use a lower voltage for the motor supply (so it will turn slower even when max speed is demanded).
misan
misan
over 8 years
Great, now observe the value of output, that depending on which direction you move the shaft will quickly turn 255 or -255 (that's the control trying to compensate for the position error induced). That should steer the motor to follow the reference and to stop there once reached. If motor polarity is inverted then it will never stop.
engin
engin
over 8 years
dc motor very fast turning also encoder i controll with hand so i cant make balance..i read from serial monitor, encoder working
misan
misan
over 8 years
Turning non-stop in both ways suggest me encoder input is not working as expected. If you use the latest version from github you can diagnose the encoder from the serial monitor. No need for the motor to be powered while you do that, just the encoder.
engin
engin
over 8 years
i use servostrap v02 for ardiuno...i connect all also i look what u post photo..
engin
engin
over 8 years
ı change motor cables so start nonstop turn to other side...ardiuno got 5v from laptop with usb cable...aiso 5volt and gnd wire go to encoder from ardiuno ports...uno and l98 motor driver gnd so i connect but still same
misan
misan
over 8 years
Hi engin, First thing is to check the encoder input, scroll down a bit to the previous conversation with Minh Pham. But right of the bat, just swap the motor wires and try again,
engin
engin
over 8 years
i use 1000 pulse encoder...
engin
engin
over 8 years
hello misan, Firstly thanks for share this project...i make same all when i didnt connect dir and pul wire then i tested motor nonstop turning..whats my wrong? i saw l298 gnd connect to where on ardiuno uno?
misan
misan
over 8 years
You need to download Processing IDE https://processing.org/download/?processing
Minh Pham
Minh Pham
over 8 years
Thank you and merry christmas!!! How do you use the PIDTunning tool in windows??
misan
misan
over 8 years
Congratulations Minh Pham! Indeed, all grounds need to be connected together even though motor is powered at 12V or more and Arduino works at 5V only.
Minh Pham
Minh Pham
over 8 years
Finally it work. COMMON GROUND............Have to plug ground from the L298N to arduino and 12v power supply ground
Minh Pham
Minh Pham
over 8 years
Ok I measure the volt output of the motor it's reading only 1.9v when running the script.
misan
misan
over 8 years
Yes, they are, but please remember to set the enable the bridge (in my card is done with a jumper)
Minh Pham
Minh Pham
over 8 years
Pin 9 and 10 go to IN1 and IN2 on the L298N right??
misan
misan
over 8 years
Yes that means encoder is working (as position has changed). The output is also reacting to that change so you should see a change in the motor control outputs.
Minh Pham
Minh Pham
over 8 years
Position=0 PID_output=0.00 Target=0.00 Position=420 PID_output=-255.00 Target=0.00 first is when I start and second is when I move the motor by hand, so my encoder is working right?
misan
misan
over 8 years
Bad checksum is not a problem (unless you have previously saved any PID value). Please note you need to add an end-of-line after any command, without it no answer is produced.
Minh Pham
Minh Pham
over 8 years
When I check in serial monitor at the end it say bad checksum and when I try to send command there nothing.
misan
misan
over 8 years
Hi Minh Pham, If you use the latest code from github you can check whether the encoder inputs are working or not (the "?" command will read current position). Once you know position readings are correct you can move on to the next step. PID tuning is really important, but you start just setting value for P, higher values will mean a strong control action (more sensitivity). If encoder input is not working it is possible you have no output no matter what you do.
Minh Pham
Minh Pham
over 8 years
Hi Misan, I cant make my my motor salvage from a printer to work. I check the motor it's good, I check the optical encoder it's good, check the output signal of the ramp with an oscilloscope it give signal but when i check the output signal from arduino to l298n motor shield ( pin 9 and 10) with the oscilloscope seem like there nothing. I dont know what's wrong could you help me?? Btw does PID tuning really important for it to run?? Because I didnt know how to setup and tuning it.
misan
misan
over 8 years
Thanks @neirons.
neirons
neirons
over 8 years
After Your suggestion, PID tuner tool works as expected. Thank you.
misan
misan
over 8 years
Try adding the line import java.util.*; at the top of the code.
neirons
neirons
over 8 years
My qestion is about this line in your PidTunningTool: Scanner sc = new Scanner(s); When i started tool from processing, there was error that Scanner is not found. Is this some external library or something else?
misan
misan
over 8 years
Hi, Encoders I use are digital quadrature signals.
-=paddy=-
-=paddy=-
over 8 years
Hey Misan, what is the raw output signal of the encoder. square or sinusoidal? would be nice to try interpolation if the latter is the case!
misan
misan
over 8 years
Then it might be picking up noise on the step line, you better disable that interrupt just in case while you perform your tests to be sure.
gottmoz
gottmoz
over 8 years
link to the sketch I'm using.. https://drive.google.com/file/d/0B3gtQ6-WmEKnM2lmSDRjY0JoWTA/view?usp=sharing
gottmoz
gottmoz
over 8 years
No, the only thing connected to pro mini is 0tx and 1rx.. nothing else connected..
misan
misan
over 8 years
I am afraid you have connected one of the encoder outputs to the step input (pin 2)
gottmoz
gottmoz
over 8 years
Strange, serial shows no movement of encoder but motor output and target changes when i´m rotating motor shaft...
misan
misan
over 8 years
Hi Gottmoz, In my github code pins 9 & 10 are intended to power the motor PWM. Encoder can go to pins 0 & 1 of the leonardo pro micro remove pinMode(encoder0PinA, INPUT); pinMode(encoder0PinB, INPUT); pciSetup(encoder0PinB); attachInterrupt(0, encoderInt, CHANGE); // encoder pin on interrupt 0 - pin 2 attachInterrupt(1, countStep , RISING); // step input on interrupt 1 - pin 3 and replace by attachInterrupt(0,encoderInt, CHANGE); attachInterrupt(1,encoderInt, CHANGE); attachInterrupt(2, countStep, RISING); remember to connect encoder to pins 0 & 1
gottmoz
gottmoz
over 8 years
In the picture I'm using the uno only to power the encoder 5v, signals go to leonardo... I still not quite understand what I'm suposed to comment out and how to associate pin 9, 10 to encoder...
misan
misan
over 8 years
Hi Gottmoz, Oops, but looking at your picture it seems an Arduino (can't tell whether it is a UNO or a Leonardo) is the one getting the wires from the encoder. What I mentioned before is only useful if you use Leonardo-based (32U4) board. I usually comment the inputs to be used in the source code.
misan
misan
over 8 years
Hi Gottmoz, Because you are using a Pro Micro (leonardo based) you have more external interrupts available (External Interrupts: 0(RX), 1(TX), 2, 3 and 7) so that means you do not need to use the PCI stuff I use so you can just use the attachInterrupt function to associate a pin with an interrupt. You will need two of them for the encoder A&B signals (for example 0 & 1) as the Micro will use the USB for serial communication these are actually free now for other uses.
gottmoz
gottmoz
over 8 years
Link to picture of my jigg: https://drive.google.com/file/d/0B3gtQ6-WmEKnejkteHYxMU5lcUU/view?usp=sharing
gottmoz
gottmoz
over 8 years
Hello! I made a motorjigg just to try out different motors and drivers easy to se the actual movement. The problem is i´m trying to use a arduino pro micro as brain, but i won´t get any encoder readings.. I had a look att the datasheet for leonardo and believe that Encoder pins should be 9,10 instead but it won´t work... Can this be the problem?void pciSetup(byte pin) { *digitalPinToPCMSK(pin) |= bit (digitalPinToPCMSKbit(pin)); // enable pin PCIFR |= bit (digitalPinToPCICRbit(pin)); // clear any outstanding interrupt PCICR |= bit (digitalPinToPCICRbit(pin)); // enable interrupt for the group } I´m really stuck and my skills are not enough this time...
misan
misan
over 8 years
Hi Jaro Pe, Please try latest version from here: https://raw.githubusercontent.com/misan/dcservo/master/dcservo.ino
Jaro Pe
Jaro Pe
over 8 years
Hi Hey, what am I doing wrong? https://www.youtube.com/watch?v=XblU3wzSOl0 Serial console is inactive. How can this make? "Serial port prints current position and target position every second. Serial input can be used to feed a new location for the servo (no CR LF)" Thanks
misan
misan
over 8 years
Hi hqkhuong, you certainly can. Just use motors with enough torque for the job.
hqkhuong
hqkhuong
over 8 years
pls tell me, i can using this plan to control router cnc machine for woodworking Thks,
misan
misan
over 8 years
hi syntaxing, I have not used serialEvent before but it may be a better solution than mine. Thanks a lot.
syntaxing
syntaxing
over 8 years
Hey Misan, I was going through your code with the serial input capabilities. Have you tried using a SerialEvent before in the code to read the serial input? I wonder if it would work faster using this method.
misan
misan
over 8 years
Thanks David, looking forward to it.
ddv88334
ddv88334
over 8 years
Hello, I upgraded your design to split the job. I count now the step dir pulses with an additional microchip pic16f628 wich sends the desired position to the arduino by serial communication at 115200bps. And I'm able now to count the pulses easily up to 10000mm/sec with 100 pulses per mm. This to overcome the problem that the arduino nano wasn't fast enough to count the pulses from ramps simultaneous with high motor speed. When the design is finished I will share it. Grtz, David
misan
misan
over 8 years
Hi evesky, Yes, you may need to adapt some of the pins when moving to another Arduino version, but most importantly it is the pins accessed with PINB or PIND constants the ones that will be trickier (I used that to get faster access, you will need to find out which port and bit that new pin is at).
evesky2015
evesky2015
over 8 years
Hi misan, If I use your code in my Arduino2560,Should I change pins that you had defined? Thanks evesky
misan
misan
over 8 years
Hi Benson, In the github code I am using a brushed DC motor. I plan on adding some conditional code so the same could be used for brushed or brushless motors (with PWM+direction interface). Some brushless motors are controlled by two pins, one that accepts a PWM signal controls the speed and a second one controls the direction of rotation. Kind Regards, Miguel
Benson Hadlock
Benson Hadlock
over 8 years
How does that work? Thanks again Benson
Benson Hadlock
Benson Hadlock
over 8 years
Hello Misan, I see in V05 you have BLDC's. Are you using Brushless Motors in your current version? If so, are the drivers integrated in the motor or are you using a different motor driver? Thanks Benson
misan
misan
over 8 years
Hi lond, Looking great.
lond
lond
over 8 years
My new PCB arrived today, a large improvement from my prof of concept: https://lh3.googleusercontent.com/-px9oO3z_DPg/VjPdMrf1KBI/AAAAAAAAEMs/68OBBQ8703U/s800-Ic42/DSC_1692.JPG /// Marcus
misan
misan
over 8 years
Hi ddv88334, My experience so far is that encoders and motor controllers use to work at 3.3v too. But getting a $4 Maple Mini from China may take a while. But a larger PIC may do the job of the Arduino brilliantly too. I have used PID library because it was available, other than that, it should be easy to translate to other platform (I mentioned Maple Mini as it is the other one I tested it on, because of PID library and IDE compatibility).
ddv88334
ddv88334
over 8 years
Dear Misan, Thank you for your quick response. I thought the same, and had the idea like you said to change the board, but the problem with the maple board is the 3.3V. I don't like to convert all the signals to 3.3V. So I'm now trying with a microchip 12f629 taking over the pulse count and send them to the arduino via the serial port at a speed of 38400bps. It works so far when I send no more than 100 pulses, but if more than this I have troubles with the timing of my serial transmit function, because the pic12f629 has no hardware rs232 port. I'm working on it to solve this. At the moment I'm able to capture 100 pulses sent by repetier with a speed of 1000mm/sec, 100pulses/rev. I'm writing the microchip firmware in assembler. I know maybe it isn't the best solution, but my knowledge of the microchip is better than atmel(0 knowledge). I plan also to synchronise the PID calculations of the arduino's with a shared clock to archive more synchrone movements. I keep you informed of the results and if it finally works well I will share my project to all of you. Thanks,
misan
misan
over 8 years
Dear ddv88334, You're welcome. Our poor Arduino may be biting more than it can chew depending on both step pulse rate and encoder pulse rate. We may reach a point where all the time is spent in interrupt service code and PID code is not run every millisecond as expected. If that is the case you may try reducing the PID frequency myPID.SetSampleTime(10); but if that is not enough I can see two choices: either you move to faster processor (have a look at the sample code for Maple Mini, which is a 32 bit processor running at a higher clock frequency) or you try to optimize the code by using assembler code and getting rid of the calls to Arduino library functions that are built for easy of use but not for real-time performance. Still, being the step signal processed at an interrupt I find weird that you are missing steps but it may be because the pulse frequency is very high. Anyway, when you say you read the position with the serial port: is it possible that the 920 you get is the position but the target is correctly set to 1000?
misan
misan
over 8 years
Dear Benson, Please remove altogether the setting of TCCR1B as the timer will be set by the Servo library properly. With an ESC the PWM frequency is not related to the motor control switching anymore. Keep us posted on your results.
ddv88334
ddv88334
over 8 years
Dear Misan, Thank you very much for sharing this project. I experienced now a while and found that by higher pulse speeds from Repetier software the arduino can no more follow, so it is missing pulses. I have a motor with 334 pulses/rev and a 1:3 gear reductor. So to achieve some printing speed I need more speed. When I enter 100 pulses a mm in repetier and a max speed for the axis of 200mm/sec I'm already missing step pulses. I'm using an arduino nano and check the position after the repetier command with the serial interface. For example if I command to move 10 mm with 100pulse/mm I should read at the end with the serial interface position 1000.But surprisingly this is not the case. I only read about 920.
Benson Hadlock
Benson Hadlock
over 8 years
Hello Misan, That's pretty much what I thought. I just meant change TCCR1B & 0b11111000 | to 490 HZ . Its not a soothing sound on your ears!! Thanks for the reply. Benson
misan
misan
over 8 years
Hi Benson, For an ESC like that one, which was bidirectional, a single servo signal is needed and depending on its length it will turn one way or the other (or it will stop). You can use servo lib https://www.arduino.cc/en/Reference/Servo and just one pin, for example pin 9. Please note that you will need to change PID.setOutput(0,180) (sorry I failed to follow the 0x03 thing).
Benson Hadlock
Benson Hadlock
over 8 years
Hello Misan, If I wanted to try using the ESC I pasted the link about. Would I just change the timer on pins 9 and 10 to 0x03 to get the 1-2ms pulse width? Thanks Benson
trenton carr
trenton carr
over 8 years
Thanks, I'll keep an eye out.
misan
misan
over 8 years
Thanks Trenton, It's been mentioned before. This is still a work in progress. I printed a couple of sample parts and I rebuilt the printer with the stock motors. There was not a significant difference but I was expecting to get a better result with the DC motors. What it is missing, in my opinion is speed control in the feedback loop, which is in the pipeline. Till then the coast phase of each motion is a bit rough (speed jitter).
trenton carr
trenton carr
over 8 years
Hi misan This is great stuff,well done. Do you have some printed samples to show print quality please?
misan
misan
over 8 years
Hi evesky, In your stepper one step turns into a certain angular motion (i.e. if you use 16x microstepping on a 200steps/revolution stepper one step is 0.1125 degrees). When you have encoder, it gives a number of pulses per revolution too. Dividing 360 by the number of pulses you get the angle/pulse (ie a 448 CPR encoder using 4x pulse decoding you get 1792 counts per revolution, so 360/1792 gives you 0,2001 degrees/count. Now lets us assume the examples above match your machine. Then you will need to reduce your steps/mm (M92 command if EEPROM is enabled) by a 56.22% (as 0.1125/0.2001 = 0.5622). If your original steps/mm was 80 (as in many printers) the new value would be 44.97steps/mmm, though now there are no steps but encoder counts, so you may say counts/mm instead).
evesky2015
evesky2015
over 8 years
Hi misan, Are there some mathematical relation about step(from marlin )and count(from encoder)? Thanks evesky
misan
misan
over 8 years
Wow Benson, that really looks cool (but expensive). Thanks for sharing it.
Benson Hadlock
Benson Hadlock
over 8 years
This could be a solution for driving Brushless Gimbal Motors. It is expensive though and a little weird form factor for the aaplication. http://www.operativerc.com/products-bgmc.html
misan
misan
over 8 years
You can use X command to send destination through the serial port. For example X1000 will send the motor to location 1000. No need to jse step or dir pins for that, just the serial comm port.
evesky2015
evesky2015
over 8 years
Hi misan, If do I just want to take text for the code without STEP pin and DIR pin , how should I do? Thanks, evesky
misan
misan
over 8 years
Do you mean the one on github? They are in the comments sections: A0 pin is direction and D3 is step.
evesky2015
evesky2015
over 8 years
Hi misan, I download the latest version of the firmware,but I couldn't find the definition of STEP pin and DIR pin. Could you tell me the reason? Thanks, evesky
Benson Hadlock
Benson Hadlock
over 8 years
Video testing with Graphic Display. https://youtu.be/_FKyZh2Dh3A
misan
misan
over 8 years
Congrats Benson!! If you upload a video let us know.
Benson Hadlock
Benson Hadlock
over 8 years
Hello Misan, It's working now! Keep up the good work. Thank you. Benson
misan
misan
over 8 years
Hi Benson, Not sure what may be wrong. I would test: 1) that the encoder works ok (the code from the github allows you to check current encoder value using command "?" ) 2) if at the beginning the motor fights your attempts to turn it by hand CW and CCW
Benson Hadlock
Benson Hadlock
over 8 years
Hello Misan, Thank you for all of your help Misan! Its working CCW but spins continuously CW. Any suggestions? Thanks again Benson
misan
misan
over 8 years
Hi Benson, These are no relevant, all set to zero would be the same.
Benson Hadlock
Benson Hadlock
over 8 years
Hello Misan, How did you determine these numbers? input=80, output=0, setpoint=180; Thanks Benson
misan
misan
over 8 years
You can have a look at the code in here https://www.arduino.cc/en/Reference/ServoWrite pwmOut can turn into something like servo.write(value); once you have set the output range of the PID from 0 to 180 (now it i goes from -255 to -255 in line myPID.SetOutputLimits(-255,255);)
gottmoz
gottmoz
over 8 years
I just started looking at the code, and added a define servo.h and i suppose that i will remove define m1 and m2? What else do i need to do in the code to use one pwm output for esc?
misan
misan
over 8 years
Please let us know about your results.
gottmoz
gottmoz
over 8 years
Ok, i will give it a shot this weekend!
misan
misan
over 8 years
... servo lobrary to replace pwmOut in my code. That should do it.
misan
misan
over 8 years
I reckon it may work but my guess is most ESC are tuned for speed. I do not know how well they will work here. Also, I assume your ESC can turn backwad and forward. If that is the case you should give it a try. You can use Lady Ad's
gottmoz
gottmoz
over 8 years
I think position, for a 3d printer...
misan
misan
over 8 years
Do you want to achieve a speed control or a position control?
gottmoz
gottmoz
over 8 years
Misan: But what if i would use a sensored car esc?
misan
misan
over 8 years
It would not be difficult, just changing the pwm frequency, but It will not work for a position control as the sensorless drivers do have trouble starting at low speed.
gottmoz
gottmoz
over 8 years
Would it be hard to modify servostrap output to rc pwm? If not then it would be possible to use brushless outrunner with rc car esc....
misan
misan
over 8 years
Hi Benson, The PIDAutotune linbary did not work well for me. You can google for PID manual tuning, there is plenty.
Benson Hadlock
Benson Hadlock
over 8 years
Hello Misan, Are you aware of any PID Tuning XLS Templates or Sim software that would work for Tuning the PID? Thanks Benson
misan
misan
over 8 years
Added new file to the repo that should do it without PinChangeInterrupt library (no time for testing it though).
misan
misan
over 8 years
@Benson Sorry, I realized I made a mistake as I wanted to get rid of it (as better performance can be obtained without it).
Benson Hadlock
Benson Hadlock
over 8 years
Hello Misan, Which PinChangeInt.h Version are you using? Thanks Benson
misan
misan
over 8 years
@evesky2015 Those are reading digital pins in a faster way that digitalRead() does. PINB represents all the inputs of Port B. Doing an AND (&) with a certain power of two (like 1=2^0 or 16=2^4) you can isolate certain bit values (bit0 and bit4 in this case).
evesky2015
evesky2015
over 8 years
Dear misan, There have " New = (PINB & 1 ) + ((PINB & 16) / 8); and "New2 = (PIND & 192) / 64;" in your code, I don't know about this . Could you tell me some thing ? Thanks evesky.
misan
misan
over 8 years
Hi Ben, The way I am using it, each h-bridge if the L298 is always enabled. IN1 and IN2 pints are controlled by PWM outputs. Motor stops when the position error is zero.
Benson Hadlock
Benson Hadlock
over 8 years
Sorry about misspelling name.
Benson Hadlock
Benson Hadlock
over 8 years
Thank you for the reply Musan. I asked that question because I feel I'm missing something. Do I need to wire enable pin from Ramps/ Marlin to anything? Or wire enable pin from L298 to anything? Motor just spins. Thanks again Ben
misan
misan
over 8 years
@Benson_Hadlock You can do any of the two, it will work in both cases (I once make stepper and DC motor work in sync just for fun). But I'd remove 4988 and connect to step/dir pins. You're welcome, misan.
Benson Hadlock
Benson Hadlock
over 8 years
Hello Misan, From Marlin Step / Dir, do you remove 4988 and connect directly to Step and Dir on the Board or do you hook them up to step and direct with 4988 Installed? Thanks Ben
misan
misan
over 8 years
@evesky2015 no hardware needed, it is just a look-up table for encoder increment.
evesky2015
evesky2015
over 8 years
@misan Dear misan,there have "const int QEM [16] = {0,-1,1,2,1,0,2,-1,-1,2,0,1,2,1,-1,0};" in your code ,I have no idea about it. If does it need some hardware?
misan
misan
over 8 years
@evesky2015 You can download the whole library from here https://github.com/br3ttb/Arduino-PID-Library/zipball/master I does not include an "application.h" file on it.
evesky2015
evesky2015
over 8 years
@misan Thank you very much. Would you send me the PID_v1 file? In my PID_v1 file , I found "#include "application.h" " at the PID_v1.cpp file .But I don't have the file in my library. My email:evesky324 at gmail.com Sorry to my English.
misan
misan
over 8 years
@evesky2015 It seems the library is not properly installed. Newer versions of Arduino IDE do include a menu option for library import/install. If that is your case you should use that and give it the zip file with the library you downloaded. If your IDE is too old and does not have this feature, it may be a good moment for getting a new one.
evesky2015
evesky2015
over 8 years
@vleud101 Thank you very much,I had put the PID_v1 files in my library folder.So I'm very confused.
vleud101
vleud101
over 8 years
@evesky2015 You put the "include" files in your libary folder? PID_v1.cpp is not included in the download, you need to download it separately . It was somewhere in the comments but i can't find it anymore. If i'm at home i can send you.
evesky2015
evesky2015
over 8 years
Dear misan, Here are my error . D:\Program Files (x86)\arduino-1.7.3\libraries\PID_v1\PID_v1.cpp:8:25: fatal error: application.h: No such file or directory #include "application.h" ^ compilation terminated. Then what is the problem here? Thanks
lond
lond
over 8 years
The sensor AS5040 and magnet are sampled from the manufacturer and the PCB is a own creation :) /// Marcus
misan
misan
over 8 years
Dear Marcus, That is great and looks sweet. I am about to test a similar idea with AS5600 magnetic sensor, it works well at 9000 rpm at least (though the manufacturer does not suggest such a usage). Which one are you using? Can the unit be bought online or you build it yourself? Thanks, Miguel
lond
lond
over 8 years
I replaced the optical encoder for a magnetic one and a bigger motor: https://lh3.googleusercontent.com/-5emov5Rtsjc/VhaRhW2m2nI/AAAAAAAAEH8/zcptvFckXaA/s800-Ic42/DSC_1650.JPG /// Marcus
misan
misan
almost 9 years
@shams iqbal there is nothing wrong about using DAC output if you already have the power amplfier, those who don't may find it easier and cheaper to use PWM
misan
misan
almost 9 years
@ekaggrat there is some code available for that https://www.youtube.com/watch?v=Z6OMT1fIQnU there is a link to the code in the video page
misan
misan
almost 9 years
@tandel Sorry, I was not getting notice about new messages. You can email me misan (at) upv.es
Anonymous
Anonymous
almost 9 years
i think there is something wrong with this comment box iwill try other option which is convinient to you
Anonymous
Anonymous
almost 9 years
//#define DEBUG #include <PID_v1.h> #define encoder0PinA 12 #define encoder0PinB 8 #define PWM 9 #define CWCCW 11 double kp=1,ki=0,kd=0.0; double input=0, output=0, setpoint=0; double input1=0, output1=0, setpoint1=0; PID myPID(&input, &output, &setpoint,kp,ki,kd, DIRECT); PID myPID1(&input1, &output1, &setpoint1,kp,ki,kd, DIRECT); volatile long encoder0Pos = 0; long previousMillis = 0; // will store last time LED was updated long target0=0; // destination location at any moment // destination location at any moment //for motor control ramps 1.4 bool newStep = false; bool oldStep = false; // Install Pin change interrupt for a pin, can be called multiple times void pciSetup(byte pin) { *digitalPinToPCMSK(pin) |= bit (digitalPinToPCMSKbit(pin)); // enable pin PCIFR |= bit (digitalPinToPCICRbit(pin)); // clear any outstanding interrupt PCICR |= bit (digitalPinToPCICRbit(pin)); // enable interrupt for the group } void setup() { pinMode(encoder0PinA, INPUT); digitalWrite(encoder0PinA, HIGH); pinMode(encoder0PinB, INPUT); digitalWrite(encoder0PinB, HIGH); pciSetup(encoder0PinA); pciSetup(encoder0PinB); TCCR1B = TCCR1B & 0b11111000 | 1; // set Hz PWM Serial.begin (115200); //Setup the pid myPID.SetMode(AUTOMATIC); myPID.SetSampleTime(1); myPID.SetOutputLimits(-150,150); pinMode(13,OUTPUT); digitalWrite(13,HIGH); // disable motor brake pinMode(CWCCW,OUTPUT); analogWrite(PWM,255); // step pin interrupts on rising edge attachInterrupt(0, countStep , RISING); // step0 input on interrupt 1 - pin 2 } void loop(){ input = encoder0Pos; setpoint=target0; myPID.Compute(); // interpret received data as an integer (no CR LR): provision for manual testing over the serial port //if(Serial.available()) target1=Serial.parseInt(); pwmOut(output); #ifdef DEBUG if(millis() % 2000 == 0) target0=target1=random(1000); // that was for self test with no input from main controller if( millis() % 1000 ==0 ) { Serial.print(target1); Serial.print(":"); Serial.print(" P="); Serial.print(output); Serial.print(" P1="); Serial.print(output1); Serial.print(" 0: "); Serial.print(encoder0Pos); // print out current location every second Serial.print(" 1: "); Serial.println(encoder1Pos); // print out current location every second } #endif } void pwmOut(int out) { // if(abs(out)<10) digitalWrite(13,LOW); else digitalWrite(13,HIGH); // brake, compensate dead-band if(out<0) { digitalWrite(CWCCW,HIGH);} else { digitalWrite(CWCCW, LOW); } analogWrite(PWM, 255-abs(out) ); } const int QEM [16] = {0,-1,1,2,1,0,2,-1,-1,2,0,1,2,1,-1,0}; // Quadrature Encoder Matrix static unsigned char New, Old; ISR (PCINT0_vect) // handle pin change interrupt for D8 to D13 here { Old = New; New = (PINB & 1 )+ ((PINB & 16)/8); // encoder0Pos+= QEM [Old * 4 + New]; } void countStep(){ if (PINC&B0000001) target0++;else target0--; } // pin A0 represents direction0
Anonymous
Anonymous
almost 9 years
my code was not complete i think this comment box has limitation hre i'm posting code again for one bldc instaed of two
Anonymous
Anonymous
almost 9 years
if i use arduino due for for servostrap then it can increase my brushed dc motor speed ? i am thinking that using arduino due can read encoder faster and comare input signal faster with 72mhz instead of 16mhz of arduino uno need your precious suggestion thanks in advance.and forgive me for the too much comment
Anonymous
Anonymous
almost 9 years
i have modified code for one bldc ....please correct me if i wrong: code: /* This program uses an Arduino for a closed-loop control of TWO brushless DC-motors. Motor motion is detected by a quadrature encoder. Two inputs per motor named STEP and DIR allow changing the target position. Serial port prints current position and target position every second. Serial input can be used to feed a new location for the servo (no CR LF). Pins used: please read defines and code below Please note PID gains kp, ki, kd need to be tuned to each different setup. */ //#define DEBUG #include <PID_v1.h> #define encoder0PinA 12 #define encoder0PinB 8 #define PWM 9 #define CWCCW 11 double kp=1,ki=0,kd=0.0; double input=0, output=0, setpoint=0; double input1=0, output1=0, setpoint1=0; PID myPID(&input, &output, &setpoint,kp,ki,kd, DIRECT); PID myPID1(&input1, &output1, &setpoint1,kp,ki,kd, DIRECT); volatile long encoder0Pos = 0; long previousMillis = 0; // will store last time LED was updated long target0=0; // destination location at any moment // destination location at any moment //for motor control ramps 1.4 bool newStep = false; bool oldStep = false; // Install Pin change interrupt for a pin, can be called multiple times void pciSetup(byte pin) { *digitalPinToPCMSK(pin) |= bit (digitalPinToPCMSKbit(pin)); // enable pin PCIFR |= bit (digitalPinToPCICRbit(pin)); // clear any outstanding interrupt PCICR |= bit (digitalPinToPCICRbit(pin)); // enable interrupt for the group } void setup() { pinMode(encoder0PinA, INPUT); digitalWrite(encoder0PinA, HIGH); pinMode(encoder0PinB, INPUT); digitalWrite(encoder0PinB, HIGH); pciSetup(encoder0PinA); pciSetup(encoder0PinB); TCCR1B = TCCR1B & 0b11111000 | 1; // set Hz PWM Serial.begin (115200); //Setup the pid myPID.SetMode(AUTOMATIC); myPID.SetSampleTime(1); myPID.SetOutputLimits(-150,150); pinMode(13,OUTPUT); digitalWrite(13,HIGH); // disable motor brake pinMode(CWCCW,OUTPUT); analogWrite(PWM,255); // step pin interrupts on rising edge attachInterrupt(0, countStep , RISING); // step0 input on interrupt 1 - pin 2 } void loop(){ input = encoder0Pos; setpoint=target0; myPID.Compute(); // interpret received data as an integer (no CR LR): provision for manual testing over the serial port //if(Serial.available()) target1=Serial.parseInt(); pwmOut(output); #ifdef DEBUG if(millis() % 2000 == 0) target0=target1=random(1000); // that was for self test with no input from main controller if( millis() % 1000 ==0 ) { Serial.print(target1); Serial.print(":"); Serial.print(" P="); Serial.print(output); Serial.print(" P1="); Serial.print(output1); Serial.print(" 0: "); Serial.print(encoder0Pos); // print out current location every second Serial.print(" 1: "); Serial.println(encoder1Pos); // print out current location every second } #endif } void pwmOut(int out) { // if(abs(out)<10) digitalWrite(13,LOW); else digitalWrite(13,HIGH); // brake, compensate dead-band if(out<0) { digitalWrite(CWCCW,HIGH);} else { digitalWrite(CWCCW, LOW); } analogWrite(PWM, 255-abs(out) ); } const int QEM [16] = {0,-1,1,2,1,0,2,-1,-1,2,0,1,2,1,-1,0}; // Quadrature Encoder Matrix static unsigned char New, Old; ISR (PCINT0_vect) // handle pin change interrupt for D8 to D13 here { Old = New; New = (PINB & 1 )+ ((PINB & 16)/8); // encoder0Pos+= QEM [Old * 4 + New]; } void countStep(){ if (PINC&B0000001) target0++;else target0--; } // pin A0 represents direction0
Anonymous
Anonymous
almost 9 years
hey instead of two i just want to use one brushless, so please i need only one bldc servo code need help. i' m begginer in programming .by the way great work and thanks for sharing your genius !!!
ekaggrat
ekaggrat
almost 9 years
also would it not be possible to modify this setup and use it with a stepper motor and a magnetic encoder . I know bldc are the best way to go but a stepper motor with a magnetic encoder is way cheaper ( nema 17 with a as5040 chip like in magservo)
ekaggrat
ekaggrat
almost 9 years
what is print quality in comparision? also how long will a brushed dc motor last on a 3d printer?
Anonymous
Anonymous
almost 9 years
and about using dac i am going to retrofit cnc machine which have working analog servo amplifiers so why spend more time to build high power pwm amplifiers
Anonymous
Anonymous
almost 9 years
dear is there any way to port your code in avr studio and use it with atxmega controller since the starting i am not familiar with arduino platform
misan
misan
almost 9 years
Hi shams_iqbal, Using atxmega seems a way up: you can run motors at higher rpms if you can handle faster response to encoder inputs. Using a DAC for the output may be tricky: it can work as far as you have a linear power amplifier but those are inefficient in the use of power. PWM will usually be a better choice as less power will be wasted. I focused on Arduino and Maple Mini as two low cost choices for low and medium computing power.
Anonymous
Anonymous
almost 9 years
hi did you had tried atxmega controller for same purpose as atxmega controller support hardwire quadrature decoding option and up to three encoder can be connected with one atxmega microcontroller this one runs faster how about to add dac on output instead of pwm if using atxmega controller this have built in dac to control analog servo drives can you plz guide me to porting out your code on atxmega controller regards
misan
misan
almost 9 years
<p>Hi <a rel="nofollow" target="_blank" href="/users/pamalofeev" class="mentioned-user">@pamalofeev</a>&nbsp;. Thanks for the link. That project seems to be better thought out and better documented too :-) I do think a joint velocity+position control is a better choice.</p>
pamalofeev
pamalofeev
almost 9 years
<p>Good job! <br></p><p>Here <a href="http://elm-chan.org/works/smc/report_e.html" target="_blank" rel="nofollow">http://elm-chan.org/works/smc/report_e.html</a> described DC motor controller for Attigny software on the assembler. I think it can be ported to atmega328, but you may have to replace quartz from 16 to 20 MHz. In Russia, some use and significantly improved a controller in their hobby-cnc.<br></p>Sorry for my English
misan
misan
almost 9 years
<p><a rel="nofollow" target="_blank" href="/users/lond" class="mentioned-user">@lond</a>&nbsp; If you want you can use three of the analog inputs so each one will act upon Kd, Ki &amp; Kp values by means of three potentiometers. This way you could manually tune the values while PID is working.&nbsp;</p><p><br>I did not have any success with autotuning.&nbsp;</p>
lond
lond
almost 9 years
<p>Hi! I have a oscillating movement in my 3D-printer. Is there a easy way tune the PID setting? Autotune or analog input?</p><p>/// Marcus</p>
misan
misan
about 9 years
<p><a rel="nofollow" target="_blank" href="/users/lond" class="mentioned-user">@lond</a>&nbsp; That is expected. If you do not want that you need to set new encoderPos and target location to the value of your choice once enable gets back to 0 ... or you do that when it gets to 1 and disable the interrupts meanwhile so no new encoder counts will happen. But still you need a way to get back to normal (re-enabling interrupts).</p>
lond
lond
about 9 years
<p>If I put your code in the PWM-loop the motors snaps back in the old position when I activate the drivers.</p><p>/// Marcus</p>
misan
misan
about 9 years
<p><a rel="nofollow" target="_blank" href="/users/lond" class="mentioned-user">@lond</a>&nbsp; forget the main loop. </p><p>add this as the first line of pwmOut</p><p>if( ((PINB &gt;&gt;1) &amp; 1) == 1 ) {digitalWrite(M1,LOW); digitalWrite(M2,LOW); return; }</p>
lond
lond
about 9 years
<p>I tried to put this code in the main loop:</p><p>&nbsp; &nbsp; while ((PINB &amp; (1&lt;&lt;PB1)) == 1) {<br>&nbsp; &nbsp; &nbsp; &nbsp; noInterrupts();<br>&nbsp; &nbsp; &nbsp; &nbsp; analogWrite(M1,0);<br>&nbsp; &nbsp; &nbsp; &nbsp; analogWrite(M2,0);<br>&nbsp; &nbsp; &nbsp; &nbsp; interrupts();<br>&nbsp; &nbsp; }<br></p><p>But i can't get it to work. My EN-pin is pin 9.</p><p>I'm a PICbasic guy, so I probably did something wrong :)</p><p><br></p><p>/// Marcus</p>
misan
misan
about 9 years
<p><a rel="nofollow" target="_blank" href="/users/lond" class="mentioned-user">@lond</a>&nbsp; Now that I think about it for a second time, you can do it more easily just by adding a condition to the pmwOut function. If /enable input equals one then just set M1 and M2 to zero and exit, otherwise do the regular processing. No need to change the way PWM is sent.&nbsp;</p>
misan
misan
about 9 years
<p><a rel="nofollow" target="_blank" href="/users/lond" class="mentioned-user">@lond</a>&nbsp; Looking good man!&nbsp;</p><p>What you ask is a pending task. It can be done easily but I haven't done it yet in my code.</p><p>How to do it? Instead of using PWM on pins IN1 and IN2, PWM would only act on L298 ENABLE pin. If PWM is set to 0 that will mean driver output disable. Pins IN1 and IN2 would need to be controlled in a way that they are always oposite logic level, one way will be forward direction the other backwards.</p><p>Of course you will need a new input pint that will do the /ENABLE action (active low if you want to be pololu compatible). So when this pin==1 you stop the PID loop and force PWM output to 0.</p><p>Feel free to submit a link to your code if you implement this so other people can use it too.</p>
lond
lond
about 9 years
<p>My 3D-printer is almost done :)</p><p><a href="https://lh3.googleusercontent.com/-rI7CDYx3gfI/VX3dGgCV8dI/AAAAAAAADkc/pfzS25yHzjs/s512/DSC_1438.JPG" target="_blank" rel="nofollow">https://lh3.googleusercontent.com/-rI7CDYx3gfI/VX3dGgCV8dI/AAAAAAAADkc/pfzS25yHzjs/s512/DSC_1438.JPG</a></p><p><a href="https://lh3.googleusercontent.com/-lNuidNu4Oo8/VVN2pDd4MNI/AAAAAAAADb0/oSEzyzJB-B0/s512/DSC_1383.JPG" target="_blank" rel="nofollow">https://lh3.googleusercontent.com/-lNuidNu4Oo8/VVN2pDd4MNI/AAAAAAAADb0/oSEzyzJB-B0/s512/DSC_1383.JPG</a></p><p><br></p><p>Is it possible to deactivate the driver via a input pin as motor disable on a stepper-motor driver?</p><p><br></p><p>/// Marcus</p>
ronny441
ronny441
about 9 years
<p>oups --'.. how i hadn't got this, i thought i understood all the code but it seems not :D</p><p>thank you very much bro for the code and especially for your help :)&nbsp;</p>
misan
misan
about 9 years
<p><a rel="nofollow" target="_blank" href="/users/ronny441" class="mentioned-user">@ronny441</a>&nbsp; if motor is wired backwards then the it will turn full speed forever. You can swap the motor wires or do a software change, like pwmOut(-output); instead of pwmOut(output);</p><p>The reason that thing happens is that when polarity is wrong, each control action makes the motor to move further away from the target location instead of getting closer to it.</p>
ronny441
ronny441
about 9 years
<p>that's exactly what i did and it worked for me 5/5 <br><br>Thank you bro&nbsp;</p><p><br></p><p>but there's something i can't understand !!!! whene i change the polarity of my motor ( from the output channel of my motor card) the motor stay turning on one direction and don't stop !!! wired thing it happens just when i inverse the polarity, otherwise the motor turn and hold the desired position. any way it's not very important for me i can handle with it but just i ask because i can't understand what happen !!!!!&nbsp;</p>
misan
misan
about 9 years
<p>There are other choices, of course, but involve to assign one additional output per motor to to change the PWM output function, so instead of having PWM on both IN2 and IN1 inputs you apply it just to ENA and use two digital outputs to configure IN2 and IN1 so motor turns one direction or another. Nothing difficult but more involved than the solution I suggested (however, it may be better in the long run, specially if you plan to control two motors with one Arduino, as that way you can use one PWM output per motor, simpler).</p>
ronny441
ronny441
about 9 years
<p>thank you for your reply bro ...</p><p>well i like your idea.. &nbsp;so you assume that there is no software solution for this ? kind controlling 2 output pin instead of 1 ?&nbsp;</p>
misan
misan
about 9 years
<p>That board is totally compatible, you just need to force the ENA pin (connect it to +5V) and use the two PWM outputs M1 &amp; M2 to connect to IN1 &amp; IN2 inputs of your board.</p>
ronny441
ronny441
about 9 years
<p>Hello Misan, <br>at first i want to thank you for sharing this project, <br>I tried to use your code and do a little change to make it compatible with a full Dual H-Bridge&nbsp;but unfortunately i didn't &nbsp;succeed .. i used this one <br><a rel="nofollow" target="_blank" href="http://www.geeetech.com/wiki/index.php/L298N_Motor_Driver_Board">http://www.geeetech.com/wiki/index.php/L298N_Motor_Driver_Board</a><br>so&nbsp;to&nbsp;control&nbsp;the&nbsp;motor&nbsp;we must&nbsp;use&nbsp;3&nbsp;PINs ,&nbsp;2&nbsp;for&nbsp;direction&nbsp;and&nbsp;1&nbsp;for&nbsp;PWM<br></p><p>my&nbsp;question&nbsp;is&nbsp;do you&nbsp;have&nbsp;any&nbsp;idea&nbsp;how&nbsp;to modify your&nbsp;code&nbsp;to&nbsp;a&nbsp;make&nbsp;it&nbsp;compatible&nbsp;with this&nbsp;driver ,&nbsp;i&nbsp;mean&nbsp;i have&nbsp;to&nbsp;use&nbsp;2 different&nbsp;PIN&nbsp;to&nbsp;control&nbsp;the CW&nbsp;and&nbsp;CCW&nbsp;direction.<br></p><p><br></p><p>thank's&nbsp;:)&nbsp;</p>
misan
misan
about 9 years
<p><a rel="nofollow" target="_blank" href="/users/vleud101" class="mentioned-user">@vleud101</a>&nbsp; yes, here is the proof: <a rel="nofollow" target="_blank" href="https://www.youtube.com/watch?v=Uq0IWYMi8cI">https://www.youtube.com/watch?v=Uq0IWYMi8cI</a>&nbsp;the&nbsp;only&nbsp;catch&nbsp;is&nbsp;that&nbsp;I&nbsp;used&nbsp;motors&nbsp;with&nbsp;fewer&nbsp;lines&nbsp;in their&nbsp;encoder and&nbsp;built-in&nbsp;driver electronics&nbsp;(so I&nbsp;have&nbsp;fewer boards&nbsp;to&nbsp;wire).</p>
vleud101
vleud101
about 9 years
<p>Are there already some tests with uno and 2 encoders?&nbsp;</p>
misan
misan
about 9 years
<p><a rel="nofollow" target="_blank" href="/users/psclkhoury" class="mentioned-user">@psclkhoury</a>&nbsp; In the case of that motor I was using it had a built-in control electronics where HIGH = 0 PWM and LOW = 100% PWM. If your motor works as usual, you will do use just abs(out), that means 0% = LOW and 100% = HIGH.</p>
psclkhoury
psclkhoury
about 9 years
<p><a rel="nofollow" target="_blank" href="/users/misan" class="mentioned-user">@misan</a>&nbsp; Okay this is, probably, my last question. In pwmOut why are you giving a duty cycle of 255 - abs(out) and not just abs(out)?</p><p>Sorry for bothering</p><p>Thanks&nbsp;</p>
misan
misan
about 9 years
<p><a rel="nofollow" target="_blank" href="/users/psclkhoury" class="mentioned-user">@psclkhoury</a>&nbsp; I am pushing code as I get something working with not much cleanup. I am sorry newStep and oldStep variables have you wondering (they serve no purpose and can be removed). &nbsp;QEM is a quadrature encoder fine state machine that reacts to changes on any of the two edges of the encoder signals and updates the position count accordingly. Not my code but works beautifully (it came from here <a rel="nofollow" target="_blank" href="http://letsmakerobots.com/content/how-use-quadrature-encoder">http://letsmakerobots.com/content/how-use-quadrature-encoder</a>&nbsp;)<br>ISR is an interrupt service routine (the ones I use are associated with pin changes on input pins, there are two as changes on each port pins trigger a different interrupt).&nbsp;</p><p>You&nbsp;are&nbsp;welcome.</p>
psclkhoury
psclkhoury
about 9 years
<p><a rel="nofollow" target="_blank" href="/users/misan" class="mentioned-user">@misan</a>&nbsp; Hey sorry I'm asking a lot of questions. In the code there are two variables newStep and oldStep that you never seem to use, what are their purpose? And at the end I didn't quite get the use of QEM and the ISR (old, new, encoderPos). If you don't mind explaining I'll be greatfull.</p><p>Thanks</p>
misan
misan
about 9 years
<p><a rel="nofollow" target="_blank" href="/users/psclkhoury" class="mentioned-user">@psclkhoury</a>&nbsp; this setup has to be calibrated as any stepper motor. The number of ticks/revolution has to be properly configured into your firmware. Axis should stay synchronized as pulses are sent this way. No changes are needed.</p>
psclkhoury
psclkhoury
about 9 years
<p><a rel="nofollow" target="_blank" href="/users/misan" class="mentioned-user">@misan</a>&nbsp; So how are you converting step pulses to position of the encoder? Does the stepper and the encoder have the same number of "ticks" per revolution?</p><p>And should I change anything in the speed and acceleration settings in the firmware to synchronize x axis and y axis?</p><p>Thanks</p>
vleud101
vleud101
about 9 years
<p>AI ok, then i got other problems. Because i did that already. Tomorrow ill measure the step output from the ramps. Ill also tried the sprinter firmware (doesnt need so much pre requiments) but also no luck.&nbsp;</p>
misan
misan
about 9 years
<p><a rel="nofollow" target="_blank" href="/users/vleud101" class="mentioned-user">@vleud101</a>&nbsp; Marlin will not allow movements if the temperature sensor readings are outside the MINTEMP and MAXTEMP values on Configuration.h. If one if these error conditions is met a message will appear on the serial port &nbsp;saying so (on the host software). I usually set TEMP_SENSOR_0 to 0 to disable sensor input in Configuration.h and that should be it.&nbsp;</p>
vleud101
vleud101
about 9 years
<p>Misan,<br><br>I connected the uno to my RAMP (X-as). When i run the Ramps test software from (<a rel="nofollow" target="_blank" href="http://reprap.org/wiki/RAMPS_1.4">http://reprap.org/wiki/RAMPS_1.4</a>)&nbsp;It&nbsp;works.&nbsp;(Very&nbsp;slow,&nbsp;don't&nbsp;know&nbsp;why&nbsp;yet).&nbsp;But if&nbsp;i use the&nbsp;Marlin&nbsp;software and&nbsp;if i&nbsp;use&nbsp;host&nbsp;software&nbsp;on&nbsp;manual,&nbsp;i cant&nbsp;get&nbsp;any&nbsp;movement&nbsp;(I&nbsp;turned&nbsp;off&nbsp;the&nbsp;tempature&nbsp;sensors&nbsp;already&nbsp;in&nbsp;configuration.h).&nbsp;Do&nbsp;i&nbsp;need&nbsp;to&nbsp;short&nbsp;some&nbsp;pins&nbsp;from the&nbsp;X-as&nbsp;driver?&nbsp;Like&nbsp;SLP/Ground&nbsp;or&nbsp;something?&nbsp;</p>
misan
misan
about 9 years
<p><a rel="nofollow" target="_blank" href="/users/psclkhoury" class="mentioned-user">@psclkhoury</a>&nbsp; The step/dir interface does lack of feedback. It means the smoothieboard does not know when the step is done. &nbsp;We cannot change that. But the purpose of this software is for your DC motor to be used as if it were a stepper. That includes the smoothieboard assuming every step pulse is honored right away. You may easily add on the Arduino an output signal that goes HIGH when position error (difference between encoder position and target position) is zero and LOW otherwise. That signal you may use it for other purposes, like stopping a extruder, but that will require changes to smoothieboard firmware I cannot help you with.</p>
psclkhoury
psclkhoury
about 9 years
<p>Hey, is there a way to implement this to a smoothieboard? If I use the STEP DIR pins from the board and feed them to the arduino, how will the smoothieboard know when a step or move is finished, so that when I move the axis by hand, the extruder knows when to stop.&nbsp;</p>
vleud101
vleud101
over 9 years
<p>Ha i just where thinking to read out my PID and position. I did not understand it also do something. &nbsp;If i use the code from arduino.cc : <a rel="nofollow" target="_blank" href="http://playground.arduino.cc/Main/RotaryEncoders">http://playground.arduino.cc/Main/RotaryEncoders</a>&nbsp;Then&nbsp;my&nbsp;encoder&nbsp;really nice&nbsp;responding&nbsp;to&nbsp;it&nbsp;without&nbsp;missing&nbsp;a&nbsp;step.&nbsp;In&nbsp;your&nbsp;code i&nbsp;changed&nbsp;the&nbsp;pins&nbsp;to&nbsp;"2&nbsp;and&nbsp;3"&nbsp;because&nbsp;they&nbsp;have interrupt&nbsp;on the arduino&nbsp;uno.&nbsp;I&nbsp;don't&nbsp;need&nbsp;to&nbsp;change&nbsp;something&nbsp;else&nbsp;in your&nbsp;code&nbsp;right?&nbsp;When&nbsp;i&nbsp;change&nbsp;your&nbsp;pins.&nbsp;Or&nbsp;do&nbsp;i&nbsp;need&nbsp;to&nbsp;do&nbsp;something&nbsp;with&nbsp;the&nbsp;manipulated pins?&nbsp;</p><p><br></p><p>Sorry&nbsp;for&nbsp;spamming you,&nbsp;but&nbsp;thanks&nbsp;for&nbsp;the&nbsp;very great&nbsp;responds!</p>
misan
misan
over 9 years
<p><a rel="nofollow" target="_blank" href="/users/vleud101" class="mentioned-user">@vleud101</a>&nbsp; if it is printing is because you uncommented the #define DEBUG and then it will print a few values every second AND it will select a random destination every two seconds. But what does not look good is the last values 1:-1 do no change as the 1 is motor0 current location, if motor is moving that should change if encoder is wired properly.&nbsp;<br>For regular use you want #define DEBUG to be commented out and the motor should stay stopped till pulses are received from RAMPS.</p>
vleud101
vleud101
over 9 years
<p>Thanks for your comment, it is doing somting now! :D <br>My output from my monitor:<br></p><p>-15: P=-19.00 P1=0.00 0: 0 1: -1</p><p>-15: P=-19.00 P1=0.00 0: 0 1: -1</p><p>-15: P=-19.00 P1=0.00 0: 0 1: -1</p><p>-15: P=-19.00 P1=0.00 0: 0 1: -1</p><p>933: P=-19.00 P1=0.00 0: 0 1: -1</p><p>-40: P=-40.00 P1=0.00 0: 0 1: -1</p><p>-40: P=-40.00 P1=0.00 0: 0 1: -1</p><p>-40: P=-40.00 P1=0.00 0: 0 1: -1</p><p>298: P=-40.00 P1=0.00 0: 0 1: -1</p><p>-33: P=-34.00 P1=0.00 0: 0 1: -1</p><p>981: P=-34.00 P1=0.00 0: 0 1: -1</p><p>-2901: P=-90.00 P1=0.00 0: 0 1: -1</p><p>My axis is now just doing somting.. a little bit to + and then to minus. I didnt attach my ramp so it has to be steady right? He needs to hold he's position?&nbsp;<br><br></p><div><br></div>
misan
misan
over 9 years
<p><a rel="nofollow" target="_blank" href="/users/vleud101" class="mentioned-user">@vleud101</a>&nbsp; simpler: just change </p><p>&nbsp; myPID.SetOutputLimits(-150,150); to &nbsp; myPID.SetOutputLimits(-400,400);<br></p><p>and replace pwmOut(output); with &nbsp;&nbsp;md.setM1Speed(output);</p>
vleud101
vleud101
over 9 years
<p>Hello Misan, <br>First 1000 thanks for sharing this project! <br>I try to use your code in combination of a motorshield from pololu, but programming is not my good part.. iam more a mechanic. <br>But i try and i have a question if iam at the good way:<br><br>I use your code from servostrapv05 in combination with this shield&nbsp;and&nbsp;a&nbsp;Arduino&nbsp;UNO<br><a rel="nofollow" target="_blank" href="https://github.com/pololu/dual-vnh5019-motor-shield">https://github.com/pololu/dual-vnh5019-motor-shield</a></p><p>I&nbsp;eliminated&nbsp;the&nbsp;second servo&nbsp;because i&nbsp;first&nbsp;want to&nbsp;try&nbsp;one.&nbsp;<br></p><p>The&nbsp;shield&nbsp;uses&nbsp;md.setM1Speed(&nbsp;x&nbsp;)&nbsp;x&nbsp;= -400&nbsp;to&nbsp;400 where&nbsp;-&nbsp;is&nbsp;CW&nbsp;and&nbsp;+&nbsp;CCW&nbsp;</p><p>I know&nbsp;what&nbsp;port&nbsp;manupilation&nbsp;is,&nbsp;but&nbsp;i dont know&nbsp;how you used&nbsp;it.. the&nbsp;biggest&nbsp;problem&nbsp;is&nbsp;where i&nbsp;define&nbsp;the&nbsp;direction.&nbsp;<br></p><p><br></p><p>Code:</p><p>/*</p><p>&nbsp; &nbsp;This program uses an Arduino for a closed-loop control of TWO brushless DC-motors. </p><p>&nbsp; &nbsp;Motor motion is detected by a quadrature encoder.</p><p>&nbsp; &nbsp;Two inputs per motor named STEP and DIR allow changing the target position.</p><p>&nbsp; &nbsp;Serial port prints current position and target position every second.</p><p>&nbsp; &nbsp;Serial input can be used to feed a new location for the servo (no CR LF).</p><p>&nbsp; &nbsp;</p><p>&nbsp; &nbsp;Pins used: please read defines and code below</p><p><br></p><p>&nbsp; &nbsp;Please note PID gains kp, ki, kd need to be tuned to each different setup. </p><p>&nbsp; &nbsp;</p><p>&nbsp; </p><p>&nbsp; &nbsp;*/</p><p>//#define DEBUG</p><p>#include &lt;DualVNH5019MotorShield.h&gt;</p><p>DualVNH5019MotorShield md;</p><p>#include &lt;PID_v1.h&gt;</p><p>#define encoder0PinA &nbsp;2 //12 </p><p>#define encoder0PinB &nbsp;3 //8 </p><p>//#define encoder1PinA &nbsp;7 </p><p>//#define encoder1PinB &nbsp;6 </p><p>//#define PWM &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 9 //Using md.setM1Speed(x);</p><p>//#define PWM1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;10</p><p>bool CWCCW = false; //#define CWCCW &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</p><p>//#define CWCCW1 &nbsp; &nbsp; &nbsp; &nbsp;5 </p><p>double fac = 0;</p><p><br></p><p>double kp=1,ki=0,kd=0.0;</p><p>double input=0, output=0, setpoint=0;</p><p>double input1=0, output1=0, setpoint1=0;</p><p>PID myPID(&amp;input, &amp;output, &amp;setpoint,kp,ki,kd, DIRECT);</p><p>PID myPID1(&amp;input1, &amp;output1, &amp;setpoint1,kp,ki,kd, DIRECT);</p><p><br></p><p>volatile long encoder0Pos = 0;</p><p>volatile long encoder1Pos = 0;</p><p><br></p><p>long previousMillis = 0; &nbsp; &nbsp; &nbsp; &nbsp;// will store last time LED was updated</p><p><br></p><p>long target0=0; &nbsp;// destination location at any moment</p><p>long target1=0; &nbsp;// destination location at any moment</p><p><br></p><p>//for motor control ramps 1.4</p><p>bool newStep = false;</p><p>bool oldStep = false;</p><p><br></p><p>// Install Pin change interrupt for a pin, can be called multiple times</p><p>void pciSetup(byte pin) </p><p>{</p><p>&nbsp; &nbsp; *digitalPinToPCMSK(pin) |= bit (digitalPinToPCMSKbit(pin)); &nbsp;// enable pin</p><p>&nbsp; &nbsp; PCIFR &nbsp;|= bit (digitalPinToPCICRbit(pin)); // clear any outstanding interrupt</p><p>&nbsp; &nbsp; PCICR &nbsp;|= bit (digitalPinToPCICRbit(pin)); // enable interrupt for the group </p><p>}</p><p><br></p><p>void setup() { </p><p>&nbsp; fac = 400/255;</p><p>&nbsp; md.init();</p><p>&nbsp; pinMode(6, INPUT_PULLUP);</p><p>&nbsp; </p><p>&nbsp; pinMode(encoder0PinA, INPUT); digitalWrite(encoder0PinA, HIGH); </p><p>&nbsp; pinMode(encoder0PinB, INPUT); digitalWrite(encoder0PinB, HIGH); &nbsp;</p><p>&nbsp; pciSetup(encoder0PinA);</p><p>&nbsp; pciSetup(encoder0PinB);</p><p>&nbsp; </p><p>// &nbsp;pinMode(encoder1PinA, INPUT); digitalWrite(encoder1PinA, HIGH); </p><p>// &nbsp;pinMode(encoder1PinB, INPUT); digitalWrite(encoder1PinB, HIGH); &nbsp;</p><p>// &nbsp;pciSetup(encoder1PinA);</p><p>// &nbsp;pciSetup(encoder1PinB);</p><p>&nbsp; </p><p>&nbsp; TCCR1B = TCCR1B &amp; 0b11111000 | 1; // set &nbsp;Hz PWM</p><p>&nbsp; Serial.begin (115200);</p><p>&nbsp; //Setup the pid </p><p>&nbsp; myPID.SetMode(AUTOMATIC);</p><p>&nbsp; myPID.SetSampleTime(1);</p><p>&nbsp; myPID.SetOutputLimits(-150,150);</p><p>&nbsp; md.setM1Brake(0); //pinMode(13,OUTPUT); digitalWrite(13,HIGH); // disable motor brake</p><p>&nbsp; md.setM1Speed(400); //pinMode(CWCCW,OUTPUT); analogWrite(PWM,255);</p><p>&nbsp; </p><p>// &nbsp;myPID1.SetMode(AUTOMATIC);</p><p>// &nbsp;myPID1.SetSampleTime(1);</p><p>// &nbsp;myPID1.SetOutputLimits(-150,150);</p><p>// &nbsp;pinMode(13,OUTPUT); digitalWrite(13,HIGH); // disable motor brake</p><p>// &nbsp;pinMode(CWCCW1,OUTPUT); analogWrite(PWM1,255);</p><p>&nbsp; // step pin interrupts on rising edge</p><p>&nbsp; attachInterrupt(0, countStep &nbsp; &nbsp; &nbsp;, RISING); &nbsp;// step0 &nbsp;input on interrupt 1 - pin 2</p><p>&nbsp; attachInterrupt(1, countStep1 &nbsp; &nbsp; , RISING); &nbsp;// step1 &nbsp;input on interrupt 1 - pin 3</p><p>&nbsp; </p><p>} </p><p><br></p><p>void loop(){</p><p>&nbsp; &nbsp; input = encoder0Pos; </p><p>&nbsp; &nbsp; setpoint=target0;</p><p>&nbsp; &nbsp; input1 = encoder1Pos;</p><p>&nbsp; &nbsp; setpoint1=target1;</p><p>&nbsp; &nbsp; myPID.Compute();</p><p>&nbsp; &nbsp; myPID1.Compute();</p><p>&nbsp; &nbsp; // interpret received data as an integer (no CR LR): provision for manual testing over the serial port</p><p>&nbsp; &nbsp; if(Serial.available()) target1=Serial.parseInt();</p><p>&nbsp; &nbsp; pwmOut(output); </p><p>&nbsp; &nbsp; //pwmOut1(output1);</p><p>#ifdef DEBUG</p><p>&nbsp; &nbsp; if(millis() % 2000 == 0) target0=target1=random(1000); // that was for self test with no input from main controller</p><p><br></p><p>&nbsp; &nbsp; if( millis() % 1000 ==0 ) </p><p>&nbsp; &nbsp; {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; Serial.print(target1);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; Serial.print(":");</p><p>&nbsp; &nbsp; &nbsp; &nbsp; Serial.print(" P=");</p><p>&nbsp; &nbsp; &nbsp; &nbsp; Serial.print(output);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; Serial.print(" P1=");</p><p>&nbsp; &nbsp; &nbsp; &nbsp; Serial.print(output1);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; Serial.print(" 0: ");</p><p>&nbsp; &nbsp; &nbsp; &nbsp; Serial.print(encoder0Pos); // print out current location every second</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Serial.print(" 1: ");</p><p>&nbsp; &nbsp; &nbsp; &nbsp; Serial.println(encoder1Pos); // print out current location every second</p><p>&nbsp; &nbsp; } </p><p>#endif</p><p>}</p><p><br></p><p>void pwmOut(int out) {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //if(abs(out)&lt;10) digitalWrite(13,LOW); else digitalWrite(13,HIGH); // brake, compensate dead-band</p><p>&nbsp; &nbsp;if(out&lt;0) { CWCCW = HIGH;} &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//digitalWrite(CWCCW,HIGH);} </p><p>&nbsp; &nbsp;else { CWCCW = LOW; } &nbsp; &nbsp; &nbsp; &nbsp; //digitalWrite(CWCCW, LOW); }</p><p>&nbsp; &nbsp;md.setM1Speed(255*fac-abs(out*fac)); &nbsp;//analogWrite(PWM, 255-abs(out) );</p><p>&nbsp; }</p><p><br></p><p>//</p><p>//void pwmOut1(int out) {</p><p>// &nbsp;// if(abs(out)&lt;10) digitalWrite(13,LOW); else digitalWrite(13,HIGH); // brake, compensate dead-band</p><p>// &nbsp; if(out&lt;0) { digitalWrite(CWCCW1,HIGH);} </p><p>// &nbsp; else { digitalWrite(CWCCW1, LOW); }</p><p>// &nbsp; analogWrite(PWM1, 255-abs(out) );</p><p>// &nbsp;}</p><p>// &nbsp;</p><p>&nbsp; </p><p>const int QEM [16] = {0,-1,1,2,1,0,2,-1,-1,2,0,1,2,1,-1,0}; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Quadrature Encoder Matrix</p><p>static unsigned char New, Old;</p><p><br></p><p>&nbsp; ISR (PCINT0_vect) // handle pin change interrupt for D8 to D13 here</p><p>&nbsp;{ </p><p>&nbsp; Old = New;</p><p>&nbsp; New = (PINB &amp; 1 )+ ((PINB &amp; 16)/8); //</p><p>&nbsp; encoder0Pos+= QEM [Old * 4 + New];</p><p>}</p><p><br></p><p>static unsigned char New2, Old2;</p><p>ISR (PCINT2_vect) // handle pin change interrupt for D0 to D7 here</p><p>&nbsp;{ </p><p>&nbsp; Old2 = New2;</p><p>&nbsp; New2 = &nbsp;(PIND &amp; 192)/64; //(PIND &amp; 128 )/128 + ((PIND &amp; 64)/32); //</p><p>&nbsp; encoder1Pos+= QEM [Old2 * 4 + New2];</p><p>}</p><p><br></p><p>void countStep(){ if (PINC&amp;B0000001) target0++;else target0--; } // pin A0 represents direction0 "Input A0"</p><p><br></p><p>void countStep1(){ if (PINC&amp;B0000010) target1++;else target1--; } // pin A1 represents direction1 "Input A1"</p><p><br>Thanks for&nbsp;helping me&nbsp;out!&nbsp;(and more pp&nbsp;if&nbsp;they&nbsp;use&nbsp;this&nbsp;shield)</p>
misan
misan
over 9 years
<p><a rel="nofollow" target="_blank" href="/users/tomm" class="mentioned-user">@tomm</a>&nbsp; you're welcome :-)</p>
tomm
tomm
over 9 years
<p>Many Thanks and especially for the links provided.</p>
misan
misan
over 9 years
<p><a rel="nofollow" target="_blank" href="/users/tomm" class="mentioned-user">@tomm</a>&nbsp; servostrapv02 and on use x4 encoder count, which provides four times the number of lines as the effective resolution (which is usually better but it causes more interrupts too). The software does not need to know the resolution but if the motor is too fast and/or resolution is too high it might end losing counts (which we do not want to happen). It works for my motors but I do not think it can handle many thousands rpm with 500-line/rev encoders or more. </p><p>PinChangeIntConfig.h is no longer used as it is mentioned here <a rel="nofollow" target="_blank" href="https://code.google.com/p/arduino-pinchangeint/downloads/detail?name=pinchangeint-v1.4.zip&amp;can=2&amp;q">https://code.google.com/p/arduino-pinchangeint/downloads/detail?name=pinchangeint-v1.4.zip&amp;can=2...</a>=</p><p><br></p><p>but you can get if here if you want it <a rel="nofollow" target="_blank" href="https://github.com/Ltalionis/PinChangeInt/blob/master/PinChangeIntConfig.h">https://github.com/Ltalionis/PinChangeInt/blob/master/PinChangeIntConfig.h</a></p>
tomm
tomm
over 9 years
<p>Thank you for your response. The servostrap.ino works well after the adjustment of k parameters. The servostrapv02.ino uses a different approach to count the encoder pulses: the quadrature encoder matrix. Is it more efficient? Does this software need to know the encoder resolution? Could you please disclose the PinChangeIntConfig.h file? By the way, as a motor driver I am using the L6202, works ok.</p>
misan
misan
over 9 years
<p><a rel="nofollow" target="_blank" href="/users/tomm" class="mentioned-user">@tomm</a>&nbsp; I have been making some changes (as I learn) so now I discourage the use of that library in favor of a faster way (but less flexible one): &nbsp;<a rel="nofollow" target="_blank" href="http://playground.arduino.cc/Main/PinChangeInterrupt">http://playground.arduino.cc/Main/PinChangeInterrupt</a></p><p>However, it seems you have it working but you need to properly adjust Kp, Ki &amp; Kd for your system (PID parameters). &nbsp;If not the motor may oscillate around the set point. Usually set Ki=Kd=0 and start with Kp=0.1 to see how it goes, if oscillation stops, try higher values of Kp while the system remains stable.</p><p>Encoder resolution depends on the number of lines you have on your encoder disk (and the mode the software uses them to achieve x1 x2 or x4 the number of lines per revolution). </p>
tomm
tomm
over 9 years
<p>Servostrapv02.ino includes PinChangeIntConfig.h. It has been already mentioned, that PinChangeInt.h include file can be find in <a href="http://dl.bintray.com/greygnome/generic/pinchangeint-2.40-rc2.zip" target="_blank" rel="nofollow">http://dl.bintray.com/greygnome/generic/pinchangeint-2.40-rc2.zip</a>, but at this location there is no PinChangeIntConfig.h included. What definitions need to be done for this ...Config.h file. I am not getting any compilation errors with that include file being ignored, but my Pro Mini based hardware makes an erratic motor control with no data being displayed at serial monitor. I also could not find the definition of encoder resolution, where should I look for it? Thank you.</p>
gottmoz
gottmoz
over 9 years
<p>I am starting to get everything working, thanks misan! Now i will start to work on pota for pid tuning.. I burned my nucleo board yesterday, and now i have to wait a week för a new one...</p>
misan
misan
over 9 years
<p><a rel="nofollow" target="_blank" href="/users/Blali" class="mentioned-user">@Blali</a>&nbsp; for sure Arduino Pro mini will work. The sure bet is to use one per axis, but I am working on having two axis working off a single Pro Mini. Using a linear stripe would be better and will allow you to use a geared motor (smaller) and get rid of the backslash, but it is more difficult to get it mechanically right (unless you are repurposing an old printer carriage and have it already in place).</p>
Blali
Blali
over 9 years
@misan thank you very much for this fast answer! i will also prefer the closed loop control for x and y axis only. so i need ardurino uno for the motors ( ardurino pro mini) won´t work? you are using the encoder as motor tacho (encoder takes the turning positions of the motor). in order to get a better printing precision, wouldn´t it be better to use linear encoder stripes as used in 2d printers. this would give you a real position feedback where the build precision of the 3d printer wouldn´t be so crucial anymore.
misan
misan
over 9 years
<p><a rel="nofollow" target="_blank" href="/users/gottmoz" class="mentioned-user">@gottmoz</a>&nbsp; good idea the pot adjustment. Arduino has six analog inputs, maybe they could be used to adjust P, I and D gains. I do not know what can go wrong with your Nucleo code.</p>
misan
misan
over 9 years
<p><a rel="nofollow" target="_blank" href="/users/Blali" class="mentioned-user">@Blali</a>&nbsp; no change to Mega firmware is needed (though you will need to adjust the steps/mm value as if you have changed your stepper or pulley teeth size).</p>
misan
misan
over 9 years
<p><a rel="nofollow" target="_blank" href="/users/Blali" class="mentioned-user">@Blali</a>&nbsp; You got it right. But you can keep the RAMPS as it will allow you to control bed and hotend temperatures. But instead of pololus you will connected the step and dir pins to each motor controller. My current idea is to make just X &amp; Y axis with servos.&nbsp;</p>
Blali
Blali
over 9 years
must i change the firmware of my main ardurino board, or just the firmware of the "motor ardurinos"?
Blali
Blali
over 9 years
Do I understand this right?: i am using a ardurino mega and raps 1.4 to controll my reprap at the moment. for this project i need my ardurino mega (without ramps shield) and a ardurino uno for each axis + h bridge + motor + encoder??? or do i still need my ramps? are there some instructions?
gottmoz
gottmoz
over 9 years
<p>Tried -9999 to 9998 but that did not work at all, does not respond to any command...</p>
gottmoz
gottmoz
over 9 years
Ok, thanks!
misan
misan
over 9 years
<p><a rel="nofollow" target="_blank" href="/users/gottmoz" class="mentioned-user">@gottmoz</a>&nbsp; I guess that is due to the fact you have this line myPID.setInputLimits(0.0, 1000);</p><p><br></p><p>You need to change it for the PID to be able to accept position values beyond 1000 or below 0.</p>
gottmoz
gottmoz
over 9 years
Thanks, now its soft of working, now it works both ways, but it will only accept position commands below 1000 when i command through serial... otherwise a little bit of tuning, would be nice with pid tuning through a potentiometer and serial output of the values.....
misan
misan
over 9 years
<p><a rel="nofollow" target="_blank" href="/users/gottmoz" class="mentioned-user">@gottmoz</a>&nbsp; I think PID output limits should be -1,1 as you want a signed output (CW or CCW directions)</p>
gottmoz
gottmoz
over 9 years
<p>I already did some work at mbed.com but havent got the pid to work correctly... The pid only works in one direction...if someone would like to help at mbed.com user:gottmoz password:12131213</p>
misan
misan
over 9 years
<p><a rel="nofollow" target="_blank" href="/users/gottmoz" class="mentioned-user">@gottmoz</a>&nbsp; For that board you cannot use Arduino code (which Maple Mini is compatible with). You can use mbed.com online development environment. That rules out the use of PID library, but you should be able to easily adapt it to use this implementation of the same library for mbed system <a rel="nofollow" target="_blank" href="http://developer.mbed.org/users/aberk/code/PID/">http://developer.mbed.org/users/aberk/code/PID/</a></p>
gottmoz
gottmoz
over 9 years
Hello! i just bought a stm32f411re nucleo board and tried to upload your software made for maple mini, but it won't work, SerialUSB.parseint.... is the problem.. Any thoughts of an solution? Im thinking about making a shield for the nucleoboard that drives 4 servos... Any help is appreciated!
misan
misan
over 9 years
<p><a rel="nofollow" target="_blank" href="/users/Leadnuts" class="mentioned-user">@Leadnuts</a>&nbsp; You do not need extra outputs but additional inputs (two inputs per encoder). Trouble is that the pulses in these inputs are time-critical, so if you miss any edge your count won't be correct. Alternatively, you can have a slave Arduino to process the encoder's signals. This way you could only query it from the main processor (Arduino Mega?) ends one movement to double check all axis are ok (and if not, a corrective motion can be scheduled). You could use one of the unused serial ports on Arduino Mega for such interface. It is a bit far fetched but it seems it would work.</p><p>That approach, however, is not checking every step of the motor so the corrective action may happen too late ... but it is the price to keep it simple.&nbsp;</p>
Leadnuts
Leadnuts
over 9 years
<p>Any clue of where &nbsp;I could look to see how to do the control loop for correctional pulses? &nbsp;I am using the SD8825 on a Azteeg X3 controller.. I'm guessing I would have to find some customized code to have them work together, enabling them through the "Expansion pins" since their aren't any feedback pins on the stepper drives.</p>
misan
misan
over 9 years
<p><a rel="nofollow" target="_blank" href="/users/Leadnuts" class="mentioned-user">@Leadnuts</a>&nbsp; Of course you can use encoders with steppers. But if you do there are two ways: one, use the stepper as a regular AC motor (with a sin/cos drive signals) and the encoder as the position feedback. Or you can use the stepper as it is, with a conventional microstepping driver and later perform the control loop, providing additional pulses if target position is not reached due to missed steps.&nbsp;</p>
misan
misan
over 9 years
<p><a rel="nofollow" target="_blank" href="/users/Ritterchen" class="mentioned-user">@Ritterchen</a>&nbsp; If you use a quadrature encoder the direction is provided by the two signals. The encoder that you link can do the work. Arduino may be short of CPU time if handling several motors.</p>
Leadnuts
Leadnuts
over 9 years
<p>neat project. &nbsp;Is it possible to use the encoders with steppers, or just the DC motors? I have a few tiny 5000ppr hollow shaft encoders that can just slip on the motor shaft between the pulleys and motor flange, I was thinking it would be neat to use them...&nbsp;</p>
Ritterchen
Ritterchen
over 9 years
<p>Hello together, some months ago I also started to work on a simple low-power servo system. Could be also interesting for small hobby cnc-machines up to 0,5Nm if you use proper power supplys.<br>I set up a test system with an old printer-motor and a linear encoder strip which worked fine. Due I'm not so talented in programming my code was a bit messy :D<br>How did you solved the direction detection? I thought about this situation the carriage is at one position and by some reason it can move foreward/backward just 1 count. But this count you need for the detection, right? So it reduces the resolution to 50%.<br>Was there a mistake in my thoughts?<br><br>I also found this on ebay: <a rel="nofollow" target="_blank" href="http://www.ebay.com/itm/191168670515?_trksid=p2060778.m1438.l2649&amp;ssPageName=STRK%3AMEBIDX%3AIT">http://www.ebay.com/itm/191168670515?_trksid=p2060778.m1438.l2649&amp;ssPageName=STRK%3AMEBIDX%3AIT</a><br>Not tested but looks interesting too - you need coupling for your motor then.<br>I&nbsp;will&nbsp;test&nbsp;your&nbsp;code&nbsp;with&nbsp;my&nbsp;old&nbsp;setup&nbsp;soon&nbsp;and&nbsp;reply for&nbsp;the&nbsp;results&nbsp;here.<br></p><p>Could&nbsp;it&nbsp;be&nbsp;interesting&nbsp;to&nbsp;use&nbsp;the&nbsp;Arduino Due&nbsp;for&nbsp;the&nbsp;signal&nbsp;processing&nbsp;of&nbsp;3-4 Motor-Encoders?</p>
misan
misan
over 9 years
<p><a rel="nofollow" target="_blank" href="/users/GrandGibier" class="mentioned-user">@GrandGibier</a>&nbsp; Congrats! You're welcome.</p>
GrandGibier
GrandGibier
over 9 years
<p>Changed PID values, it works fine... <br></p><p>Thanks a lot for your help</p>
misan
misan
over 9 years
<p><a rel="nofollow" target="_blank" href="/users/GrandGibier" class="mentioned-user">@GrandGibier</a>&nbsp; But even when you remove the debug code, please note the PID needs to be customized to your motor. That means values Kp, Ki, and Kd have to be adjusted. Without the proper values motor may not stop and can be running back and forth all the time.</p>
misan
misan
over 9 years
<p><a rel="nofollow" target="_blank" href="/users/GrandGibier" class="mentioned-user">@GrandGibier</a>&nbsp; Good.</p><p>Please note the debug code I mentioned before that wrote to the serial port needs to be removed. A delay in the loop will make it unstable. Do you still have it?</p>
GrandGibier
GrandGibier
over 9 years
I re-started from scratch and redo the wiring with the Arduino Uno... Now the encoder works : steps increase when rotating CCW and decrease when rotating CW. Then I finished the wiring... The motor rotation is erractic, it oscillates CW/CCW/CW when I power on. When I open the Arduino Serial Terminal, oscillation stops. When I enter a value in the Arduino Serial Terminal, it seems it rotate the value and direction (difficult to say if the number of steps is correct), then turn CW or oscillate. Note : Same behavior if the DIR and STEP (D3 and A0) input pin are connected to ground or +5V
misan
misan
over 9 years
<p><a rel="nofollow" target="_blank" href="/users/GrandGibier" class="mentioned-user">@GrandGibier</a>&nbsp; That does not look right, you should get a consistent increase or decrease when moving CW or CCW. Please double check the encoder's signals go to the pins stated in the code (digital pins 2 &amp; 8) and that there is a good connection.</p>
GrandGibier
GrandGibier
over 9 years
<p>It displays a suite of <b>0,</b> then when I rotate the Coder CW &nbsp;it displays <b>2, 3,</b> or CCW &nbsp;&gt; <b>-1, -2 .</b></p><p>Then each time the coder gives impulsion, it swaps &nbsp;<b>2, 3, 2, 3, 2, 3</b> &nbsp;or &nbsp;<b>-1 , -2 , -1, -2 , -1</b></p><p>Could it be a problem of the libraries I use : PinChangeIntConfig.h, PinChangeInt.h ?</p>
misan
misan
over 9 years
<p><a rel="nofollow" target="_blank" href="/users/GrandGibier" class="mentioned-user">@GrandGibier</a>&nbsp; There are a couple of things to double check: that the encoder signal is properly handled (without powering the motor). You can add something like delay(100); Serial.println(encoder0Pos); within the loop and see what you get when you rotate the motor CW or CCW by hand. Use the Arduino Serial Terminal window to see the results (select 115200bps as the serial speed). Is is counting properly one way and the other?</p><p>(later we can focus in the motor part)</p>
GrandGibier
GrandGibier
over 9 years
I received my oscillo... It seems everything is OK. - This picture show the Step and Dir CW input signal (Step Channel #1, Dir Channel #2) : <a rel="nofollow" target="_blank" href="http://www.lasource.org/download/cl/step-dir-cw.jpg">http://www.lasource.org/download/cl/step-dir-cw.jpg</a> - This picture show the Step and Dir CCW input signal (Step Channel #1, Dir Channel #2) : <a rel="nofollow" target="_blank" href="http://www.lasource.org/download/cl/step-dir-ccw.jpg">http://www.lasource.org/download/cl/step-dir-ccw.jpg</a> - This picture show the 2 rotary encoder input signal (Encoder A : Channel #1, Encoder B : Channel #2) : <a rel="nofollow" target="_blank" href="http://www.lasource.org/download/cl/rotaty_encoder_a-b.jpg">http://www.lasource.org/download/cl/rotaty_encoder_a-b.jpg</a> - This picture show the PWM signal from the Arduino when powering on (Step input : Channel #1, PWM output : Channel #2) : <a rel="nofollow" target="_blank" href="http://www.lasource.org/download/cl/pwm_when_power_on.jpg">http://www.lasource.org/download/cl/pwm_when_power_on.jpg</a> - This picture show the PWM signal from the Arduino when Step /Dir start (Step input : Channel #1, PWM output : Channel #2) : <a rel="nofollow" target="_blank" href="http://www.lasource.org/download/cl/pwm_when_step_on.jpg">http://www.lasource.org/download/cl/pwm_when_step_on.jpg</a>. It stay less than 1 second in that state then become like that : <a rel="nofollow" target="_blank" href="http://www.lasource.org/download/cl/pwm_when_step_off.jpg">http://www.lasource.org/download/cl/pwm_when_step_off.jpg</a> even if I change the Step speed or Dir input or stop the Step, the&nbsp;motor&nbsp;turn.<div>&nbsp;I tried with 1 Arduino Uno and 1 Pro Micro, tried to swap M1&lt;&gt;M2, Encoder A&lt;&gt;B...same behavior. Any idea or things to check ? Your help is welcome, thanks. PS : Just in case of, the Sketch is here : <a rel="nofollow" target="_blank" href="http://www.lasource.org/download/cl/servostrapv02-m.ino">http://www.lasource.org/download/cl/servostrapv02-m.ino</a> I have double checked, but maybe I made an error.</div>
GrandGibier
GrandGibier
over 9 years
Same thing, the motor start,but don't stop. Sometime the motor start when power on. I am waiting for an oscillo and I will test the encoder and signals... Thanks
misan
misan
over 9 years
<p><a rel="nofollow" target="_blank" href="/users/GrandGibier" class="mentioned-user">@GrandGibier</a>&nbsp; what happens if you exchange DC motor wires?</p>
GrandGibier
GrandGibier
over 9 years
Now the motor change direction when I change the stepper direction, but it does not stop !(continuous rotation until I change the direction). Maybe a problem with the coder ? I will test the coder signal and try with an arduino demo sketch.
GrandGibier
GrandGibier
over 9 years
<p>Thanks, I'll do a try...</p>
misan
misan
over 9 years
<p><a rel="nofollow" target="_blank" href="/users/GrandGibier" class="mentioned-user">@GrandGibier</a>&nbsp; I have reviewed your L298N circuit and it seems different than mine. There is an additional chip to make interface simpler (but different than mine). In essence PwmOut function needs to be adapted. Instead of using TWO output PMW pins your board uses just one. The second pin is for stating whether you want CW or CCW motion.</p><p>Something like this (E pin of your board is PWM and M is CWCCW according to this <a rel="nofollow" target="_blank" href="http://www.dfrobot.com/wiki/index.php/MD1.3_2A_Dual_Motor_Controller_SKU_DRI0002">http://www.dfrobot.com/wiki/index.php/MD1.3_2A_Dual_Motor_Controller_SKU_DRI0002</a>&nbsp;)&nbsp;:</p><p><br></p><p>void pwmOut(int out) {</p><p>&nbsp; &nbsp;if(out&lt;0) digitalWrite(CWCCW,HIGH); else &nbsp;digitalWrite(CWCCW, LOW); </p><p>&nbsp; &nbsp;analogWrite(PWM, abs(out) );</p><p>&nbsp; }</p>
waleedq
waleedq
over 9 years
<p>@<a href="https://www.youmagine.com/users/grandgibier" target="_blank" rel="nofollow">GrandGibier</a> i've faced the same issue before,&nbsp; please bare in mind that the code attached here is using port manipulation to read the ports data, i think this would vary from board to board as the ports are more or less in each board, make sure that they are reading the right pins or convert it to use digitalRead.</p>
GrandGibier
GrandGibier
over 9 years
Looks Great... I tried with the elements I have : - Arduino Uno - Pololu Geared motor - <a rel="nofollow" target="_blank" href="https://www.pololu.com/product/2218">https://www.pololu.com/product/2218</a> - Pololu Magnetic Encoder - <a rel="nofollow" target="_blank" href="https://www.pololu.com/product/2598">https://www.pololu.com/product/2598</a> - DF Robot Dual H-Bridge - <a rel="nofollow" target="_blank" href="http://www.dfrobot.com/index.php?route=product/product&amp;product_id=66&amp;search=DUAL+H-Bridge+V1.30&amp;category_id=48">http://www.dfrobot.com/index.php?route=product/product&amp;product_id=66&amp;search=DUAL+H-Bridge+V1...</a>&nbsp;<div>Unfortunately, impossible to have something working. The DC motor turns always same direction, sometime it does not stop or does not start.<br></div><div>The Motherboard of the printer is an Arduino Ramps Compatible (Megatronics V3.0 with DRV8825 Stepper drivers) <a rel="nofollow" target="_blank" href="http://reprapworld.com/?products_details&amp;products_id=468">http://reprapworld.com/?products_details&amp;products_id=468</a>&nbsp;<div><br></div></div>
misan
misan
over 9 years
<p><a rel="nofollow" target="_blank" href="/users/miloslab" class="mentioned-user">@miloslab</a>&nbsp;please bear in mind that steppers usually are driven at x16 microstepping, so they need 3200 pulses per revolution, so 32/3200 = 1/100 mm or 10 microns per step (at least in theory <a rel="nofollow" target="_blank" href="http://www.micromo.com/microstepping-myths-and-realities">http://www.micromo.com/microstepping-myths-and-realities</a>&nbsp;)</p>
misan
misan
over 9 years
<p><a rel="nofollow" target="_blank" href="/users/lond" class="mentioned-user">@lond</a>&nbsp;That looks great.&nbsp;</p>
J Huang
J Huang
over 9 years
<p>@<a rel="nofollow" target="_blank" href="https://www.youmagine.com/users/lond">lond</a>&nbsp;WOW, it is a very neat stepper-DC converter :)</p>
lond
lond
over 9 years
I made a PCB with a Arduino Pro Mini and a L298 on: <br><a href="https://lh5.googleusercontent.com/-0PIJGaXeE44/VNPHkVkolyI/AAAAAAAAC8w/0LZrGYUneB4/s512/DSC_1164.JPG" target="_blank" rel="nofollow">https://lh5.googleusercontent.com/-0PIJGaXeE44/VNPHkVkolyI/AAAAAAAAC8w/0LZrGYUneB4/s512/DSC_1164.JPG</a> <br> /// Marcus
miloslab
miloslab
over 9 years
<p><a rel="nofollow" target="_blank" href="/users/misan" class="mentioned-user">@misan</a>&nbsp;</p><div>an optical linear encoder strip has 6 lines / mm, the sensor produces a two phase signal 6 + 6 pulses per mm 24 edges / mm, the accuracy is 0.04 mm.</div><div>Stepper 200 steps / mm belt pulley 16 teeth GT2 2 mm based 32/200 = 0.16 mm Microstepping improves engine operation, stepper not stops eg. To 7/16 step. The optical sensor is more accurate than the stepper. Is it good?</div>
waleedq
waleedq
over 9 years
<p>@<a href="https://www.youmagine.com/users/misan" target="_blank" rel="nofollow">misan</a> i think i knew what is causing the motor to go crazy, i didn't add a common ground between the RAMPS and the mega board that controls the motor, as each one is supplied from a different power supply, i will try it once i get home. Thank You.</p>
misan
misan
over 9 years
@waleedq good to know it is working for you know. Please note that if step input gets noise it may cause motor motion due to pulses being added to the target location.
waleedq
waleedq
over 9 years
<p>@<a href="https://www.youmagine.com/users/misan" target="_blank" rel="nofollow">misan</a> Thank you for your replay, the problem was that am using Arduino Mega this the only spare one that i have, i think the problem was in the way the code reads the pins using pin manipulation (PINC&amp;B0000001) so this is why the encoder was always reading one direction.</p><p>Now i've got things working, tuned the PID's motor is stepping now !!.</p><p>i've tried to connect to to the DIR and STEP from my RAMPS board but the motor went crazy and the weird thing that the step value started to change without moving the axis. dunno what could cause the issue exactly but i will look into it today and i will try do the quadrature encoding version as am still working on the first version.</p><p>I will keep you updated. thanks</p>
misan
misan
over 9 years
<p><a rel="nofollow" target="_blank" href="/users/J Huang" class="mentioned-user">@J Huang</a>&nbsp;When I am using a stepper in that printer pulleys are different (more teeth) but just answering your question I had around 102 pulses/mm in my X-axis stepper. I run the stepper using 16x microstepping.</p>
J Huang
J Huang
over 9 years
@misan What was the number of pulses/mm when using stepper? Did the stepper run in full-step mode or micro-step mode?
misan
misan
over 9 years
<p><a rel="nofollow" target="_blank" href="/users/miloslab" class="mentioned-user">@miloslab</a>&nbsp; I think you can use that too. I reckon the linear strip is just the same as the slotted disk of the encoder but unfolded. I reckon sensor in the carriage also produces the same quadrature input (but I have not verified that myself). My guess is that it is going to work the same with this firmware. Please report back with your results.</p>
misan
misan
over 9 years
@waledq Please note that encoder counts and motor rotation need to be aligned, if not the will run full-throttle forever (as the error increases because the motor moves away from the target location instead of getting closer and closer). You can fix that by reversing motor polarity (switch motor wires) or switch encoder wires. Please let me know if this is fixed.
misan
misan
over 9 years
<p><a rel="nofollow" target="_blank" href="/users/J Huang" class="mentioned-user">@J Huang</a>&nbsp;In my case it was 31.138 pulses/mm (when using 2x encoder) it should double when using the latest v02 which uses 4x when reading encoder pulses.</p>
miloslab
miloslab
over 9 years
<p>Misan thanks for the link; in my PIXMA IP4000 deceased are similar engines think that going to use? The engine that powers the head would have been ideal, but it has a linear encoder, do you think the same principle?</p>
waleedq
waleedq
over 9 years
<p>Great job!!, yesterday i was trying to implement it for my 3d printer but the dc motor kept on turning, i didn't get what was going wrong, the encoder readings was going in +ve but the direction reading where going in -ve would that be the reason that the motor kept turning?</p>
J Huang
J Huang
over 9 years
What are the pulse resolutions (i.e. the moving distance of x or y axis per pulse output from Marlin) before and after the mod?
misan
misan
over 9 years
<p><a rel="nofollow" target="_blank" href="/users/miloslab" class="mentioned-user">@miloslab</a>&nbsp;You can get it from here <a rel="nofollow" target="_blank" href="http://dl.bintray.com/greygnome/generic/pinchangeint-2.40-rc2.zip">http://dl.bintray.com/greygnome/generic/pinchangeint-2.40-rc2.zip</a></p>
miloslab
miloslab
over 9 years
Please, where can I find the library PinChangeIntConfig.h, PinChangeInt.ha PID_v1.h? thanks
misan
misan
over 9 years
@ekaggrat I have uploaded a picture of the part I printed in the video. The orange encoder cover in the motor [right] was printed with the original steppers and the one on the left-hand side was printed with the DC motors. Quality-wise I do not see an improvement but that is just the beginning as that was done without a controlled speed profile, something I am working at now that I reckon will improve output quality.
ekaggrat
ekaggrat
over 9 years
any gain / fall in print quality, just curious. I think you should put a pic of a print on the same setup before and after the mod
misan
misan
over 9 years
<p>@WWC, thanks for the link. It is right and now it is correctly stating encoder is 448 lines and not 888 as they said before. </p><p>This other one is a bit cheaper and you can buy just one unit <a rel="nofollow" target="_blank" href="http://www.ebay.com/itm/Mitsumi-448P-R-AB-phase-encoder-encodes-tacho-motor-speed-disk-DC3V-24V-5V-12V-/361190538538?pt=LH_DefaultDomain_0&amp;hash=item5418a23d2a">http://www.ebay.com/itm/Mitsumi-448P-R-AB-phase-encoder-encodes-tacho-motor-speed-disk-DC3V-24V-5V-1...</a></p>
WWC
WWC
over 9 years
<p><a rel="nofollow" target="_blank" href="/users/misan" class="mentioned-user">@misan</a>&nbsp;In the motor link you have it looks like there is a different motor there now. This one says 64 lines. The other one said 888 i believe.</p><p>This looks like what i saw before.&nbsp;</p><p><a rel="nofollow" target="_blank" href="http://www.aliexpress.com/store/product/5pcs-MABUCHI-385-motor-with-Encoder-448-AB-phase-encoder-motor-for-Printer-copier-car-home/833384_32218907529.html">http://www.aliexpress.com/store/product/5pcs-MABUCHI-385-motor-with-Encoder-448-AB-phase-encoder-mot...</a></p>
J Huang
J Huang
over 9 years
<p>Good catch indeed. I thought it was 2x encoder configuration when I counted the input steps and output (encoder) pulse in the waveform posted by misan.</p><p>The challenge of replacing stepper with DC motor in consumer 3D printer is how to minimize the printing positioning error at a reasonable cost so that it has the similar or better performance/cost ratio. We just start to see the first batch of 3D printers with DC motor deployment on the market -- such as MoD-t and Micro</p>
Jimf
Jimf
over 9 years
<p>I choose falling edge since that is what geckodrives uses for there step input although I don't think it matters all that much. &nbsp;I have over a dozen of their servo and stepper drives so I kept the same config. &nbsp;</p><p>Motor spinning smoothly at 1500rpm with the encoder interrupt routine reading 20,000 counts/sec without missing a beat. Woohoo!!!!</p>
misan
misan
over 9 years
Good catch Jimf!!, my mistake shuffling code back and forth. I reckon RISING is a better choice for edge selection. It's already updated on youmagine.
Jimf
Jimf
over 9 years
<p>I ended up changing the step input interrupt from CHANGE to FALLING edge trigger. &nbsp;This should be the correct way to handle step input. &nbsp;you don't want the step to increment on both rising and falling edges which would double the step input. &nbsp;Now 800 step inputs gives me 1 full revolution.&nbsp;</p>
Jimf
Jimf
over 9 years
<p>Ya there probably something wrong with either my Tek freq generator or fluke counter. &nbsp;I'll scope out the signal and verify it later. &nbsp;sorry to bother you. &nbsp;</p>
misan
misan
over 9 years
The way you generate the signal may be the problem. Is it possible you are creating a signal of half the frequency? (a single cycle requires two edges and usually two delay calls if software generated) I assume you apply the signal for just one second. Alternately, you can just use the serial port to send integer values to command motion (using Arduino serial monitor without CR or LF) to check whether it does as expected or not (that would check the regulation loop by letting you set the desired location).
Jimf
Jimf
over 9 years
I serial printed out the encoder position and I do get 800 pulses per rev so the interrupt code is correct and working. However a 400hz stepper signal only gives me 1 revolution. So something is wrong with my setup somehow.
misan
misan
over 9 years
I have tested my encoder with a hardware-based 4x encoder (Cortex M4) and I get around 1800 counts/revolution (I guess I have a 448 line disk). Similar numbers were obtained with my code and Arduino. I will re-check that later.<div><br></div><div>Could you please replace interrupt code with just Encoder0Pos++; and see how many counts you have after a single rotation?</div>
misan
misan
over 9 years
<p>There are two interrupts attached to it. If one of them is not working that would the expected result. I know that interrupt on pin change has higher latency, but it seemed to work ok for me. However, I have got some trouble with the real number of lines of my encoder as I sourced it from Aliexpress and no data sheet was available. So I assumed the error was the vendor's but now that you mention this, it could be my fault. I will have a look and I will let you know.</p>
Jimf
Jimf
over 9 years
Misan, I think there may be a problem with V2 firmware quadrature decoder function. I'm using a 200 line encoder, with 4x quadrature, it should take 800 step pulses for one motor revolution but It only takes 400 steps pulses. The quadrature code seems to do 2x counting. I used a 400hz signal from my TEK pulse generator and the motor only spins one complete revolution per second. I also verified it was a 200line encoder. Regards Jim
Jimf
Jimf
over 9 years
<p>I was running 20volts and was able to get 1300rpm smoothly with 200line encoders. &nbsp;Using higher resolution encoders will eat up a lot more cycles and drop max RPM but if you can get atleast 600rpm that is much faster than most any 3d printer needs with belt drive &nbsp;</p><p>There seems to be some negative comments within the Reprap community regarding servo drives vs steppers &nbsp; I use both but most of my CNC machines are servo driven. &nbsp;I know what a good servo system is capable of and there is no doubt that I would choose a servo over a stepper anytime. &nbsp; This Arduino servo makes it really cost effective compared to what I have invested in my other servo driven machines &nbsp;. . &nbsp;</p>
misan
misan
over 9 years
<p>Hi Jimf, I am very happy you have it working too. I share with the intent it might be useful for other people. I tried but failed to use the Arduino PID autotune library that would have provided users autotune of the P, I &amp; D gains (I do not think there is anything wrong with the library but I failed to make it work).&nbsp;</p><p>Please feel free to do as you see fit and if you share it with us even better.</p><p>I am afraid v02 is going to have trouble with high rpm motors. It works ok with my motors at 12V but faster motors may end up eating all processing time in the interrupts and stop working ok. Initial version handle faster rpm at the cost of lower resolution.</p>
Jimf
Jimf
over 9 years
Got a chance to play around with the PID values and got the servo motor to spin really smooth. Had to lower the D term a little. Most stepper drivers have mid band resonance problems that causes steppers to lose torque and misstep when spinning around 300-500rpm. This varies depending on motor, voltage and torque. A servo motor does not have this problem. It will spin smoothly from zero to max RPM. I believe that some of the issues with fast 3d printers is from mid band resonance causing lost steps. High performance steppers drivers like Geckodrives have anti-resonance but they are expensive. The low end stepper drivers used in most 3D printers do exhibit really bad resonance issues. I can tell you that a good servo driver/motor combination runs so much smoother/faster than most stepper motors can. Having used Geckodrive and Parker servo drivers, I’m plesently surprised how well this simple Arduino servo program works. I plan to make a small pcb board servo driver with this design if you don't mind.
misan
misan
over 9 years
Jimf Thanks a lot for your testing and support.
Jimf
Jimf
over 9 years
http://youtu.be/VDxEXbkjAsg Tested the firmware this morning and it really does work great. Good job. Thanks
misan
misan
over 9 years
<p>Hi Frank,&nbsp;To prevent wire slippage, designs like Richrap's 3DR use reels where the wire is fixed to it and slipping is just not possible. I did my version of it a while ago <a rel="nofollow" target="_blank" href="http://www.thingiverse.com/thing:203836">http://www.thingiverse.com/thing:203836</a></p><p>If&nbsp;you&nbsp;have&nbsp;your&nbsp;wire&nbsp;not&nbsp;fixed&nbsp;to&nbsp;the&nbsp;reel, slippage&nbsp;is&nbsp;possible&nbsp;no&nbsp;matter&nbsp;the&nbsp;type&nbsp;of&nbsp;motor&nbsp;you&nbsp;use.&nbsp;I&nbsp;am&nbsp;afraid closed-loop&nbsp;is&nbsp;not&nbsp;helping&nbsp;you&nbsp;here&nbsp;(unless&nbsp;encoder uses a&nbsp;linear&nbsp;encoder&nbsp;measuring the&nbsp;actual&nbsp;carriage&nbsp;movement&nbsp;and&nbsp;not&nbsp;motor&nbsp;turns).</p>
Frank Taylor
Frank Taylor
over 9 years
Really neat idea. I have a question, I'm using a delta printer with a cable system, which has a habit of slipping. Will your system compensate for this, or would I need to switch to a belt to eliminate the slip? Thanks in advance :)
misan
misan
over 9 years
Please note that the motors featured in this article are erroneously marked as having 888 line encoders but they really are 448-line encoders. (or 1792 ticks per revolution if 4x mode is used for encoder info).
misan
misan
over 9 years
Maybe Maple Mini can be the cheapest way to control four motors as&nbsp;it&nbsp;can&nbsp;handle&nbsp;encoder&nbsp;signals using built-in&nbsp;hardware&nbsp;timers&nbsp;<a target="_blank" rel="nofollow" href="http://www.aliexpress.com/item/leaflabs-Leaf-maple-mini-ARM-STM32-compatibility/32214664071.html">http://www.aliexpress.com/item/leaflabs-Leaf-maple-mini-ARM-STM32-compatibility/32214664071.html</a>
misan
misan
over 9 years
<p>You're welcome. I did try using one Arduino to control two motors but &nbsp;I did not get it to work reliably. Maybe if done in assembler it can work (or with encoders with less lines). Anyway, &nbsp;I am planning to use Arduno Pro Mini boards for this, one per motor, that can be had for less than $2 each.</p>
gennro
gennro
over 9 years
<p>Thanks misan, I am going to order some of those motors and play with what you have going on here. Also are you using one arduino to control 2 motors now?</p>
misan
misan
over 9 years
<p>The motor comes with a MXL pulley so I am using a MXL belt.</p>
gennro
gennro
over 9 years
<p>What are you using to drive the belt, pulley wise?</p>
misan
misan
over 9 years
1- Encoders in the motors I am using have 888 lines. Quadrature encoders have the potential to provide 4x this resolution (it depends on how the software handles it). So in theory you can resolve up to 3552 "steps"/revolution. But contrary to stepper motors, these values represent an accurate angular position, so I reckon they offer better spatial resolution. 2- I am using 2ms between each PID calculation. 3- At least to me they are mysterious motors from China (encoder datasheet can be found online). I posted the link to the motors on the youtube video details. http://www.aliexpress.com/item/New-boutique-12V-DC-motor-385-servo-motors-speed-encoder-888-line-AB-phase-encoder-For/1345460690.html
levlandau
levlandau
over 9 years
<p>This is very nice. Well done, really cool to see a working implementation.&nbsp;</p><p><br></p><p>I have a couple of questions:</p><p>1) What resolution is possible with this motor? Would this allow more precise control of the motion steps as compared to a stepper motor?</p><p>2) What is the speed of the feedback loop, how fast can it respond to position error?</p><p>3) Is there a datasheet on the motor and encoder, or are they mysterious cheap motors/encoders from China :-)?</p>

misan

19 objects 59 Followers 59 Downloads
Enjoy a 10% sitewide
Discount at checkout
Get a 10% Discount