c++ and Java
lobo
Posts: 100
Which programming language is more powerful C++ or Java?
If you wanted to make a complex (sensors,video,hands,speech,A.I,ect....) robot which language would be better suited for this job.
By the way, which language was used to control the land rovers or mars rovers whatever they are called on mars?
·Thanks guys for yas response!
If you wanted to make a complex (sensors,video,hands,speech,A.I,ect....) robot which language would be better suited for this job.
By the way, which language was used to control the land rovers or mars rovers whatever they are called on mars?
·Thanks guys for yas response!
Comments
There are problems that C++ can handle efficiently that Java cannot.
The fundamental issue is in object allocation. In C++, you can declare single chunk of memory that contains an array of objects, laid out one after another. In C++, you can declare objects on the stack.
In Java, all objects are allocated from the heap. All object declarations are in truth pointers to objects allocated from the heap. Arrays of objects are arrays of pointers to objects individually allocated from the heap.
And C++ allows you to step in and write routines that control object construction and allocation on a class-by-class basis. Java does not. And, of course, in Java, you have no control over object destruction. The garbage collector does that on whatever schedule it feels like. In C++, you are responsible for object destruction. You can link in a garbage collector on a class-by-class basis, if you think it necessary. But if you need to control when objects are destroyed, you have that control.
In the sort of scientific simulation software that C++ was initially designed for, this difference can make a massive difference in performance. If a program run involves millions of objects being constructed and destroyed, the effiiciencies that are possible in C++ can mean many orders of magnitude difference in run-time.
On the other hand, C++ is a vastly more complicated language than Java. Very much easier to write reasonable-looking code that quietly does the wrong thing. And in something like a robot - sensors, video, hands, speech, etc. - you aren't likely to be using the features of C++ that make it superior to Java.
Unless, of course, you're trying to write your own AI video recognition routines.
Having said that, I strongly believe that microcontrollers are a class unto themselves and that their resident Assembler is the best to handle the particular architectural quirks on a chip by chip basis.
Thus we have Parallax's PBasic and the competitors.
Within that, you have two main schools of thought -- Specific Hardware features versus Software Created Features.
The power and glory of software created features is two-fold. you can do things that appear to be impossibe any other way AND you learn more about the low level details of a microprocessors operation.
For example:
Have you ever wanted to create 13 bit Asychronous transmissions? Well you can with the SXes and Virtual Peripherals. OR 5 bit or 17bit or whatever.
In the end, both Java and C++ will just take up more space and slow down a processor.·· Face the reality that they are intended for big communal corporate programing projects, not finely tuned machines or one off applications
In small embedded processors, speed is achieved by going deeper and deeper into fundamental software levels.
In other words, how low can you go? Or are you afraid to go low?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"When all think alike, no one is thinking very much.' - Walter Lippmann (1889-1974)
······································································ Warm regards,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
Post Edited (Kramer) : 4/5/2006 1:43:15 PM GMT
Higher level languages like C++ and Java assume certain facilities - sizeable stacks, allocatable memory, etc.
On microprocessors these facilities may be limited or absent altogether. So compiler writers are forced to limit the capabilities of the language, and programmers are forced to write in a very different style than they would on a more capable platform.
Higher level languages give you portability - but not on microprocessors, each of which will force its own set of limitations on the language implementation. They give you structures to organize larger software projects - but no microprocessor can hold a large software project. And they isolate you from the specific details of your platform - and with a microprocessor most often you care a great deal about the specific details of your platform.
So few if any of the advantages of higher level languages are relevent to programming microcontrollers.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Happy new year
Code "blote" also affects the VB's in terms of how it's stored and compiled.
Don't misunderstand me, I love the VB's, been using them sence ver 1.0 (DOS), wrote drivers and objects for 2 & 3, worked on the OOP model for 4, moved onwards into my current employment when 5 was released, Owned 6 from RC1, and the .Nets. THe VB's are execlent for OS dependent platforms, but for a micro, nope. IMHO, a dilect basic or asm is best.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Just tossing my two bits worth into the bit bucket
KK
·
It's not whether the processor is embedded in a larger system or not that's at issue, it's what capabilities the processor has.
And while you can fit a JVM on a very small system, compared to what we're seeing on desktops, you can't fit it on a PIC microcontroller with 512 bytes of RAM.
Look at the Javelin Stamp - it implements an extremely limited subset of Java, but it pulls 30 times the current draw as does the Basic Stamp II.
Not to knock it - it's my favorite Stamp. But the best selling of the PIC micros are the smallest and least capable. For the tasks that they're being used for, Java isn't the appropriate answer.
Neither, for that matter, is C++.
As a result, you also begin to see how dependent you are on a higher level languages generalizations. You place yourself in the care and trust of the language's developers and have to beg them for support, pay for revision, wait for improvements and so on.
I have another product that uses a whole Byte to designate True/False. To me in seems to eat RAM 8 times as fast. Is it really a better product if it doesn't have 8 times as much RAM?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"When all think alike, no one is thinking very much.' - Walter Lippmann (1889-1974)
······································································ Warm regards,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
okay yas responses where great and i learned a lot and for that i thank all participants.
So if i want to build a robot with artificial intelligence, vision, speech, legs,hands, walking capabilities, you now like the kind of robots that japan is building that are about 5' tall or more, what processor and language do i use or they use?
please dont be irritated by my questions you are my teachers just want to know.
For motor control with programable autonomy and such, use microcontrollers. But for real data crunching, how about a SBC [noparse][[/noparse]single board computer] such as a 386 or later. These now come in small packages with SDcard interface. The SDcard gives you 1 gigabyte of storage.
It is basically, a variety of systems that apply where they do their best.
In other words, you everything AND use it to it's best advantage.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"When all think alike, no one is thinking very much.' - Walter Lippmann (1889-1974)
······································································ Warm regards,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
Thank you for your response
I guess you could easily go to C++ or Java.
Try the 'Circuit Cellar'
Alternatively, just shop for an older generation laptop motherboard for a Pentenium I or II.
But, I suspect you will have to provide a hefty power supply. Even 275watts is quite a bit for a robot.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"When all think alike, no one is thinking very much.' - Walter Lippmann (1889-1974)
······································································ Warm regards,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
Take a gander:
A Linux-oriented Intro to Embeddable Single Board Computers
You can do a lot, with these.
Even hang a coupld of dozen Basic Stamps off their USB, so as to remain on-topic
Woohoo - section 6, 3rd one down is mine. Fame, of a sort [noparse]:)[/noparse]
(Hmm, the website's down. Wonder what's up with that....)
And, for a bit of obScenix, there's an IO expander board for it that uses an SX28...
Steve
I think for A.I., the most common languages used are LISP and PROLOG.
Rodney Brooks from M.I.T. wrote a book on LISP:
people.csail.mit.edu/brooks/book-covers/lisp.html
I think the students at M.I.T. use various versions of C (not C++) to program their robots:
www.newtonlabs.com/ic/
web.mit.edu/6.270/www/contestants/
I note that this "little" board is described as pulling only one watt.
Which is 300+ times as much current draw as a BS2. (Just to indicate the scale of the difference between an SBC and a microcontroller
I think the guys at Parallax would be highly disappointed if I didn't make that clear.
Multi-tasking often creates unacceptible motion delays.
For instance, and SX-48 might control as many as 32 servo motors or a similarlly high number of H-bridges or a combination and take direction via SPI, I2C, or RS-232.
For less motors, a BS-24p might be all you ever want.
Or, you might try the new Propeller with 8 microcontroller on one chip in parallel.
Meanwhile, the SBC would sort out trying to recognize where to go and what to do.
So you could move and think at the same time.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"When all think alike, no one is thinking very much.' - Walter Lippmann (1889-1974)
······································································ Warm regards,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
(definitely looking forward to a propeller Stamp!)
Steve
There will always be a reason to return to it when battery power is concerned and speed is not so critical.
It is great for solar powered remotes too.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"When all think alike, no one is thinking very much.' - Walter Lippmann (1889-1974)
······································································ Warm regards,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
As far as VB, many would consider that scripting in a GUI rather than programming.
Kramer's point on coding is spot on- you will never get code that is truly 'optimal' without dipping down to the ASM level. Case in point, even PC parts (sound card, video card, etc) almost always have drivers written in ASM- why? Because it's the only true way to get efficient code. Compilers can do quite a bit, and have come a long way, but they will never be as good as going down to the machine level.
The best robotic systems that I've seen have designs that were completed as sub-systems-
On power consumption: look at the BS2 power requirements (or the BS1 for that matter)- it is pretty darn efficient, which helps make battery driven robots run longer-
(Kramer, the BS2 is rated at 3mA run, the BS1 1mA)-
Ryan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Ryan Clarke
Parallax Tech Support
RClarke@Parallax.com