Posted: 12/12/2007 9:41:08 PM EDT
|
I heard in Engineering Class today we will be leaning C++ in our computer programming class, as opposed to older class curriculum that taught Fortran. Whats it like? Difficult? Whats the language look like? I have been a CNC programmer as a machinist for about 10 years now, so I somewhat understand the logistics of programming codes to make machines do what I ask. Will that help at all? |
Not really. Are you good at math? You won't use much in your programs, but if you're naturally good at math, you'll find that programing comes naturally as well. There are examples of C++ code everywhere. The majority of Open Source programs are written in C, followed by C++. |
I'm pretty good at math, and by the time I take this course, I'll be in either Calc I or Calc II. That will help with the logical thinking type aspect or something? |
If you ignore most of what you can do with C++ and focus on perfect structure and error checking as if you were doing COBOL, you will shock everyone by always writing good C++. Yes, the math will help. So will being older and not distracted. |
|
//C++ is a good language. Much better than Fortran. //It is also a fairly common language and job opportunities are vast for C++ programmers. //I tend to think that all good programmers are mathematicians and can express ideas as mathematical expressions (algorithms). //Bad programmers are "scripter kiddies" that cant visualize algorithms, they lack the maths. Their brains dont have a #include math.h
|
Logical thinking is what programming is all about. You've got to break the problem down into small enough parts for the computer to handle. Anyways, C++ shouldn't be all that difficult if you can handle calc. The first time it will get semi-difficult is when you have to deal with pointers and stuff but that won't be for a while. You'll probably find that cin/cout are kind of annoying. Classes are also overly complicated in C++. This will probably be your first example:
|
| Coming from a strong mainframe/COBOL/Fortran background I took to CNC programming the few times I did it like a duck to water. I would actually expect that the opposite is true and that the OP will do fine. Of course, I was motivated -- CNC machines are really cool! |
Just G and M code on CNC machines. There is software to write this for you, but i do it all by hand because the software like to waste time and make redundant moves ect. When multiplied over thousands of parts, a few seconds a piece makes a huge difference. Heres a little sample. This is an exceptionally easy program, but its the beats I could find.. N10 G00 G20 G40 G49 G80 G90 G98 (1/4" SLOT DRILL) N12 T3 M06 N14 S10000 M03 N16 G00 G54 G43 X0.25 Y0.1 Z1. H03 M08 N18 Z0.1 N20 G99 G81 Z-.1 R.05 F12. N22 M97 P1000 N24 M09 (13/64" DRILL) N26 T4 M06 N28 S3761 M03 N30 G00 G54 G43 X0.25 Y0.1 Z1. H04 M08 N32 Z0.1 N34 G99 G73 Z-1. R.05 Q.1 F18. N36 M97 P1000 N38 M09 (1/4-20unc TAP) N40 T3 M06 N42 S1000 M03 N44 G00 G54 G43 X0.25 Y0.1 Z1. H03 M08 N46 Z0.1 N48 G99 G84 Z-.75 R.05 F50. N50 M97 P1000 N52 M09 N54 G91 G28 Y0 Z0 N56 G90 N58 M30 |
Thats gibberish to me....
|
for (x=0;x<=1;++x) { cout << showpos << x << endl; } |
Showoff.
|
|
Programming concepts are universal. Coming to terms with language syntax & specific functionality is the challenge. I cut my teeth on Visual Studio 6 & GNU. For example, some funky error messages come up if your header file function prototypes don't match the actual function implementation in the .cpp (specifically, for differing function arguments between .h & .cpp function calls - so make sure they match). Your ideas can be good to go but you'll be stuck in a holding pattern unless/until you resolve that damned syntax error - been there, done that! Best advice I can give is, get the code working 1st & then worry about optimization - if you have time. Don't fancy yourself into a corner. Start simple & implement the slick stuff incrementally as you come to grips w/ the specifics. And yes, a strong math background helps. Edited for |
Thats what i was hoping. I know it wont automatically be a piece of cake, but the logic that goes into arranging code to not only do what need to be done, but to put in order and make the machine understand it. That makes perfect sense. |
Can CNC machines execute code in conditional loops? In other words, can they repeat a sequence of events x number of times, depending on the value of y? |
Sort of. We have subprograms and in the first line there is a call out for the subprogram number and number of times to run it. You can also run subroutines that mixed with different locations to run the same routine in multiple places on the same part. |
Does the subprogram have to run a fixed number of times, or can you tell it to run until x is true? |
Just for some help with terminology. You will eventually see the term function passed around a lot. It is really no different than a subroutine with some MINOR conceptual differences. Here is a list of terms you should be able to know what they mean before trying to program. Variable mathematical operators plus minus times divide modulo replacement (=) really really equal to (==) data types: int double string looping structures: for while do-while functions |
Some of the new CNC's are amazing. They can run a part, bring up an infrared probe, check the part, make offsets, and rerun the tools. Then call you on your cell phone if something goes wrong. If it's something simple it may be able to be fixed over the internet. The actual subprograms usually just run the specified number of times, but as I said the new shit is unreal. HERES AN EXAMPLE |
|
I don't know anything about CNC programming, but C++ has been my primary programming language since about 1993. I came from C and assembler, then moved primarily to C++, with Java, VB, and now a lot of C#. I wrote the C++ test we give to job candidates. Basic C++ is not too complicated, but it can be very complicated when you add multiple inheritance or make heavy use of templates, template meta-programming, etc. In fact, combined with STL, C++ is probably the most complicated programming environment there is. And the language has a multitude of gotchas. Pass by reference vs. pass by value semantics for classes is one; the lack of garbage collection is another. Operator overloading allows you to compare apples to oranges. ![]() In general, I think a mathematical background is helpful in terms of being a good programmer, but it won't make you a good programmer. Mathematics will do nothing to prepare you for OOP, which is what C++ is all about. But it's an approachable language. If you have a programming background you will be able to muddle through without killing yourself. |
HERES AN OLD MANS HIP JOINT BEING MADE CNS has gone haywire in the last 10 years. They make some amazing shit. And BTW, if one of those chips jumps down your shirt, you will wish it was .223 brass.
|
Great advice. Syntax is syntax no matter what language so as long as you can grasp the concept, any language is learnable fairly easy. We started off in school with simple basic and qbasic. Since then, learning another programming language has become easier and easier. I've done little in C or C++, mainly in school and that was almost 10 years ago. I wish now I would have leaned more on the programming side rather than the hardware/networking. Hardware is becoming so integraded, hell, most companies have 5 to 10 programmers for ever network admin where 15 years ago it felt like the exact opposite, to me anyhow. Sorry for the hijack. |
+1 - learn the various param rules; pass-by-value v. pass-by-reference & all that. You might get into pointers (a C++ halmark of sorts, though most languages have some form of pointer/mem-addressable implementation), which are simple once you get the hang of them, but they can be elusory unless you stick to it. And recursive function can get interesting. One of the early mind-benders (for me) was trying to implement a rudsimentary algorithm that simulated fractal pattern output using a recursive function. It was a basic console app that displayed patterns of '*' in sequences according to a particular starting pattern, employing an imaging routine via in the recursive function call to create the necessary fractal pattern output. the entire program was primarily this one function; the whole thing being perhaps 1 page worth of code, but it took me most of the damned day just to coime to terms w/ it, which I ultimately did. Probably the most satisfying part of it was going back the next day & finding out that only 5 out of the (still remaining) 17 of us in that class got it working. Gven the natuer of your subject, it'll be interesting to hear just how deeply they delve into the C++ fundamentals. |
Oh wow! I've used the Atmega48/88/168 series (similar?). It's a good chip to learn off of. Programming tiny MCUs is different from programming on a PC. Keep the programs as small and as simple as possible! Best of luck! |
Haven't even gotten to the stage of plugging into it yet. I am just reading the books, copying the code into the editor, just getting used to the feel of the operators, functions, things like that. I wrote a tiny program that calculates how many pills a person on multiple medications should get so they return to the pharmacy in one trip to refill them all at once. My first firmware project is just going to be uploading pre-written code into a simple MCU that flashes LEDs synched with sound. |
Flashing LEDs is the embedded equivalent of "Hello, World\n"! It's where everybody begins. Most people don't learn programming for the purpose of programming microcontrollers. It's pretty nice to see some people doing it. |
Nice to know there's someone on Arfkom I can ask questions to |
|
C++ is easy. I just finished a class in C++. There are a ton of websites to help you with code. When you are studying a language, I recommend you do twice the amount of assigned work. It helps you pick the language up much faster. Write programs on your own for fun, try problems that are posed on the internet. |
Subnet where is your function prototype? Real programmers make their own header files.... C++ isn't that great for math, anyways. |
I beg to differ. By itself, sure. But you can write your own library and define your own operators. Imagine a library that can seamlessly handle the set of all operations on real and complex numbers. It's been done before. A virtual class for all numbers, definitions for reals and complex, and overloaded operators defining the proper behavior. I don't know too many languages, but this is the only one I know of that lets you redefine operators for a class. Once you write your library, the rest is gravy. |
I beg to differ. Going from straight procedural language (like Fortran 77) to an object oriented language is a big conceptual step (assuming that you actually want to use the language to its fullest). Of course, you can write Fortran-esque code in C++ and get it to run, but it's not really C++. |
I'd agree. OOP is it's own thing, but after that, you can pretty much pick up anything. Then you too can get pissed off that multiple inheritence isn't supported, or you can't do operator overloading, or...
|
|
I remember in the early 90's taking a C++ class and I did very good. That was the first and only "programing" class I took. The Prof. (also head of the Computer Science Department) wanted me to change my major, but I had other plans. I found the programing to be very easy to understand, once you got into it. I also found it was very functional. Mike PS: The whole class had to buy new $95 books and were told the bookstore would not buy them back since the class was going to be dropped because the programming was not going to be used any longer. They were wrong. I have seen a lot of discussion about C++ since. |
|
It depends on how they teach it and how your mind works. If they teach traditional step-by-step (calculator) based programming and you are good with math skills in your head and logically steps it will be easy. But if they are teaching Object Oriented programming which this is the ended design purpose of the lastest versions of C++ and C#, some people find object oriented very difficult. It is a separation of form and function. Most people with an engineering mind find it difficult to think in that way. Either way the language itself is easy for most applications. It only gets difficult with the use of the millions of complicated built-in add-ons that are out there. |
C# and vb.net support operator overloading also. I've never needed to do it, but its supported. |
|
