17

Greetings,

I am trying to decide between C and C++ for my robot. I am a 5+ year veteran of Visual Basic.NET, however I'm going with Linux (Ubuntu) on this robot, and there is a compatibility problem between Linux and the .NET Framework. I want to stick with whichever language I choose for all of my projects, so I want to make sure that I choose the most appropriate one for the task. For reference, I will describe my current robot in progress and what I am going to do with it. I am in the process of building a full-sized R4 Astromech (yep, I'm one of those guys). I have incorporated a PC motherboard with an Intel Core 2 2.1 GHz processor, 1 GB RAM. I will be using a scratch-built parallel interface card to control the drive motors, head motor, as well as a secondary parallel interface card (going to a second parallel port) which all of the sensors (IR, Ultrasonic Ranging, Visual Recognition via webcam, etc.) will be going to. Commands will be given using speech recognition (currently have a VB.NET scratch-built recognition program that I will be adapting to the new language). Given the specifications and desired goals listed above, would I be better off with C or C++? I greatly appreciate any suggestions that you might have. Thanks! Thaskalas

Thaskalas
  • 171
  • 1
  • 3
  • IMHO, learning C will be easier than learning C++. I would start there. – James Feb 11 '11 at 20:51
  • 12
    Use C++. You'll find the object oriented environment more familiar, and you'll have far less work to do. If you were using a 4MHz microcontroller you might have to think twice, but here it's hardly an issue. I'd almost go as far as suggesting Java. – Hannesh Feb 11 '11 at 20:54
  • 1
    @Hellfrost What's your problem with VB.net? While I prefer C# that's just a stylistic choice. – CodesInChaos Feb 11 '11 at 20:56
  • 1
    which language is the most appropriate for the task? -- the one you know of course; unless you want to spend a few years learning a new language before starting with the task. – Gene Bushuyev Feb 11 '11 at 20:57
  • 2
    Edwin's answer got deleted, but I wanted to chime in. Yes, C++ compilers give much better error messages on C code. Complaining about template error message shows you missed the point, C code doesn't cause template error messages. The improved type-safety of the C++ compiler (and requirement for accurate function prototypes) catches a LOT of errors in C code. – Ben Voigt Feb 11 '11 at 21:41
  • To expand on Gene's answer: Stick with what you know until it actually doesn't perform up to the task. It doesn't matter how many people say some other language is better if the one you're using does the job fine, and if what you're using doesn't do the job, figure out why, and that will direct your search for a better tool. – Mike DeSimone Feb 11 '11 at 21:48

7 Answers7

8

What do you mean by a compatibility problem? Have you looked at Mono? It's an open-source implementation of the .NET libraries. It's geared toward C# not VB.NET but if you're more comfortable in a .NET environment use that. Speed isn't really an issue here as a Core2Duo is plenty fast for what you need to do.

If Mono won't work for you, I'd recommend C++. There are a lot more libraries out there for C++ (or at least, I am familiar with more, e.g. Boost), which can use most C libraries too. There's no real speed penalty for using C++. While using C wouldn't be bad per-se, C++ has some benefits and no drawbacks, so it's probably the better choice.

Miles Strombach
  • 308
  • 1
  • 11
  • Thanks everyone! I appreciate all the suggestions. I did check out Mono, and even though it is primarily designed for C#, it does have the VB.NET complier. As a couple of people suggested, I'll stick with what I know. Thanks again everyone! – Thaskalas Feb 11 '11 at 21:21
  • 1
    @Thaskalas: If you like this answer best (or any other answer), make sure you click on the checkmark underneath the voting tally to "accept" the answer and show that you think it's the best! :-) – Platinum Azure Feb 11 '11 at 22:49
  • 2
    C++ isn't a superset of C, might want to say "mostly a superset" – alternative Feb 11 '11 at 23:34
1

I would recommend using ROS. It will let you get started with a sophisticated Inter-Process Communications manager, as well as a large library of sophisticated robotics code, including multiple implementations of SLAM and other critical robotics algorithms. ROS also lets you program in multiple languages, including C, C++, and Python, so you aren't stuck with one language or another down the road.

Bradley Powers
  • 717
  • 7
  • 19
1

I would also recommend C++ and ROS. In our company we're migrating to it, because there's so many people working on it, expanding it, and adding lots of cool features.

With this, you can forget about implementing most of the basic low-level stuff and start working on what you intend to research.

It's really easy to set up and start developing.

Victor
  • 348
  • 2
  • 12
0

Since you're running Linux on it, I'd recommend a split approach, where you do the lower-level (device interface, where you may need fast performance) stuff in C (or C++), and the higher level stuff in a modern language like C# (using Mono) or Java, or even Python.

Python especially is hugely expressive, has a large set of libraries, and has a pretty straightforward C interface.

Writing your high-level control stuff in a low-level language like C/C++ will get old fast (IMHO). Robots should be fun!

payne
  • 13,833
  • 5
  • 42
  • 49
  • Ouch, calling C++ non-modern? – GManNickG Feb 11 '11 at 21:05
  • Yea, sorry about that. After all, it was designed in the 80s. – payne Feb 11 '11 at 21:07
  • 1
    It's bee updated multiple times since. Initial design time has nothing to do with modern or not. Boolean algebra was first described in 1854, all our programs are old! – GManNickG Feb 11 '11 at 21:39
  • 1
    Of course! But even updates are constrained by backward-compatibility requirements. My point was admittedly subjective, but most of the people I work with would consider the current incarnations of Pytyhn+Ruby and Java+C# to be "modern" relative to C++. That's all. – payne Feb 11 '11 at 21:45
0

Have you considered D? It's a fairly new language, is compiled to native code and can link directly to C. (The entire C standard library is even available from D, and bindings to the POSIX API are included in the standard library.) Basically all you need to do to use any C library from D is compile it with a C compiler and translate the function prototypes, constant declarations, etc. in the header file.

D is low-level enough that an experimental kernel is written in it, but has modern features like garbage collection (though manual memory management is still permitted), builtin strings and arrays, and more advanced/easier to use template metaprogramming facilities than C++. The biggest disadvantage is lack of a mature toolchain and libraries for enterprise-y things, but for your purposes that probably doesn't matter. BTW, if you need to do a bunch of matrix manipulation and stuff, there's the SciD project, which provides nice templated wrappers over LAPACK and BLAS.

dsimcha
  • 67,514
  • 53
  • 213
  • 334
0

Use C++. You have the space. You can use it "as a better C" to start with.

James Crook
  • 1,600
  • 12
  • 17
0

C++ is a bigger tool bag; why would you not want that!? You need not use all the tools, but with C you'd have no choice. Most importantly with C++ you have the choice of using both C and C++ third-party libraries.

Clifford
  • 88,407
  • 13
  • 85
  • 165