Author Topic: Tutorial on C++ for $50 Robot (and beyond?)  (Read 26305 times)

0 Members and 1 Guest are viewing this topic.

Offline WebbotTopic starter

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
Tutorial on C++ for $50 Robot (and beyond?)
« on: May 04, 2008, 08:50:15 PM »
Dear Members,

Have posted a tutorial on using C++ with the $50 Robot along with the source code for a generic C++ library and an example of using it for the $50 Photovore.

See:-

http://www.societyofrobots.com/member_tutorials/node/108


I welcome any feedback, positive or negative, on instructions and clarity but lets limit it to the $50 Robot component part list for now -e ATMega8, HS311 servos etc. Equally this isn't the forum to debate the plus and minus of programming languages, chipsets etc. It does what it does.

This does everything for the $50 Photovore and I'm currently working on code for UART, serial LCD, Sonar, Sharp IR which won't take long. My code will implement specific make/model of these devices and it would be great if you could contribute code for other makes/models over time. There have been several posts recently about member collaboration to work on larger projects and am happy to take the lead on this baby of mine. So any contributions, questions, etc that come thru me, and 'make  the grade' will be considered for future releases of the library. But thats the future.

So for now - can you let me know your experience with this release. Can you make it work? If not why not? If yes - then what do you think? Are you new to C++? etc etc

Keep it coming

Webbot
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline Kohanbash

  • Supreme Robot
  • *****
  • Posts: 430
  • Helpful? 1
Re: Tutorial on C++ for $50 Robot (and beyond?)
« Reply #1 on: May 04, 2008, 10:27:01 PM »
Hey
Nice tutorial, It was easy to read and the classes seem useful.
Also I like how you addressed C programmers (like myself)
Robots for Roboticists Blog - http://robotsforroboticists.com/

Offline Private Reid

  • Robot Overlord
  • ****
  • Posts: 272
  • Helpful? 0
  • I love apples ... Yum !!!
Re: Tutorial on C++ for $50 Robot (and beyond?)
« Reply #2 on: May 05, 2008, 03:04:37 AM »
nice...

Very nice...

Really Good...

10 out of 10...

100%

A+


Offline pomprocker

  • Supreme Robot
  • *****
  • Posts: 1,431
  • Helpful? 16
  • Sorry miss, I was giving myself an oil-job.
    • Nerdcore - Programming, Electronics, Mechanics
Re: Tutorial on C++ for $50 Robot (and beyond?)
« Reply #3 on: May 06, 2008, 12:04:24 PM »
For the (and beyond) part, I recommend we go with Java micro edition. Java is very portable, and uses OOP like C++

Offline WebbotTopic starter

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
Re: Tutorial on C++ for $50 Robot (and beyond?)
« Reply #4 on: May 06, 2008, 02:18:59 PM »
For the (and beyond) part, I recommend we go with Java micro edition. Java is very portable, and uses OOP like C++

Well my 'day job' is Enterprise Java Beans/Oracle/AppServers etc so I know it well - and 'yes' I prefer it to C++. But since Java is normally an interpreted language then wouldn't this limit us to controllers with a built in Java runtime interpreter chip like the Javelin Stamp? Haven't really looked into it so would welcome your views.

The other consideration is that this tutorial was to build on the $50 Tutorial which is all in C and so the jump to Java may be 'a bridge too far' - but am open to thoughts from the forum SO LONG AS it includes feedback from 'newbies' as well as 'Java Overlords'   ;D If Java gets the vote then lets scrap C++ and go with Java - if that is the generally held view.

Obviously everyone has their own 'pet' chip set and their own 'pet' language - and this does make sharing software difficult and maybe Javas portability could help this. However: there is a big distinction between compiling the code to work on many platforms and the physical differences between chips and what ports/bits in what registers do what. Personally, I think this is where some of the collaboration over certain SoR projects fall down ie if someone has written something 'great' in BASIC for a PICAXE, say, then its very hard for newbies to turn this into C on an AT Mega8. So our software posts only have a 10% audience.

This is why I have targeted the $50 Robot by extending from C to C++ - its not such a great leap. But, in an ideal world, the lead developer in one language would have other members to back them up and translate the library into all the main architectures/languages to try and keep them in step. Now that would be cool - but is beyond the bounds of  my 'free time' etc.

Thanks for the input folks - keep it coming....
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline pomprocker

  • Supreme Robot
  • *****
  • Posts: 1,431
  • Helpful? 16
  • Sorry miss, I was giving myself an oil-job.
    • Nerdcore - Programming, Electronics, Mechanics
Re: Tutorial on C++ for $50 Robot (and beyond?)
« Reply #5 on: May 06, 2008, 03:52:30 PM »
I found MacAVR by these same people early...here is this...

http://www.harbaum.org/till/nanovm/index.shtml

Offline WebbotTopic starter

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
Re: Tutorial on C++ for $50 Robot (and beyond?)
« Reply #6 on: May 06, 2008, 06:03:42 PM »
I found MacAVR by these same people early...here is this...

http://www.harbaum.org/till/nanovm/index.shtml

Thanks for the link - very interesting. But the initial image confirms my suspicion:



So the 8k of Flash Memory (actually just under) is used by the JVM (ie the Java runtime interpreter) and you only get 512 bytes of EPROM for your program. So on an 8k chip you don't have much space for your application! I appreciate that Java apps compile to a very small size (since they are pseudo-code) but, even so, not much left to work with. Practically I think that this means you would need to standardise on bigger, say 32k, chips and hence the higher $ entry point which counteracts my wish to aim for the 'low entry' '$50 Robot' folk. The other complication for new-2-Java folk is that they would also need to download and install any new revisions of the JVM. And this is the big hassle with any interpreted language like Java and most BASICs: bugs can be in your code or in the currently installed 'language'. I seem to spend my 'real life' downloading new JDK's, JRE's and versions of other browsers and 3rd party stuff and then have to re-test what works with what.

