Log in

View Full Version : C or C++


penguain
13-11-2006, 19:50
which programming language is used in the robot for FIRST(FRC)... i see on the web site it says its C.... but my Team coach said it was C++?

some clarity would be helpful

thanks

thegathering
13-11-2006, 19:53
We use C with an IDE called MPLab by Microchip.


*edit* I wish we could use C++ though, then maybe we'd get some more programmers on our team. C tends to scare them off. :( (maybe that's MPLab's icky-sticky interface rather than the language itself :p )

chris31
13-11-2006, 20:11
Its C.

We use C with an IDE called MPLab by Microchip.


*edit* I wish we could use C++ though, then maybe we'd get some more programmers on our team. C tends to scare them off. :( (maybe that's MPLab's icky-sticky interface rather than the language itself :p )

They could always command line compile it. Im sure they would hate that even more.

Kevin Sevcik
13-11-2006, 20:28
I don't think an FRC robot program is likely to benefit from object oriented programming in most cases. We're typically not dealing with a lot of objects that need to be created and destroyed that would benefit from a general class, mainly. There would be some benefit from the probable increase in code modularity and code reuse.

Mostly, however, I think objects inherently incur higher overhead costs than simple structures and procedure calls, what with instantiation and all sorts of things. So I don't think you could take advantage of the strengths of object oriented programming without making your code uselessly large.

thegathering
13-11-2006, 21:07
Mostly, however, I think objects inherently incur higher overhead costs than simple structures and procedure calls, what with instantiation and all sorts of things. So I don't think you could take advantage of the strengths of object oriented programming without making your code uselessly large.
Well, we tried to make our code as object oriented as we could, which ended up working well for our automatically aiming camera/launcher code. :)

X-Istence
13-11-2006, 21:46
We use C with an IDE called MPLab by Microchip.


*edit* I wish we could use C++ though, then maybe we'd get some more programmers on our team. C tends to scare them off. :( (maybe that's MPLab's icky-sticky interface rather than the language itself :p )

The icky interface scared me for a bit. C is an awesome language for embedded systems.

efoote868
13-11-2006, 21:53
just be thankful you don't have to program it in assembly... :P

C works terrific for a robots needs, when I'm trying to help the java peoples learn it, i tell them
"object oriented programming with robots would be kinda useless. For example, what would be the point in
Robot868 robot1 = new Robot868(void);
robot1.drive(10.0);
when you could write code that would simply be drive(10.0)? besides, the interface that Kevin supplies us with is alot more useful."

Too bad its not so easy to describe #define, or any other preprocessors to them :(.

Kevin Sevcik
14-11-2006, 00:21
Well, we tried to make our code as object oriented as we could, which ended up working well for our automatically aiming camera/launcher code. :)

It wasn't C++ code, though, so you didn't have class definitions and a memory manager floating about cluttering things up. You can, of course, still mostly apply object oriented design rules to get more modular, more portable code, but it still won't be C++ code, for good or ill. (Mostly for good)

JamesBrown
14-11-2006, 02:35
We use C with an IDE called MPLab by Microchip.


*edit* I wish we could use C++ though, then maybe we'd get some more programmers on our team. C tends to scare them off. :( (maybe that's MPLab's icky-sticky interface rather than the language itself :p )

Use eclipse, it is much nicer than MPLAB

Also I think C is the easier of the two languages, the things that c++ simplified (Classes Structs etc) are really not important for what we are doing.

RoboMadi
14-11-2006, 06:52
Use eclipse, it is much nicer than MPLAB


Last year, one of our programmers was used to Eclipse, and he pretty much hooked up everyone to use it. Its really nice, especially the way it breaks down the code.
C or C++, as far as writing the code, theres not much of a difference. I'm just waiting when FIRST will upgrade their systems, and we'll have some other language to play with... :rolleyes:
But on a bright note, responsive time for C is much faster than any other language.

MikeDubreuil
14-11-2006, 08:24
I'm just waiting when FIRST will upgrade their systems, and we'll have some other language to play with... :rolleyes:
I hope this never happens. C is a de facto standard in embedded software. In FIRST a good application of C++ is creating a dashboard program.

Stuart
14-11-2006, 10:31
I personaly would like to see a move to C++ . .mainly because I think its easier to think of a robot in terms of objects than not. and for the most part any thing you write in C can be put directly in to C++ with out any changes.

not saying that we take the jump all the way to java, (java.eguals(the.suck())) , but saying that a move to OO would be nice.

Matt Krass
14-11-2006, 14:25
I personaly would like to see a move to C++ . .mainly because I think its easier to think of a robot in terms of objects than not. and for the most part any thing you write in C can be put directly in to C++ with out any changes.

not saying that we take the jump all the way to java, (java.eguals(the.suck())) , but saying that a move to OO would be nice.

C++ would be a pretty hefty extra load on the processor, and for minimal gain. As far as objects go, I've found structs are pretty good, I'm working in my spare time on an object based robot API using all structs, its very doable.

Last year I used very modular code utilizing the same method, well enough I could pick up and move parts of my code in to another teams to help them, with the only change being adding the interface code to theirs. Once they had it, we were able to "plug" code modules in, it was very effective.

♥♣♠♪
14-11-2006, 16:47
Too bad its not so easy to describe #define, or any other preprocessors to them :(.

All you have to do is explain what compilation is and everything else should be easy.

