Go to Post instead of complaining, suck it up, think a little harder, and make the most of what you do have. - Andy Grady [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

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 20-02-2012, 20:33
Gondorf5 Gondorf5 is offline
Registered User
FRC #1691
 
Join Date: Feb 2012
Location: Sidney, MT
Posts: 7
Gondorf5 is an unknown quantity at this point
Unhappy Newbie Alert. Our robot is competing, and I can't program it.

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++
Reply With Quote
  #2   Spotlight this post!  
Unread 20-02-2012, 20:46
DavisC DavisC is offline
Registered User
FRC #0539 (Titans)
Team Role: College Student
 
Join Date: Jul 2011
Rookie Year: 2010
Location: Virginia
Posts: 200
DavisC is just really niceDavisC is just really niceDavisC is just really niceDavisC is just really nice
Re: Newbie Alert. Our robot is competing, and I can't program it.

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.

That can get you started.
__________________
FRC Team 539
Student Member: 2010 Breakaway - 2014 Aerial Assist
Mentor: 2015 Recycle Rush - present
Reply With Quote
  #3   Spotlight this post!  
Unread 20-02-2012, 20:48
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 671
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
Re: Newbie Alert. Our robot is competing, and I can't program it.

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.
__________________
Reply With Quote
  #4   Spotlight this post!  
Unread 20-02-2012, 20:57
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,098
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Newbie Alert. Our robot is competing, and I can't program it.

Quote:
Originally Posted by Gondorf5 View Post
I think I can officially say I have no idea what I'm doing.
Find a quiet place to sit down and read this document thoroughly:

GettingStartedWithC.pdf

It's located in this directory path in your C++ installation:

WorkbenchUpdate20120204rev3111\docs\extensions\FRC \GettingStartedWithC.pdf

Attached is the Table of Contents.


Attached Files
File Type: pdf GettingStartedWithC TOC.pdf (24.5 KB, 32 views)
Reply With Quote
  #5   Spotlight this post!  
Unread 20-02-2012, 21:52
rbmj rbmj is offline
Registered User
FRC #0612 (Chantilly Robotics)
Team Role: Alumni
 
Join Date: Apr 2011
Rookie Year: 2011
Location: DC Area/Fairfax County
Posts: 192
rbmj is a jewel in the roughrbmj is a jewel in the roughrbmj is a jewel in the rough
Re: Newbie Alert. Our robot is competing, and I can't program it.

Quote:
Originally Posted by mikets View Post
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.

Finally, if you need a reference of WPILib, I have one posted here: http://rbmj.github.com/612-code/doc/html/classes.html

Last edited by rbmj : 20-02-2012 at 21:55.
Reply With Quote
  #6   Spotlight this post!  
Unread 21-02-2012, 02:09
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 671
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
Re: Newbie Alert. Our robot is competing, and I can't program it.

Quote:
Originally Posted by rbmj View Post
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.
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.
__________________
Reply With Quote
  #7   Spotlight this post!  
Unread 21-02-2012, 20:37
Gondorf5 Gondorf5 is offline
Registered User
FRC #1691
 
Join Date: Feb 2012
Location: Sidney, MT
Posts: 7
Gondorf5 is an unknown quantity at this point
Re: Newbie Alert. Our robot is competing, and I can't program it.

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.
Reply With Quote
  #8   Spotlight this post!  
Unread 21-02-2012, 20:49
DavisC DavisC is offline
Registered User
FRC #0539 (Titans)
Team Role: College Student
 
Join Date: Jul 2011
Rookie Year: 2010
Location: Virginia
Posts: 200
DavisC is just really niceDavisC is just really niceDavisC is just really niceDavisC is just really nice
Re: Newbie Alert. Our robot is competing, and I can't program it.

When you installed WindRiver, did you install both of the CD's I believe that only installing the first causes problems.

Install instructuctions are here: http://www.usfirst.org/sites/default...bench3%203.pdf

And Updates here: http://firstforge.wpi.edu/sf/frs/do/...2_update_for_c

Both are found on the KOP -> Control System: http://www.usfirst.org/roboticsprogr...control-system

Good Luck Programming!
__________________
FRC Team 539
Student Member: 2010 Breakaway - 2014 Aerial Assist
Mentor: 2015 Recycle Rush - present
Reply With Quote
  #9   Spotlight this post!  
Unread 21-02-2012, 21:42
Gondorf5 Gondorf5 is offline
Registered User
FRC #1691
 
Join Date: Feb 2012
Location: Sidney, MT
Posts: 7
Gondorf5 is an unknown quantity at this point
Re: Newbie Alert. Our robot is competing, and I can't program it.

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.
Reply With Quote
  #10   Spotlight this post!  
Unread 22-02-2012, 12:39
rbmj rbmj is offline
Registered User
FRC #0612 (Chantilly Robotics)
Team Role: Alumni
 
Join Date: Apr 2011
Rookie Year: 2011
Location: DC Area/Fairfax County
Posts: 192
rbmj is a jewel in the roughrbmj is a jewel in the roughrbmj is a jewel in the rough
Re: Newbie Alert. Our robot is competing, and I can't program it.

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:

Code:
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.

And http://cplusplus.com/doc/tutorial/ is a go-to reference.

As always, if you need help, you can post

Oh yeah, @mickets, yes, it is possible, but you're saved from yourself a little bit more
Reply With Quote
  #11   Spotlight this post!  
Unread 19-03-2012, 01:02
Gondorf5 Gondorf5 is offline
Registered User
FRC #1691
 
Join Date: Feb 2012
Location: Sidney, MT
Posts: 7
Gondorf5 is an unknown quantity at this point
Smile Re: Newbie Alert. Our robot is competing, and I can't program it.

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!

--Gondorf5--
Restoration at: -10% :-(
Reply With Quote
  #12   Spotlight this post!  
Unread 19-03-2012, 08:49
rbmj rbmj is offline
Registered User
FRC #0612 (Chantilly Robotics)
Team Role: Alumni
 
Join Date: Apr 2011
Rookie Year: 2011
Location: DC Area/Fairfax County
Posts: 192
rbmj is a jewel in the roughrbmj is a jewel in the roughrbmj is a jewel in the rough
Re: Newbie Alert. Our robot is competing, and I can't program it.

Quote:
Originally Posted by Gondorf5 View Post
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).
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.

Quote:
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?
Code:
//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);
}
Reply With Quote
  #13   Spotlight this post!  
