View Single Post
  #7   Spotlight this post!  
Unread 29-10-2008, 23:32
AustinSchuh AustinSchuh is offline
Registered User
FRC #0971 (Spartan Robotics) #254 (The Cheesy Poofs)
Team Role: Engineer
 
Join Date: Feb 2005
Rookie Year: 1999
Location: Los Altos, CA
Posts: 800
AustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond repute
Re: Team 67 C++ Example Code

Quote:
Originally Posted by Tom Line View Post
I'm sure I'm missing something since the whole class / pointer system is new to me. But I'm struggling to see a reason to program using them as opposed to using functions and returning values. This is probably just because I haven't gotten into the level of complexity where they become useful.
With C++, it starts becoming useful when you get into inheritance, and all the other OOP stuff. I haven't checked the new WPI c++ libs to see if this is a valid example, but a Victor class and Jaguar class could both inherit a motor controller class, and everywhere in your code where you manipulate an instance of a motor controller, it could really be an instance of a Victor class or a Jaguar class, and you don't have to know. So you could swap out your Victor for a Jaguar, change 1 line in your code where you create an instance of the class, and all your other code using the motor controller would still work (providing victors and jaguars don't have that different electrical characteristics).

Pointers are also available in last year's code also, but they weren't used much since you couldn't really allocate memory, and didn't have a need for it. I believe my team used pointers to pass in a structure containing our PID constants and the variable storing up the data to use for the I part of PID and the D part of PID. The function would return the motor power and update the structure.

If there was a C library available for the bot, we could easily program everything without pointers or structures, so most of this isn't exactly necessary, but instead allows us to do more. My personal opinion is that you can do everything you need to in C with pointers and structures, and not need classes, but it takes a bit more thinking and planning.
Reply With Quote