What Are Some Good Resources to Give Someone Who is Just Starting Out With C++?

Hello, so I am just starting out on programming on my team and I am having to be self-taught for the beginning. I was told that this was a good robotics community so I wanted to ask you guys if you are just starting out with C++, what are some good resources that can get me knowing the basics within a couple of months?

While I recommend Java for new programmers (it is more forgiving, and less details to worry about), the WPI library site will take you though some good examples on how to program robots.

As for never touching code before, it’s tough. Normally a class that takes you though things is a good first step. Maybe look into udemy courses? There are also some teams that give great tutorials on how to learn programming from scratch, but I can’t remember who makes them off the top of my head

Thank you for the information! I have a few months to know at least the basics, but I can totally look into everything. I can tell you that I am committed to this new thing :smiley:

Here’s my team’s C++ curriculum if you need it.
https://frc3512.github.io/ci/intro-to-cpp/

There’s other stuff at Curriculum and instruction - FRC Team 3512. Where lots of teams mess up is writing C++ as it was in 2003 with pointers everywhere. If you stick to stack allocations for robot code, you’ll end up with pretty simple code that does what you need. It’s also generally less verbose than the equivalent Java.

For example, do this:

#include <frc/Joystick.h>
#include <frc/SpeedControllerGroup.h>
#include <frc/TimedRobot.h>
#include <frc/VictorSPX.h>
#include <frc/drive/DifferentialDrive.h>

class Robot : public frc::TimedRobot {
public:
    frc::Joystick drive1{0};
    frc::Joystick drive2{1};
    frc::Joystick arm{2};

    frc::VictorSPX flMotor{0};
    frc::VictorSPX rlMotor{1};
    frc::SpeedControllerGroup left{flMotor, rlMotor};

    frc::VictorSPX frMotor{2};
    frc::VictorSPX rrMotor{3};
    frc::SpeedControllerGroup right{frMotor, rrMotor};

    frc::DifferentialDrive drive{left, right};

    void TeleopPeriodic() override {
        drive.CurvatureDrive(drive1.GetY(), drive2.GetX(), drive1.GetRawButtonPressed(2));
    }

Not this:

#include <frc/Joystick.h>
#include <frc/SpeedControllerGroup.h>
#include <frc/TimedRobot.h>
#include <frc/VictorSPX.h>
#include <frc/drive/DifferentialDrive.h>

class Robot : public frc::TimedRobot {
public:
    frc::Joystick* drive1 = new frc::Joystick(0);
    frc::Joystick* drive2 = new frc::Joystick(1);
    frc::Joystick* arm = new frc::Joystick(2);

    frc::VictorSPX* flMotor = new frc::VictorSPX(0);
    frc::VictorSPX* rlMotor = new frc::VictorSPX(1);
    frc::SpeedControllerGroup* left = new frc::SpeedControllerGroup(flMotor, rlMotor);

    frc::VictorSPX* frMotor = new frc::VictorSPX(2);
    frc::VictorSPX* rrMotor = new frc::VictorSPX(3);
    frc::SpeedControllerGroup* right = new frc::SpeedControllerGroup(frMotor, rrMotor);

    frc::DifferentialDrive* drive = new frc::DifferentialDrive(left, right);

    ~Robot() {
        delete drive;
        delete right;
        delete rrMotor;
        delete frMotor;
        delete rlMotor;
        delete flMotor;
        delete arm;
        delete drive2;
        delete drive1;
    }

    void TeleopPeriodic() override {
        drive->CurvatureDrive(drive1->GetY(), drive2->GetX(), drive1->GetRawButtonPressed(2));
    }
4 Likes

Feel free to ask here. Everyone here will point you in a good direction

If you post or read posts on Stack Overflow, don’t get discouraged. It’s a good resource, but there are a lot of bad examples on Stack Overflow. There are also a lot of users on there that are rude and will make you feel bad for asking simple questions. Again, ignore those people and don’t be discouraged by it.

1 Like

I really like that article linked in the prologue of your curriculum:
https://www.evanmiller.org/you-cant-dig-upwards.html

One of the best arguments for C I’ve read in a long time. It definitely matters if you are trying to “just get something done” vs trying to actually learn how computers work… even though the languages in that article aren’t apples-to-apples with the C++ vs Java of the FRC world.

Anywho, I’ll throw my two cents out there since its free, but I have to stick a warning label on the front of this saying that, although I am a professional software engineer by trade, and a computer scientist by bachelors degree…

