This is the newbie alert for anyone who is very knowledgeable in C++. ANY C++ PROGRAMMERS ARE ENCOURAGED TO VISIT AND REPLY IN THIS THREAD. IF YOU ARE A PROGRAMMER FOR C++ AND CAN HELP, PLEASE DO SO
I was kind of thrust into the job of programmer for this year’s 2012 FRC. Things worked out pretty well for the FTC because we were using ROBOTC and I could therefore use shortcuts like “catalysts” to take care of everything an experienced programmer can usually do, but because FRC robots don’t use ROBOTC as a programmable language, I have to start from scratch and get a workable program set up before mid-March, preferably before the end of February.
I think I can officially say I have no idea what I’m doing. If anyone who knows a lot about Wind River and C++ is within the sight of my text, I implore you to help a fellow programmer figure out what to do.
A simple program to run arcade mode and a couple of motors on a Logitech controller for the Teleop program, basic robot-programming related Wind River info (such as where the compiler is and where I go in the program to see my lines of code)… Anything would be extremely helpful right now, preferably an arcade tank drive program at least.
Many thanks from Team 1691,
–Gondorf5–
The ultimate swordsmaster is NOT the ultimate programmer for C++
If you have installed the software (in KOP) properly you should find a very simple drive template. GoTo (from the main compiler screen): "File -> New -> Example… ->-> VxWorks Downloadable Kernel Module Sample Project -> -> FRC Simple Robot Template.
This demonstrates declaring 1 joystick and driving forward during Autonomous and driving Arcade for Teleop.
Start with a sample program that’s provided with WindRiver (assuming you have installed the workbench update for FIRST). I don’t have WindRiver in front of me, so I am reciting from memory. Do File->New->Example Program then something about kernel module example, FIRST or something like that. There are many sample programs. You may want to try the “SimpleRobot” template. It should contain basic teleop code. I think it might even has a couple lines in autonomous driving the robot forward for 2 seconds or something like that.
I would also recommend starting at a template. However, I would start with the IterativeRobot template, as I’ve seen teams who used the simple robot template and got their autonomous code stuck in a loop, which prevented their teleop code from running.
What kind of end effectors do you need to control? Considering ship is tomorrow, if you want to get anything beyond the basic drivetrain working, you’ll need to test it. If you explain, I can give you some examples to help.
Also, if you have an extra cRIO, you can test your vision processing between ship and your first competition. Not so with anything mechanical on the robot. Just saying, make sure you’re smart about what you prioritize.
If you are not careful writing your code, you can stuck in a loop using the IterativeRobot template too. If you manage to prevent AutonomousPeriodic from returning, that’s how you get stuck.
Thanks everyone for your help, which I will probably continue to ask for on this thread.
First off, I just searched Wind River like you guys suggested to try and find the Sample Robot Template, but I couldn’t find it in the Kernel File. You guys mentioned a FIRST update for Wind River, and I don’t think I’ve updated it past the initial installation. If one of you could post a link to the update, I’d be grateful.
Also, I believe that I’ve found the Getting Started Guide for C/C++. It looks promising and I’ll have to read it and try to learn more about how to use Wind River FRC-wise.
So thanks again and I’ll probably be asking for help again soon.
–Gondorf5–
The ultimate swordsmaster is NOT the ultimate programmer.
Maybe now he can get somewhere.
Thanks for the links, Davis. I found the update that put on the FRC templates.
And rbmj, I’m not sure what effectors are in relation to FRC robots, but right now we have 5 motors we want to run during the competition: two motors are the drive motors for arcade mode, another will rotate a “conveyor belt,” a fourth will operate a ball launcher (1 direction, set to a button as a continuous loop until the button is not pressed), and the fifth will also go in one direction (I don’t know exactly what it will do, it is the one part the engineers are unclear to me about. I do know it will somehow pick up the basketballs from the ground, but that’s a bit irrevelant from a programming aspect). If this is unclear, ask me about it and I will do the best I can.
Again, thank you all for your cooperation. My team is grateful for your help.
–Gondorf5–
The ultimate swordsmaster is finally beginning to take C++ lessons.
You’ll need to ask your Electrical team if your motors are wired on Spikes or on Jaguars.
If they’re on Spikes, then the relevant class is the Relay class. For Jaguars, see this. You would add motors like this:
class myRobot : public IterativeRobot { //or SimpleRobot
public:
//your constructor
myRobot();
//the methods you're overriding go here
private:
Relay motor1;
Jaguar motor2;
};
//then in your constructor implementation
myRobot::myRobot() :
motor1(1), //on relay port 1
motor2(1) //on pwm port 1
{
//initialization
}
//then when you want to use them
//to set a spike:
motor1.Set(Relay::kForward); //or Relay::kReverse, or Relay::kOff
//to set a Jaguar
motor1.Set(1.0); //1.0 is full forward, 0.0 is off, -1.0 is full reverse
Make sure to read the GettingStartedWithC, the FRC 2012 control systems document, and everything else that was posted.
Plenty of teams have also open-sourced their code as well if you need to see examples. We have a huge code base, but if you’re feeling ambitious, you can look at it here.
Sorry it took so long to respond I’ve been all over the place.
Our motors are wired to a Jaguar, thank you rbmj (will the code you’ve provided set the extra motors to run on certain buttons? that would be very helpful to know and could you elaborate on what the constructor line of code is for? I’d like to know if the code you’ve provided will stand on its own or if it’s algebraic, if you know what I mean).
I’ll do my best to make light of the code and links you’ve generously provided, but in case I can’t find what I’m looking for, I need to set up the three extra motors to activate when a button is pressed and deactivate when the button is released.
I’m probably leaving something important out, I KNOW IT, but I’m suffering from a major brain fart, so thanks again for your valuable assistance!
No, it won’t run on its own. You need to plug it in with your own control logic. You’ll need to declare Joystick objects to control the robots. Your control logic will go in the TeleopContinuous function if you’re using IterativeRobot or the OperatorControl function if you’re using SimpleRobot. The documentation is your friend. You’ll also need to look at the RobotDrive class to handle arcade/tank drive. Use Joystick::GetRawButton() and if statements to control your code.
I’ll do my best to make light of the code and links you’ve generously provided, but in case I can’t find what I’m looking for, I need to set up the three extra motors to activate when a button is pressed and deactivate when the button is released.
I’m probably leaving something important out, I KNOW IT, but I’m suffering from a major brain fart, so thanks again for your valuable assistance!
–Gondorf5–
Restoration at: -10%
Something like this?
//put this inside your while(IsOperatorControl()) {} loop in SimpleRobot
//or your TeleopContinuous function in IterativeRobot:
drive.ArcadeDrive(my_joystick);
if (my_joystick.GetRawButton(1)) {
my_jag.Set(1.0);
}
else {
my_jag.Set(0.0);
}
Thanks for making that first part clear, rbmj; I wasn’t sure whether or not the “myRobot();” constructor line of coding was a little confusing. It still is, but that was the one major question I can safely ask without getting to critical about your methods.
So granted that I know which joystick button goes with what button (I’m assuming that because I’m using a Logitech controller from the FTC and was using ROBOTC, the buttons should coincide with the same numeric value for C++ because C++ is a less user-friendly version of ROBOTC… I am really good at sounding like I know more than I know, I know. I know little.), I can use the command “joystick.GetRawButton(Button# here)” to tell the action motors to activate until the button is released, when which you use the “else” to command the motor to stop. Did I translate that correctly?
Also, a quick question about one of your earlier posts; when using the “Jaguar.set” command, do I use “my_jag.Set(value.0);”, or “motorX.Set(value.0);”?
Of course, I would have to declare each motor that I plan on using under something like a void command (tell me when, where, and how I am wrong 'cause I know I’m bound to be somewhere), so motorX would be a motor that I’ve already declared and set aside to be the motor to suit that one purpose.
…I hope you understand at least half of this because I’m surprised to find that I don’t. :ahh:
Oh, and to answer your question, yes; I believe something like that should do the trick. If not, I know where to find you.
–Gondorf5–
Message to the forum visitors and those who’ve posted:
Big thanks to everyone who participates on this forum page! Tell your friends who want to learn the FRC C++ essentials. I’d like to try and make this a forum page where programmer-wannabe’s for FIRST can come to learn without having to wade through chest-high waves of seemingly complicated terms like “void” and “Jaguar” and “semicolon,” while at the same time teaching them what they need to know to end their robot’s endless-eternal-yet-inaudible-screams-of-relentless-torment…
Here’s a sample program using SimpleRobot. Most of this is in the GettingStartedWithC pdf, but…
#include <WPILib.h>
class my_robot : public SimpleRobot {
private:
//the names are completely arbitrary.
Jaguar left_front_drive;
Jaguar left_rear_drive;
Jaguar right_front_drive;
Jaguar right_rear_drive;
Jaguar actuator_yournamehere;
Jaguar actuator_someothername;
RobotDrive drive;
Joystick drive_joystick;
public:
my_robot();
void RobotInit();
void Disabled();
void Autonomous();
void OperatorControl();
};
my_robot::my_robot() : //call constructors for all members of my_robot
//PWM Ports
left_front_drive(1), //replace with your actual ports
left_rear_drive(2), //ask your electrical team for the port numbers
right_front_drive(3),
right_rear_drive(4),
actuator_yournamehere(5),
actuator_someothername(6),
//RobotDrive object
drive(
left_front_drive,
left_rear_drive,
right_front_drive,
right_rear_drive
),
drive_joystick(1) //joystick 1
{
//constructor. Initializes all objects (above)
}
void my_robot::RobotInit() {
//any run-time initialization you need goes here
}
//The following functions will be called exactly once
//after they have run the robot will just sleep until
//a state change (e.g. Autonomous to Disabled)
void my_robot::Disabled() {
//disabled code.
}
void my_robot::Autonomous() {
//your autonomous code should go here.
//make dead sure that this function returns
//before the start of TeleOp or your robot will
//be a brick
}
void my_robot::OperatorControl() {
while (IsOperatorControl()) {
drive.ArcadeDrive(drive_joystick);
if (drive_joystick.GetRawButton(1)) { //use whatever button you need
actuator_yournamehere.Set(1.0); //use whatever power you want
}
else {
actuator_yournamehere.Set(0.0); //turn off
}
if (drive_joystick.GetRawButton(2)) {
actuator_someothername.Set(-1.0); //say reverse, whatever
}
else {
actuator_someothername.Set(0.0);
}
}
}
START_ROBOT_CLASS(my_robot);
This is very minimal code, but I hope it’s enough to get you started.
I’m coding from memory and don’t have anything to test it on, so there may be some errors.
I hope that between this and the documentation you can figure out how to adapt this for your circumstances.
Thanks rbjm. I am beginning to understand the code you just posted very well. I’ll do a little C++ research on some of the terminology was used in the example you gave and post any questions I have about setting up the code sometime tomorrow. ::rtm:: Thanks again for all of your help, dude.
It looks like your team is attending the Colorado Regional in Denver this weekend. I recommend you track down your CSA (Control Systems Advisor) as soon as possible on Thursday morning, this year they can be found wearing orange baseball caps. They should either be able to help or help hook you up with a team that can.