Go to Post Competitions are won or lost far away from witnesses, ... In those long hours, is where we find inspiration in ourselves. For what inspires is not another's feats, but realize we have the power in ourselves to achieve that feat. - Mark Sheridan [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Spotlight this post!  
Unread 29-01-2009, 21:44
Phazonmutant's Avatar
Phazonmutant Phazonmutant is offline
Winrar
AKA: Greg Mitchell
FRC #2556 (RadioActive Roaches)
Team Role: Programmer
 
Join Date: Jan 2009
Rookie Year: 2008
Location: Niceville, FL
Posts: 17
Phazonmutant is on a distinguished road
Understanding the Source code

I'm a pretty proficient programmer (most of my experience is with C#), but I'm still finding myself stumped by some of the source code. I'm hoping that if I understand the source I can implement new classes as necessary and use proper conventions (especially where error handling is concerned).

First question: Macros.
FRC apparently (and inexplicably) has made extensive use of macros. I'm not extremely familiar with them, but they seem to serve many purposes.
The first one I came across: "START_ROBOT_CLASS(IterativeDemo);" at the bottom of the demo class. This references RobotBase.h, which has:
Code:
#define START_ROBOT_CLASS(_ClassName_) \
RobotBase *FRC_userClassFactory(void) \
{ \
	return new _ClassName_(); \
} \
extern "C" { \
	int FRC_UserProgram_StartupLibraryInit(void) \
	{ \
		RobotBase::startRobotTask((FUNCPTR)FRC_userClassFactory); \
		return 0; \
	} \
}
This makes no sense to me. Where is the main() function that would presumably instantiate the robot class? Also, what is this START_ROBOT_CLASS doing exactly?

Second question: Macros. Heh, sorry, I mean Macros that do error handling.
The next major macro confusion is with the "wpi_assert"s and "wpi_fatal"s that are sprinkled across the code. One example in RobotDrive.cpp:
Code:
void RobotDrive::SetInvertedMotor(MotorType motor, bool isInverted)
{
	if (motor < 0 || motor > 3)
	{
		wpi_fatal(InvalidMotorIndex);
		return;
	}
	m_invertedMotors[motor] = isInverted ? -1 : 1;
}
I understand that it's some sort of error code, but how exactly does it work? From the FRC C++ guide, the WPI library doesn't use C++'s exception handling system (for the rather odd reason that an uncaught exception might be thrown - which might happen anyway if there's no push to use exception handling). The only thing that has any macro definitions seems to be the WPIStatus.h file. Relevant section:
Code:
#ifdef WPI_STATUS_DEFINE_STRINGS
#define S(label, offset, message) const int wpi_v_##label = offset; const char *wpi_s_##label = message ;
#else
#define S(label, offset, message) const int wpi_v_##label = offset; extern const char *wpi_s_##label;
#endif
What does that do?? I confess, I'm not very well versed in preprocessor directives, but that doesn't even make a bit of sense to me.

Sorry if this was a lot of questions... Basically, I want to know:
-What happened to main() and what is the START_ROBOT_CLASS macro doing
-How the wpi_assert and _demands handle errors
Reply With Quote
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
need help understanding c code in robotdrive mahmosh C/C++ 14 16-01-2009 08:56
i downloaded the source code, now what do i do? programmr Programming 2 12-12-2008 14:39
Source code for the Easy C Pro library functions? bobpskier Programming 3 05-02-2007 21:39
[FVG]: Source Code SilverStar FIRST-related Organizations 5 24-08-2004 14:28
Patent source code? Kyle Fenton Chit-Chat 3 20-10-2001 17:53


All times are GMT -5. The time now is 12:23.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi