Go to Post Having a spare arm that you can put on in 5 minutes or less intimidates the hardware into not breaking. - ChrisH [more]
Home
Go Back   Chief Delphi > Technical > Programming
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 09-01-2013, 13:42
Bryscus's Avatar
Bryscus Bryscus is offline
EE, CpE
AKA: Bryce B.
FRC #0180 (SPAM)
Team Role: Engineer
 
Join Date: Jan 2009
Rookie Year: 1999
Location: Jupiter, FL
Posts: 173
Bryscus has much to be proud ofBryscus has much to be proud ofBryscus has much to be proud ofBryscus has much to be proud ofBryscus has much to be proud ofBryscus has much to be proud ofBryscus has much to be proud ofBryscus has much to be proud ofBryscus has much to be proud of
Tweaks to be able to build C++ code from Robot Builder

Guys,

I've gone through the Robot Builder videos on youtube and was coding along with them, but in C++. I noticed a couple of things that might trip some coders up so I thought I'd post my findings. The generated codes always seems to build fine, but when adding methods and coding command sets there are some things to be wary of:

1. Case is slightly different for C++ methods than in Java. C++ seems to be camel case starting with a capital letter and Java seems to be camel case starting with a lower case letter.

Code:
SetTimeout(1);
IsTimedOut();
2. Accessing methods/members from classes is different. In this C++ code, everything is a pointer, so access is made with "->" rather than a ".". Also, when accessing a subsystem from the robot, "Robot::" is required before the system name.

Code:
Java: Robot.claw.close();
C++: Robot::claw->close();
3. If/when creating methods for a class (normally a subsystem class), the function prototype must be added to the header (.h) file of the same name. Also the class name follow by "::" must proceed the method name.

Code:
//In Claw.h
class Claw: public Subsystem {
private:
	// It's desirable that everything possible under private except
	// for methods that implement subsystem capabilities
public:
	// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=DECLARATIONS
	SpeedController* motor;
        // END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=DECLARATIONS
	Claw();
	void InitDefaultCommand();
	void open();
	void close();
	void stop();
};


//In Claw.cpp
void Claw::open(){
	motor->Set(1);
}
4. When using commands in another class (such as a command set) the headers for those commands need to be included.

Code:
//In DeliverCylinder.cpp
#include "DeliverCylinder.h"

#include "PreparetoPickup.h"
#include "Pickup.h"
#include "Place.h"
#include "RaiseWrist.h"
#include "CloseClaw.h"
#include "DriveToPlatform.h"
#include "Backup.h"

DeliverCylinder::DeliverCylinder() {

	AddSequential(new PreparetoPickup());
	AddSequential(new Pickup());
	AddSequential(new DriveToPlatform());
	AddSequential(new Place());
	AddParallel(new Backup());
	AddSequential(new RaiseWrist());
	AddSequential(new CloseClaw());
}
5. Some else noteworthy: Keep in mind that there are auto-generated code areas. Brad talks about these in the videos. If you write code in these areas and then in the future regenerate code from Robot Builder you will loose code between these comments.
Code:
// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=REQUIRES
	Requires(Robot::claw);
// END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=REQUIRES
6. When regenerating code, Robot Builder will often create a backup of the file it replaced. It will end in a "~".


I've attached the C++ version of the project code just in case the examples above are incomplete. The code builds (I can't test whether is executes since I don't have his platform) and appears to be correct but peruse it at your own risk. The only thing missing is one of the last steps which is casting "autonomousModes->GetSelected();" to a "Command" type. This doesn't work in C++ and I don't yet have a solution.

Good luck.

- Bryce

EDIT: The project is now building fine thanks to Brad's example below (above depending on how you have your posts situated). I've updated the zip.
Attached Files
File Type: zip TestProject.zip (38.0 KB, 16 views)
__________________
The opulence of the front office decor varies inversely with the fundamental solvency of the firm.

Last edited by Bryscus : 09-01-2013 at 16:34.
 


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


All times are GMT -5. The time now is 22:49.

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