Go Down

Topic: A Eureka Moment! (Read 2019 times) previous topic - next topic

yendis

I don't know if this is an appropriate post for this section, but I just wanted to share some joy.  :)

My project is to control the speed of a DC PM motor for a classic car project.  The car will have a non-standard gearbox which has no mechanical speedometer drive.  Since I want to keep the original (mechanical) speedometer then this has to be driven by a motor, from electrical pick up pulses related to road speed. 

As a newbie to the Arduino, I have been on a steep learning curve this year.  Starting in April 2015, I decided to learn 'C' as this is the basis of the Arduino sketch language.   Then having bought an Uno, and built up an interface board, I began to put some code together.   I decided not to use the PID library as I wanted to learn the hard way - and assumed that my own code would be easier to understand (in hindsight I am not sure that it was!).

When first connected up, after a bit of debugging the motor did run, and follow the demand signal to a fashion, but there were all sorts of problems.  The speed was unstable, erratic, and sometimes the motor either jumped to full speed, or just stopped and sulked.   

Many weeks passed by as I tried to tune the P and I constants to get it under control, but I seemed to swap one problem for another and felt like I wasn't getting there.  But whilst doing this, I did make a lot of changes to the way I was declaring variable types in order to eliminate errors and overcome limitations of the code.   

Last week I posted that I still had instability problems, especially at low speed start up, and I was thinking of going back to the drawing board, and trying a brush-less motor drive instead. 

But after some further changes to variable types, and more tweaking of the P and I constants, today I finally cracked it!  The motor now tracks road speed (from a pulse generator) closely from 5 mph right up to max speed quite closely, and any overshoot is short lived.

The moral of my story?  Well I guess patience and perseverance, and watch out for data typing problems.

Whilst I am far from expert, I hope that now I will be able to help someone else at least in some small way on a similar project.

Chris

raschemmel

#1
Jan 05, 2016, 07:13 pm Last Edit: Jan 05, 2016, 07:19 pm by raschemmel
While this is all well and good, the purpose of the forum is to provide a database of useful information. Unless you intend to post a complete project package with schematics, code and photos,
your post is of no value to anyone. We already know that patience and perseverance are virtues, thank you very much. Thanks for the heads up anyway. If you really want to help others, post your project in the Exhibition Gallery with photos, and code. Since your an EE, you should have a lot to offer.
Arduino UNOs, Pro-Minis, ATMega328, ATtiny85, LCDs, MCP4162, keypads,<br />DS18B20s,74c922,nRF24L01, RS232, SD card, RC fixed wing, quadcopter

keeper63

Minor nitpick, but something that needs to be corrected: There is no such thing as an "Arduino sketch language"; Arduino sketches are written in C/C++, nothing more, nothing less. Behind the scenes, a pre-compiler does some "magic" and adds in the main() function (which calls setup(), then repeatedly calls loop() in an endless looping construct), plus the Arduino library headers - and a few other minor things.

All of this is done to help beginners feel more comfortable with using the system, as well as to improve development time; even so - a simple template "starting point" sketch could have been included and used, instead of the hidden "magic" - but then that would complicate the teaching of the system for newbies, as you would then have to explain what all the other parts were, first, before you could even get to the coding portion. It's debatable which is better, but it is what it is.

Furthermore, the term "sketch" is nothing more than a "marketing term" - one could call it instead "a program" or "source code" or something similar, and it would mean virtually the same thing. The term "sketch" instead is a name to make the system more approachable for newbies to programming.

Most of all of this, by the way, is historical re-purposing of the Wiring and Processing projects (both open source, IIRC), which I believe both used similar (or same) terminology, with the same goal of making software development and hardware embedding more approachable. However, the boards that were used back then, while superficially similar to the Arduino, were somewhat of a different nature and purpose - and were used as the inspiration to create the Arduino, instead, while parts of those systems (like the similarities with the Processing language constructs, as well as the IDE which came from Wiring) were borrowed.

At least, that's how I understand things; if I am wrong in any of this - please correct me.

:)
I will not respond to Arduino help PM's from random forum users; if you have such a question, start a new topic thread.

raschemmel

Quote
Furthermore, the term "sketch" is nothing more than a "marketing term"   
One I never cared for , because it makes the program sound like a casual collection of jots on a pad,
when, in reality, it could be very complex.
Arduino UNOs, Pro-Minis, ATMega328, ATtiny85, LCDs, MCP4162, keypads,<br />DS18B20s,74c922,nRF24L01, RS232, SD card, RC fixed wing, quadcopter

yendis

OK if I am wrong about the 'Arduino sketch language', please explain.

Much of the source code which we use to program the Arduino is not in any C reference I have seen. I taught myself C before beginning to use the Arduino, but still had to learn a lot of new stuff.

Confused of Surrey.


Chris

liuzengqiang

Just wondering what values you set your D to. Most of the time, a non-zero D leads to jittery responses since it draws from the change of values over short period of time. I usually only use P and I and only use D if the single is relatively clean and I need a faster response.