Unread 19-03-2012, 22:09
Gondorf5 Gondorf5 is offline
Registered User
FRC #1691
 
Join Date: Feb 2012
Location: Sidney, MT
Posts: 7
Gondorf5 is an unknown quantity at this point
Re: Newbie Alert. Our robot is competing, and I can't program it.

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.

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...
Reply With Quote
  #14   Spotlight this post!  
Unread 20-03-2012, 20:09
rbmj rbmj is offline
Registered User
FRC #0612 (Chantilly Robotics)
Team Role: Alumni
 
Join Date: Apr 2011
Rookie Year: 2011
Location: DC Area/Fairfax County
Posts: 192
rbmj is a jewel in the roughrbmj is a jewel in the roughrbmj is a jewel in the rough
Re: Newbie Alert. Our robot is competing, and I can't program it.

Ok. Let me go through this.

Here's a sample program using SimpleRobot. Most of this is in the GettingStartedWithC pdf, but...

Code:
#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.

If you need more help, you know where to ask.
Reply With Quote
  #15   Spotlight this post!  
Unread 20-03-2012, 23:59
Gondorf5 Gondorf5 is offline
Registered User
FRC #1691
 
Join Date: Feb 2012
Location: Sidney, MT
Posts: 7
Gondorf5 is an unknown quantity at this point
Re: Newbie Alert. Our robot is competing, and I can't program it.

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. Thanks again for all of your help, dude.

--Gondorf5--
Making steady progress at: 0%
Reply With Quote
Reply


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 03:00.

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