Go to Post By the way, I will be running for office in 2008 .... - Paul Copioli [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

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #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.
  #2   Spotlight this post!  
Unread 09-01-2013, 15:16
BradAMiller BradAMiller is offline
Registered User
AKA: Brad
#0190 ( Gompei and the Herd)
Team Role: Mentor
 
Join Date: Mar 2004
Location: Worcester, MA
Posts: 592
BradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant future
Re: Tweaks to be able to build C++ code from Robot Builder

Quote:
Originally Posted by Bryscus View Post
Guys,
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.
- Bryce
Nice resource you've provided!

I just posted an example of creating the SendableChooser for selecting autonomous programs in C++ at the bottom of this page:

http://wpilib.screenstepslive.com/s/...smartdashboard

Brad
__________________
Brad Miller
Robotics Resource Center
Worcester Polytechnic Institute
  #3   Spotlight this post!  
Unread 24-01-2013, 21:28
nightpool's Avatar
nightpool nightpool is offline
robotRectifier
AKA: Evan
no team (formerly of CORE 2062)
Team Role: Alumni
 
Join Date: Oct 2011
Rookie Year: 2011
Location: Waukesha, WI
Posts: 81
nightpool is on a distinguished road
Re: Tweaks to be able to build C++ code from Robot Builder

Tiny side note, camelCase with a uppercase initial letter can be referred to less ambiguously as PascalCase.
__________________
Proud alum of CORE 2062.
www.core2062.com
  #4   Spotlight this post!  
Unread 28-01-2013, 02:04
jmullins16's Avatar
jmullins16 jmullins16 is offline
Registered User
AKA: Jeff Mullins
FRC #2135 (Presentation Invasion)
Team Role: Mentor
 
Join Date: Nov 2011
Rookie Year: 2011
Location: San Jose, CA
Posts: 23
jmullins16 is an unknown quantity at this point
Re: Tweaks to be able to build C++ code from Robot Builder

For lack of a better place for adding RobotBuilder tweaks, I'm going to pile onto this thread. I'd love to see a dedicated forum for this since it spans Java and C++.

First, RobotBuilder is a fantastic tool, and I hope that teams--especially rookie teams--recognize the value of the software foundation that RobotBuilder can provide. Here are some C++ quirks we found (starting with version r619) that might be avoided by others:

1) Make subsystem names start with capital letters and preferably single words. We initially used lower case names (like chassis) and the default C++ code seemed to use lower case for type names which conflicted with the auto-generated instances of these types.

2) Don't bother to create a battery subsystem for analog input 8--it's already built in somewhere. An error message at runtime will tell you that you are reallocating an existing analog input.

3) When creating a PID subsystem, we got a malformed function name. It can be hand edited as a workaround (each time an export is done).

generated:
return entryShooterEncoder->PidGet();

should be:
return entryShooterEncoder->PIDGet();

4) When adding an initial default command, they must have the "requires" field set to point at the proper subsystem.

5) We were able to working generate C++ from the base .yml config file successfully, but when moving the config file to a new computer it would not generate the exact same set of code. The #include line in subsystems that have an initial default command would not be inserted. Probably due to the fact that that the #include line is outside of the auto-generation markers. In order to work around this, the #includes need to be entered manually (or just copy the exported source code instead of the .yml file).

I will try to enter these on the first forge project for RobotBuilder. Note that the current version is now r623.

Jeff
Closed Thread


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 13:43.

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