Arduino IDE is using C/C++ language so you can say that you learned C/C++ by using Arduino. I think Processing calls its program code sketch, which makes a lot of sense. It is used to visualize things so it is like a drawing or a sketch. Arduino/Wiring probably borrowed the term and claim to have used it for marketing purpose to make it sound less hard than code or program.
Serial LCD keypad panel,phi_prompt user interface library,SDI-12 USB Adapter

raschemmel

Quote
Arduino/Wiring probably borrowed the term and claim to have used it for marketing purpose to make it sound less hard than code or program.   
Well they fooled me. I started with arduino thinking I study C++ later and next thing you know I'm learning C++...
Arduino UNOs, Pro-Minis, ATMega328, ATtiny85, LCDs, MCP4162, keypads,<br />DS18B20s,74c922,nRF24L01, RS232, SD card, RC fixed wing, quadcopter

Henry_Best

Furthermore, the term "sketch" is nothing more than a "marketing term" - one could call it instead "a program" or "source code" or something similar, and it would mean virtually the same thing. The term "sketch" instead is a name to make the system more approachable for newbies to programming.
The Arduino Cookbook calls them 'recipes'.
That's not to everyone's taste, though.

larryd

The use of non programming terms makes the platform more acceptable to people in the arts.
No technical PMs.
If you are asked a question, please respond with an answer.
If you are asked for more information, please supply it.
If you need clarification, ask for help.

dmjlambert

The use of non programming terms makes the platform more acceptable to people in the arts.
Indeed.  The Arduino was born in (and specifically for) the arts.   Let's celebrate that!  10 years of attempt at transforming artists into geeks.  Or at least issuing artists their geek badges (and some of them magic smoke badges).

yendis

#10
Jan 06, 2016, 08:40 am Last Edit: Jan 06, 2016, 08:53 am by yendis
Just wondering what values you set your D to. Most of the time, a non-zero D leads to jittery responses since it draws from the change of values over short period of time. I usually only use P and I and only use D if the single is relatively clean and I need a faster response.

I did not implement a D term in my code.  One of my causes of erratic behaviour was overflow of a variable to a negative number - newbie errors. Also poor resolution was not helping - initially I went to a float variable but kept getting ovf in the result - then I changed to long, and use a x10 multiple and this worked - I still dont understand why float would not work.

PS: crOsh: I still stand by my assertion that the language used to program the Arduino is a 'sketch' and not C.  Although it uses much of the C language there are many Arduino specific terms which are not in any C definition that I know of.   It is misleading to call it C.  I am still working my way through all the Arduino specific stuff.
Chris

raschemmel

Maybe they would have less magic smoke if they smoked less magic...
Arduino UNOs, Pro-Minis, ATMega328, ATtiny85, LCDs, MCP4162, keypads,<br />DS18B20s,74c922,nRF24L01, RS232, SD card, RC fixed wing, quadcopter

liuzengqiang

PS: crOsh: I still stand by my assertion that the language used to program the Arduino is a 'sketch' and not C.  Although it uses much of the C language there are many Arduino specific terms which are not in any C definition that I know of.   It is misleading to call it C.  I am still working my way through all the Arduino specific stuff.

C doesn't define any standard functions such as print or read or delay etc. It is just keywords and syntax (and basic data types). If you are using a C compiler, which you are, you are using C. There is no need to debate whether Arduino IDE uses C, because it does.

Every programming environment has some standard functions to do things on their target systems. If you program for a PC, you probably have functions to call a shell, get path, time, open files on a FAT or NTFS system etc. These don't make your C a "PC programming language". It's still C.

If you read an Eastern Indian cookbook written in English, do you say it's written in "Indian food language" or do you say it's written in English? Yeah, you find curry and Indian eggplant very seldom used in cooking pasta or other western dishes, but that cookbook is still in English, not "Indian food language".
Serial LCD keypad panel,phi_prompt user interface library,SDI-12 USB Adapter

raschemmel

Quote
Every programming environment has some standard functions to do things on their target systems. If you program for a PC, you probably have functions to call a shell, get path, time, open files on a FAT or NTFS system etc. These don't make your C a "PC programming language". It's still C.

If you read an Eastern Indian cookbook written in English, do you say it's written in "Indian food language" or do you say it's written in English? Yeah, you find curry and Indian eggplant very seldom used in cooking pasta or other western dishes, but that cookbook is still in English, not "Indian food language".
Well said. I don't think anyone else could have said it better.
Arduino UNOs, Pro-Minis, ATMega328, ATtiny85, LCDs, MCP4162, keypads,<br />DS18B20s,74c922,nRF24L01, RS232, SD card, RC fixed wing, quadcopter

larryd

Quote
Maybe they would have less magic smoke if they smoked less magic...
lol
No technical PMs.
If you are asked a question, please respond with an answer.
If you are asked for more information, please supply it.
If you need clarification, ask for help.

Go Up