So a benefit of C or C++, even though I prefer Java, is that they are compiled (ie they do what they do) whereas sometimes Java can do 'not what they do' depending on JVMs etc.


Not wanting to plunge the dagger further into the back of Java but I've also thought about the following.

Java is great in a commercial world where you can compile a program once and then send the executable to people who may run on it on Windows, Mac, Unix etc without ANY modification - which is great. But in a microcontroller world I doubt if there would be any point in me sending someone some Gargantuan128 code and expecting it to run on their AT Mega8 - as the IO would be different, I have 20 UARTs but they have 1, I have 39.5 timers working at 128 bit resolution and they have 3 working at 8 or 16 bit. IE in mcu speak we tend to be working at a very low level.

So the only way around it is to build a low-level I/O abstraction layer (ie an Operating System!) that makes various hardware look the same, or if not, then report its own capabilities so that the layers above can re-act accordingly. Hhhmmm - may not be $50 Robot kinda code .....

I'd love to do stuff in Java but just ain't sure mcu's have enough uumph!
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline WebbotTopic starter

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
Re: Tutorial on C++ for $50 Robot (and beyond?)
« Reply #7 on: May 09, 2008, 08:16:11 PM »
Thanks to all for the responses - especially the  'A+' for 'C++' ;)


Have now got a new version with support for:
- generic UART control
- logging output to LCD - currently any kind of Matrix Orbital serial LCD
- sonar - Dynatech SRF-05

Will release it into the the Forums once its bottomed out.

Sound like any use to anyone? (Hello - is anyone out there ......)

NB I cant afford to buy all the other LCD and Sonars available so would be good for others to contribute (if not code then details of the device, spec sheets etc ).

The good thing about adding extra stuff is that I have to write some test code. So each of these makes a logical extension to the $50 Robot - ie an SRF05 Sonar 'Bot etc.

Anyone got any pressing hardware support that is required and within my budget (so no satellite controllers!) ?
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: Tutorial on C++ for $50 Robot (and beyond?)
« Reply #8 on: May 23, 2008, 09:46:48 PM »
I just added your tutorial (and this forum post) to the $50 Robot page.

Offline superchiku

  • Supreme Robot
  • *****
  • Posts: 952
  • Helpful? 5
  • cooll
Re: Tutorial on C++ for $50 Robot (and beyond?)
« Reply #9 on: May 23, 2008, 10:11:37 PM »
anyone needs java tutorial i can do that for you people
JAYDEEP ...

IT AND ROBOTICS ENGINEER

"IN THE END IT DOESNT EVEN MATTER"

Offline Private Reid

  • Robot Overlord
  • ****
  • Posts: 272
  • Helpful? 0
  • I love apples ... Yum !!!
Re: Tutorial on C++ for $50 Robot (and beyond?)
« Reply #10 on: May 24, 2008, 07:39:10 PM »
Yer...

why not!

 ;)

Offline santiago

  • Jr. Member
  • **
  • Posts: 32
  • Helpful? 0
Re: Tutorial on C++ for $50 Robot (and beyond?)
« Reply #11 on: June 21, 2008, 10:38:50 PM »
As far as i know micontrollers programed in C is better.

Offline WebbotTopic starter

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
Re: Tutorial on C++ for $50 Robot (and beyond?)
« Reply #12 on: January 03, 2009, 01:19:17 PM »
This has now been updated to include more features .... http://www.societyofrobots.com/robotforum/index.php?topic=6356.0
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline Rebelgium

  • Supreme Robot
  • *****
  • Posts: 637
  • Helpful? 0
  • It's called the future ... We like it here
    • orgcrime.net
Re: Tutorial on C++ for $50 Robot (and beyond?)
« Reply #13 on: January 03, 2009, 02:26:37 PM »
Is it possible to use C++ on a OOPic?
I know C++, and I know OOPic are Object Oriented PICs... :P

That would be great to use on robots! Advanced OO code, but still on a supersmall lightweight µC... ;D

btw,
I really prefer C++ over Java (I know both pretty good) for programming robots.
C++ is much lighter and uses less resources, which is obviously a big issue in robotics.
To relax after some hard work on robotics: A very fun free online text based MMORPG
orgcrime.net

Offline Ro-Bot-X

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,431
  • Helpful? 25
  • Store: RoBotXDesigns.ca
    • Ro-Bot-X Designs
Re: Tutorial on C++ for $50 Robot (and beyond?)
« Reply #14 on: January 03, 2009, 10:57:59 PM »
OOpic can be programmed in Basic, C and Java. This is because code is interpreted, not compiled. This slows it down pretty much. Also, on the Flash there is the firmware that does the interpretting and your code gets loaded in the EEPROM, so program space is a lot smaller. I gave up on this board when I coudn't use the Ping sensor with it (can't generate a 3us trigger signal).
Check out the uBotino robot controller!

Offline Rebelgium

  • Supreme Robot
  • *****
  • Posts: 637
  • Helpful? 0
  • It's called the future ... We like it here
    • orgcrime.net
Re: Tutorial on C++ for $50 Robot (and beyond?)
« Reply #15 on: January 04, 2009, 06:40:29 AM »
oh,  too bad.
Are yousure you can't run compiled code on an OOPic, instead of interpreted code? I don't understand why this wouldn't be possible...
Or maybe they intended to run the compiled C++ code on normal PICs... What would be best PIC18? PIC24 or maybe even PIC30 ?
To relax after some hard work on robotics: A very fun free online text based MMORPG
orgcrime.net

 


data_list