|
|
|
![]() |
|
|||||||
|
||||||||
|
|
Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
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(); Code:
Java: Robot.claw.close(); C++: Robot::claw->close(); 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);
}
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());
}
Code:
// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=REQUIRES Requires(Robot::claw); // END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=REQUIRES 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. Last edited by Bryscus : 09-01-2013 at 16:34. |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|