Shop OBEX P1 Docs P2 Docs Learn Events
c++ and Java — Parallax Forums

c++ and Java

lobolobo Posts: 100
edited 2006-04-07 14:55 in General Discussion
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!

Comments

  • Jeff DegeJeff Dege Posts: 85
    edited 2006-03-31 15:32
    C++ is a general purpose programming language, Java is not. C++ was designed to provide a number of facilities to the programmer, but it was not intended to force any particular style. Java was designed to be a purely object-oriented language.

    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.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2006-04-05 13:39
    Neither C++ 'a general purpose language' nor Java 'a object oriented languge' was ever intended for a microcontroller that individually controls BITS.

    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
  • Jeff DegeJeff Dege Posts: 85
    edited 2006-04-05 17:09
    I don't disagree with you.

    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.
  • KB3JJGKB3JJG Posts: 95
    edited 2006-04-05 22:59
    The answer to your question about the Mars rovers is JAVA, it is also used all over the world in embedded systems. For instance, a large portion of the weapons systems used by the US government are controlled by systems built on JAVA. Embedded versions of java are everywhere, your car, your coffee maker, the jukebox at the local bar and so on and so forth.
  • BatmanBatman Posts: 93
    edited 2006-04-06 01:13
    what about VB?and VB.net

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Happy new year
  • Kaos KiddKaos Kidd Posts: 614
    edited 2006-04-06 02:45
    The VB's require runtimes to execute (excluding VB 6, which compiles into standalone conde), which is not condusive for a micro controll.
    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
    ·
  • Jeff DegeJeff Dege Posts: 85
    edited 2006-04-06 04:00
    KB3JJG said...
    The answer to your question about the Mars rovers is JAVA, it is also used all over the world in embedded systems.

    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++.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2006-04-06 07:04
    Essentially IMHO, the smaller the architecture, the lower you should go in programming.

    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
  • lobolobo Posts: 100
    edited 2006-04-06 08:02
    but what does mit use for their artificial intelligence robot? pbasic, VB, or what?

    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.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2006-04-06 08:29
    If you really want artifical intelligence, I suppose a hybrid system is useful.

    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
  • lobolobo Posts: 100
    edited 2006-04-06 09:06
    where can i get one of thoes (386 and SDcard interface)? and what programming language is used to program them?
    Thank you for your response
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2006-04-06 16:19
    Google is your friend. Try 'Single Board Computer'.
    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
  • Jeff DegeJeff Dege Posts: 85
    edited 2006-04-06 17:37
    lobo said...
    where can i get one of thoes (386 and SDcard interface)?

    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 smile.gif
  • SteveWSteveW Posts: 246
    edited 2006-04-06 18:09
    >A Linux-oriented Intro to Embeddable Single Board Computers

    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
  • XNORXNOR Posts: 74
    edited 2006-04-06 20:34
    lobo said...
    but what does mit use for their artificial intelligence robot? pbasic, VB, or what?

    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.

    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/
  • Jeff DegeJeff Dege Posts: 85
    edited 2006-04-06 20:40
    SteveW said...
    Woohoo - section 6, 3rd one down is mine. Fame, of a sort [noparse]:)[/noparse]

    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 smile.gif
  • lobolobo Posts: 100
    edited 2006-04-06 23:40
    Wow it just gets better Thanks guys. Keep it coming i'am at warp speed.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2006-04-07 07:12
    I proposed this as a 'hybrid' solution. While you may use an SBC for many cognitive functions, the microcontroller can do wonders as both physical control of the motor and a communications clearing house.

    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
  • SteveWSteveW Posts: 246
    edited 2006-04-07 09:25
    Yeah, BS2 is a damn good proposition for low power. It's rather less than 1/300 of the speed, though - there's an economy of scale to be had. Balloon3 is rather more efficient, and faster still, in the way that these things improve over time...
    (definitely looking forward to a propeller Stamp!)

    Steve
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2006-04-07 14:53
    The true beauty of the good original BS2 is that it only takes 5 or so ma to operate.

    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
  • Ryan ClarkeRyan Clarke Posts: 738
    edited 2006-04-07 14:55
    MProbo is correct, LISP (and to some extent PROLOG) are the languages most often used in AI (or what I like to call pseudo AI) systems.
    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
Sign In or Register to comment.