go away spammer

Author Topic: C or C++  (Read 2672 times)

0 Members and 1 Guest are viewing this topic.

Offline Private ReidTopic starter

  • Robot Overlord
  • ****
  • Posts: 272
  • Helpful? 0
  • I love apples ... Yum !!!
C or C++
« on: March 15, 2008, 10:43:10 PM »
Ok, im not 100% sure that this question should be posted here, but I don't know where else it's supposed to go :-\

Can I program a robot in "C" or "C++"?
What is the difference?
 ???

Offline siempre.aprendiendo

  • Jr. Member
  • **
  • Posts: 32
  • Helpful? 0
    • Always learning
Re: C or C++
« Reply #1 on: March 16, 2008, 03:25:59 AM »
They are two different languages, but the basic syntax of C++ (as Java, C#,...)  is very similar to C.

The C language support the structured programming paradigm.
C++ (and Java, C# and others) support object oriented programming and structured programming. Some features of C++ (exceptions, STL library,...) require more memory than C, so usually is not fully supported by the compilers used to program microcontrollers.

Offline Kohanbash

  • Supreme Robot
  • *****
  • Posts: 430
  • Helpful? 1
Re: C or C++
« Reply #2 on: March 16, 2008, 08:49:20 AM »
You can use either one.

If you are using a micro than you probably want C.
If you have a computer on board than you can use either (C++ is better for advanced navigation/planning code)
Robots for Roboticists Blog - http://robotsforroboticists.com/

Offline JesseWelling

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 707
  • Helpful? 0
  • Only You Can Build A Robot!
Re: C or C++
« Reply #3 on: March 16, 2008, 12:41:54 PM »
Keep in mind that even if you don't have to it is still a good idea to follow object oriented design while using C. At work we build it up in levels.

  • Hardware Layer. Define all the basic hardware you are going to use, Making structures for Digital Inputs, Outputs, Analog channels, and PWM channels, Serial, I2C, and make the functions that take those structures as a parameter and do something to them or return a measurement.
  • Signal Layer. This is where you turn the raw inputs in the Hardware Layer into engineering terms such as a Distance Sensor, LED, Motor Command, Servo Command or Quadrature Input.
  • Application Layer. This is where you write your robot code using the Signal Layer. Since you have abstracted the Application code from direct Hardware it will require less changing should you change a sensor, instead you will just have to change the way the signal layer interprets the input or output.

It may seem like a waste of time, but once you get the Hardware Layer and some of the Signal layer done, making your second Robot will go a lot faster.


« Last Edit: March 16, 2008, 12:43:09 PM by JesseWelling »

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
Re: C or C++
« Reply #4 on: March 18, 2008, 12:14:09 PM »
So if I want to program in C++ using AVR Studio then does anyone know what I need to change in my makefile etc. Had a look at the AVR Freaks web site but there doesn't appear to be a simple answer. The free gnu compiler appears to have come from the Unix world so a lot of the comments are confusing for a mere Windows user. Have many years of experience with MS Visual C++ so its not the coding that confuses me - its how you get AVR Studio to work - it currently throws out errors about my class definition even for a simple 'blank' class eg
Code: [Select]
class Fred {
public:
Fred();
virual ~Fred();
}

gives the following errors in the build
Code: [Select]
Compiling: 8Mhz_Webbot.c
avr-gcc -c -mmcu=atmega8 -I. -gstabs   -O0 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=8Mhz_Webbot.lst  -std=gnu99 -Wp,-M,-MP,-MT,8Mhz_Webbot.o,-MF,.dep/8Mhz_Webbot.o.d 8Mhz_Webbot.c -o 8Mhz_Webbot.o

8Mhz_Webbot.c:9: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'Fred'
make: *** [8Mhz_Webbot.o] Error 1
Build failed with 1 errors and 0 warnings...
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: C or C++
« Reply #5 on: March 27, 2008, 02:23:20 PM »
I'm not entirely sure, but I believe that the gnu compiler cannot handle many of the C++ commands . . . I think the problem is where you say 'public:' in your code - it doesn't recognize it.

 


Get Your Ad Here

data_list