A few questions about C++

Hello everyone,

I am part of a rookie (well not anymore) team and in the 2014 FRC Competition, we plan on using C++ to program the robot.

My first question is C++ or Java better to program in?

My second question is that is this code appropriate to initialize two joysticks?

#include "WPILib.h"

class RobotDemo : public SimpleRobot
{
	RobotDrive myRobot; // robot drive system
	Joystick stick1, stick2; // only joystick

public:
	RobotDemo(void):
		myRobot(1, 2),	// these must be initialized in the same order
		stick1(1),		// as they are declared above.
		stick2(2)
	{
		myRobot.SetExpiration(0.1);
	}

Thank you to everyone and anyone who answers my question.

Austin P. //Programming Captain | The Leotechs FRC#4459

C++ and Java are extremely similar. I’d recommend you go with whichever language you’re more familiar with.

Yes, that code is a reasonable start at making a driveable SimpleRobot.

Whether you’re using C++ or Java, I’d highly recommend you take a look at Command Based Programming with the CommandBasedTemplate. You end up with more files, but I think it makes building autonomous routines and automated functions a good bit easier. Once you get basic commands set up, it’s incredibly simple to tie them together an autonomous routine like aim and fire 3 frisbees, switch to loading position, turn 30 degrees and back up 5 feet. And then build another routine that does other things.

Similar to the previous post, C++ and Java are very similar and it’s a matter of preference. However, my take on the Command Based robot is it’s good for new people to C++ so it makes it easier to develop a multi-file project. So, because you’re switching to it next year, you should use it as a starting point. Once you become more proficient in C++ development, I highly suggest you write the code from scratch to develop yourselves as programmers and as a learning process.

Java was written with C++ used as a base in many instances so they are very similar. For FIRST robots, you would find that you could port your code from one to the other fairly easily. The underlying WPI library has all of the same classes and functions.

While I am a huge fan of the command based robot, I believe that some new people may have trouble with it. It some instances it may be best to start with the simple or iterative template to get the feel for it, but then move to the command based.

I will say we had all new programmers this year, and we are using the command based robot. We had several programming mentors though that were there to help through the stumbling blocks. After it was all said and done, our students seem to love the advantages. Changing our code is a breeze now, where as without the command based robot it would take much longer. You can not get any easier coding for autonomous, the toughest part of coding a FIRST robot.

In answer to Java or C++, pick one and go. As far as FIRST robots go, neither will really be easier or better than the other in my opinion.

Thank you for all of the responses!

Just have one more question… How would one go about modifying the speed that the robot moves when the joystick is fully pushed forward in Teleop mode, like in Autonomous, the speed is set

myRobot.Drive(-0.5, 0.0);

is there a teleop version of this (if that makes sense)

probably something like

myRobot.TankDrive(Stick1->GetRawAxis(2)*.5 , Stick2->GetRawAxis(2)*.5);

I’m not sure which axis is which for your controller (where the number 2 should be substituted with the Y axis of your controller for tank drive). I’m also not sure that you’re using tank drive :wink: Just multiply your joystick value by whatever you want to reduce the speed by, regardless of whether you’re using arcade or tank or holonomic or whatever.

Thank you!

Looking at the code for RobotDrivie, it looks like you can also say

myRobot.SetMaxOutput(.5)

to apply a global factor to your drive output.

I’m a big fan of the command-based robot framework, even for sophisticated teams. It makes the robot code much easier to understand.

thank you!