Rickertsen2
14-11-2006, 21:00
I think most of us would agree that we would rather have the flexibility and added features of C++, particularly object oriented-ness.

The problem with C++ is that along with its added features comes added bloat and inefficiency. Unless the architecture and processing power were SUBSTANTIALLY and unnecessarily upgraded, all of the people who keep complaining that C is primitive would be complaining that their code wouldn't run if we upgraded to C++. Memory allocation/deallocation is no small task, especially when handled in software. C++ is good for PCs where functionality is a greater priority over efficiency and there is an abundance of computational power, but not so great for our application. In industry, C is not considered outdated, it is the standard in the world of embedded programming and for good reason. C is sleek and slim.

Heated seats, radios and air conditioning are good to have but race cars don't have them and do just fine without them. Our robots, like race cars are designed minimalistically. There is nothing on a FIRST robot that is not absolutely necessary and that goes for code too.

Any problem that can be solved in C++ can be solved in C. The solution may not be as coder friendly, but chances are it will be smaller and take fewer processor cycles to execute.

Alan Anderson
14-11-2006, 22:43
I think most of us would agree that we would rather have the flexibility and added features of C++, particularly object oriented-ness.
Why? What particular itch would be scratched by having OO in your robot-programming toolkit?
Any problem that can be solved in C++ can be solved in C.
That's obviously true -- because the first implementation of a C++ compiler was as a preprocessor that produced straight C code. If you want to use C++ to program your robot, just get a copy of the old AT&T Cfront program. :P

Kevin Sevcik
14-11-2006, 23:09
Why? What particular itch would be scratched by having OO in your robot-programming toolkit?Well it would let you use << instead of printf's. Heck you could overload << operator to output motor values or set the target of a PID loop or other mostly useless but amusing things, I suppose.

TimCraig
14-11-2006, 23:17
It's amazing the misconceptions that have been posted here about the differences between C and C++. C++ code doesn't have to be bloated compared to equivalent C code. When using the advanced features you do have to know what you're doing if you don't want to pay a size or performance penalty.

I used C for years and then moved to C++. Moving back to C was an extreme shock. Having to jump through hoops to do reasonable encapsulation and using funky naming conventions to keep the code organized and readable is a roaring pain. The lack of proper const types is inhibiting.

Some here seem to think that using C++ entails a lot of new and free calls to create and destroy objects. If your C code isn't using a lot of malloc and free calls, there will be no difference. And for a FIRST robot you really don't need any dynamic memory allocation.

C++ is a much better language and with proper use can even produce smaller, faster code than C. Not to mention if the code is properly written, it's easier to understand, maintain, and more robust.

Gdeaver
15-11-2006, 08:13
I always thought the problem with object oriented languages and microcontrolers was the async nature of OO. In other words OO is terrible for RTOS's.

Alan Anderson
15-11-2006, 08:21
Why? What particular itch would be scratched by having OO in your robot-programming toolkit?Well it would let you use << instead of printf's. Heck you could overload << operator to output motor values or set the target of a PID loop or other mostly useless but amusing things, I suppose.
I was asking about Object Oriented, not Operator Overloading. My question is this: how would object-oriented programming be useful in programming a FIRST robot?

Modular programming is obviously a good thing, but I don't really see a good use for classes and inheritance and polymorphism and such.

Dave Flowerday
15-11-2006, 08:30
I always thought the problem with object oriented languages and microcontrolers was the async nature of OO. In other words OO is terrible for RTOS's.
Actually C++ is quickly gaining in popularity in the embedded world. The last project I worked on at Motorola was almost entirely C++ code running on an embedded control board under the pSOS and OSE RTOSes.

Bongle
15-11-2006, 10:09
Too bad its not so easy to describe #define, or any other preprocessors to them :(.
For #define, I told the kids on my team it is essentially the same as a find-replace on your code before it actually gets compiled. That explanation is good enough for what we used it for (#define leftMotor1 pwm01).

TimCraig
15-11-2006, 12:48
I always thought the problem with object oriented languages and microcontrolers was the async nature of OO. In other words OO is terrible for RTOS's.

Object oriented languages aren't any more asynchronous than purely procedural languages. If you're talking about the message passing paradigm, that's just OO speak for function calls.

That said, however, most microcontroller programs have to deal with asynchronous events.

chris31
15-11-2006, 15:40
http://www.virginiafirst.org/workshop_info.shtml

I figure it just a typo but look at "Beginning Programming - part 1". Maybe they know something we dont know. Im pretty sure its a typo though.

X-Istence
15-11-2006, 15:46
I screw it all. Let's go back to the PBASIC boards from a few years ago.

chris31
15-11-2006, 18:47
I screw it all. Let's go back to the PBASIC boards from a few years ago.

LOL. I have never used to PBASIC boards but I like the C ones just fine.

Astronouth7303
15-11-2006, 21:34
I'm going to try to clarify somethings about using OOP on the current breed of controllers.

Using any kind of memory management on the PIC18s would incur a performance penalty in terms of pointers, indirect addressing, management overhead, etc. I don't care how few malloc()/free() calls there are; it only takes one. In order to perform indirect addressing, you have to copy the pointer to a special register. Every dereference requires this, on a byte-by-byte basis. I'm not even sure you can perform an indirect function call. (Remember, code is stored seperate from data.)

I agree that using OOP principles is a Good Thing(tm). But the limits of the PIC18 processors are such that full-blown OOP (or even just objects) as it is normally implemented is impractical.