  1. I don’t have many years of FRC experience,
  2. I don’t program robots or hardware professionally,
  3. I feel like I don’t see eye to eye with a lot of the popular mentality of this community when it comes to opinion on where to start, and what languages and tools to use, etc.

What I mean by that is that it won’t surprise me a bit if a little after I make this post, some others might come behind it telling you that my suggestions are leading you astray or going to be a waste of your time. Maybe they are right, I don’t really know. I am 100% self-taught when it comes to programming FRC Robotics, microcontrollers, etc, and I perceive a lack of suitable resources for true beginners when it comes to FRC and programming the RoboRio. I remember what it was like when I first started learning any type of programming at all, and mostly I remember it was hard, and that the resources for learning sucked. Luckily for you that second one has improved a bit over the years.

Getting started from scratch with making a robot controlled by the RoboRIO is still a pretty big bite, more than most can chew I think, and that’s really regardless of whether you want to use C+ or Java (or Python or anything else).

I’m not going to format this as a recommendation because I don’t want to spend the rest of the week coming back to debate down this thread whether the path I took personally is a good one for anyone else to try to follow or not. Understand that this is just what worked out for me but there are for sure many possible paths to success.

If you need to get started from total scratch you’ll have to watch some introductory/basics videos on youtube or wherever. It barely matters what language its for, mostly you need to get some concepts started so that you understand what is meant when someone talks about a variable, a function, a FOR loop, etc. These concepts show up in every language and are usually pretty similar. I don’t have any good videos in mind right now, hope to find some or make some someday.

That first part will be very boring and pretty quickly you will be itching to actually do something yourself, put something together, write the code, and see the result with your own two eyes. When I was about at that point I ordered one of these Arduino starter kits:
https://www.amazon.com/gp/product/B07CTFVM1L

The tutorials that come on the CD with that kit are not the greatest, but they will suffice. With that cheap, compact little kit you can spend hours working through the included tutorials while having fun hooking up and learning about lights, sensors, sound, motors, etc. Its tempting to want to skip around to the fun-looking stuff, I suggest running through it in order as the lessons somewhat build on each other towards the more difficult stuff.

The tutorials are a little light on the details, but with that kit of parts you can branch out to sites like instructables where there is a wealth of cool projects you can follow and try with the parts in that kit.

In my case I was not involved with FRC yet, I was trying to learn how to program a little board so I could build something specific that I wanted. I went through the tutorials in the starter kit, then used the parts in my starter kit to build the actual device I wanted, with help from the internet/google.

In your case, you want to build and program robots, right? Well, not quite enough parts in the starter kit to do that, BUT, you could go from there and order one of these guys:
https://www.amazon.com/gp/product/B07YCHCQNK/

And again, follow the tutorial and build an entire tiny robot. The included sample code is horribly written, but it does work, and you can rewrite and improve it yourself potentially by that point. I didn’t like the remote control included, so I went off the grid and built a different remote control with parts from the starter kit and some RF chips ordered online.

You can’t use the Arduino IDE to program a RoboRIO for a competition bot, but you can learn concepts and ideas that will carry over, and also be potentially useful to you elsewhere. For example, I’ve used Arduino boards to build and control animated Halloween decorations, home monitoring sensors, even a cruise control module for a very old car that did not have factory cruise option. Lots of neat stuff (again, check out instructables website)

What I like about those kits is that they are cheap and, in my opinion, a lot more beginner-friendly than even say the Romi kits (but if you or your team can afford a Romi kit, by all means give that a try too).

Some day I hope to put together a solid, well defined path for self-learners and when a question like yours pops up I’d have it in my back pocket and say “here, check this out”. I don’t have the free time currently to work on that very much but I think about it often. I made a small start at one point but barely got into it and already want to scrap and re-do it.

One thing about being self-taught is that you really have to be diligent about not jumping around and skipping stuff that doesn’t look like its necessary or related to what you are trying to do at the time. You’ll end up with big holes in your core knowledge like a block of swiss cheese and you will really regret it later. Self taught can be a tough path but it can also be very fun and rewarding. Lots of help available out on the internet. Following a path of someone else who got to where you want to go doesn’t mean its a good or “the best” path, don’t follow anyone off a cliff… including me!

At this point I can very comfortably program FRC bots, it takes just minutes to spin up the driving examples for the standard differential or even mecanum drive, I’m very comfortable running motors via joystick commands, using limelight cameras, decent autonomous modes, PID controls for motors, etc etc. I’m still working on the ability to pass that knowledge onto others efficiently…

So long story short… I “started out” with Arduino, which is basically C++, got those kits linked above, ran the tutorials and examples at my desk in my free time along with fun stuff from instructables, and I feel like it put me in a good place and understanding for when I got roped into a team needing help doing their first year of moving from Labview to C++.

Once you hit that point of doing the actual programming for the RoboRio… for know you’ll just have to google it out. There is stuff, just nothing that I thought was a slam-dunk home-run when I started googling it up. The cliff notes is that once you install the tools there will be some examples already in the VS Code IDE you can use to quickly get a robot driving and running motors and such, you won’t have to start from a blank slate. Thats where I personally think what you could learn on the Arduino kits will start to blend right into the barebones examples they give you in the WPILib coding environment and maybe, just maybe, it will all come together for you.

Just remember there’s probably about 10 other good ways for you to get to that point too, none of them really outright “wrong” as long as you get where you want to go eventually and can do the programming you want to do for your team’s bots. Find a path, try to mostly stick to it and not start jumping around to totally different things when it gets tough, use the internet for help, and best of luck to ya.

3 Likes

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.