Go to Post Actually, I think the standard Klingon warning label ought to be sufficient: 'yIQIpQo' (don't be stupid) - Alan Anderson [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 02-02-2013, 13:24
MI6 MI6 is offline
Registered User
FRC #4362
Team Role: Programmer
 
Join Date: Feb 2013
Rookie Year: 2011
Location: United States
Posts: 6
MI6 is an unknown quantity at this point
C++ Tank Drive Help

Please help with the errors and how to use a xbox controller with it!

I am getting a few errors with my code!
- Error: expected identifier before numeric constant
- Error: ISO C++ forbids declarations of parameter with no type
- Error: expected ',' or '...' before numeric constant
-Syntax Error


Code:

#include "WPILib.h"

class RobotDemo : public SimpleRobot
{
RobotDrive drivetrain(1, 2);
Joystick leftStick(1);
Joystick rightStick(2);

public:
RobotDemo()
{
GetWatchdog().SetEnabled(false);
}
void Autonomous()
{

}
void OperatorControl()
{
while (1) // loop forever
{
drive.Tank(leftStick, rightStick); // drive with the joysticks
Wait(0.005);
}
}
};

START_ROBOT_CLASS(RobotDemo);
Reply With Quote
  #2   Spotlight this post!  
Unread 02-02-2013, 16:34
Domenic Rodriguez's Avatar
Domenic Rodriguez Domenic Rodriguez is offline
Registered User
FRC #0316 (LuNaTeCs)
Team Role: College Student
 
Join Date: Sep 2010
Rookie Year: 2011
Location: Grove City, PA
Posts: 213
Domenic Rodriguez has a spectacular aura aboutDomenic Rodriguez has a spectacular aura aboutDomenic Rodriguez has a spectacular aura about
Re: C++ Tank Drive Help

In C++, you can't initialize non-const member variables at declaration. They need to initialized in the constructor. An easy way to do this is to use C++ initialization lists (more info on which can be found here).

Instead of writing your code like this:
Code:
RobotDrive drivetrain(1, 2);
Joystick leftStick(1);
Joystick rightStick(2);

public:
RobotDemo()
{
    GetWatchdog().SetEnabled(false);
}
It would look more like this:
Code:
RobotDrive drivetrain;
Joystick leftStick;
Joystick rightStick;

public:
RobotDemo() : drivetrain(1, 2), leftStick(1), rightStick(2)
{
    GetWatchdog().SetEnabled(false);
}
Instead of initializing the variables when they are declared, we initialize them in a list after the name of the constructor. This should solve the compiler errors.

Also, if you want to access the second joystick on the XBox controller, you need to use the GetRawAxis() function instead of declaring a second joystick. This also means that you have to pass the values of the two axes to the TankDrive function instead of the joystick object. The button and joystick mappings for the XBox controller can be found in this post, but I'll copy the relevant portion below:

Quote:
  • 1: Left Stick X Axis
    -Left:Negative ; Right: Positive
  • 2: Left Stick Y Axis
    -Up: Negative ; Down: Positive
  • 3: Triggers
    -Left: Positive ; Right: Negative
  • 4: Right Stick X Axis
    -Left: Negative ; Right: Positive
  • 5: Right Stick Y Axis
    -Up: Negative ; Down: Positive
  • 6: Directional Pad (Not recommended, buggy)
For this example, if we wanted to have the XBox left Y axis control the left side of the tank drive and the right Y axis control the right side, it would look like this:

Code:
drivetrain.TankDrive(joystick.GetY(), joystick.GetRawAxis(5);
Here's the whole file for reference
Code:
#include "WPILib.h"

class DemoRobot : public SimpleRobot
{
	RobotDrive drivetrain;
	Joystick xbox;
public:
	DemoRobot() :
		drivetrain(1, 2), xbox(1)
	{
		GetWatchdog().SetEnabled(false);
	}
	
	void Autonomous() {}
	
	void OperatorControl()
	{
		while (IsOperatorControl()) {
			drivetrain.TankDrive(xbox.GetY(), xbox.GetRawAxis(5));
			Wait(0.005);
		}
	}
};

START_ROBOT_CLASS(DemoRobot);
Hope this helps. If you have any more questions, feel free to ask

- Domenic
Reply With Quote
  #3   Spotlight this post!  
Unread 02-02-2013, 21:41
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: C++ Tank Drive Help

Typically a compiler error message is accompanied by the line on which the error was detected. In C/C++, that is sometimes the line after the one with the actual problem. What line is identified as causing each of the errors you see?

You're defining your RobotDrive object as "drivetrain" but you're trying to call the Tank method of something called "drive". I don't know that it's the cause of your compile errors, but it looks suspicious to me.
Reply With Quote
  #4   Spotlight this post!  
Unread 03-02-2013, 03:03
bob.wolff68's Avatar
bob.wolff68 bob.wolff68 is offline
Da' Mentor Man
FRC #1967
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2007
Location: United States
Posts: 157
bob.wolff68 is just really nicebob.wolff68 is just really nicebob.wolff68 is just really nicebob.wolff68 is just really nicebob.wolff68 is just really nice
Re: C++ Tank Drive Help

It is also unlikely that you mean what is stated regarding leftstick and rightstick. What is in the code says that joystick controller #1 (the first xbox controller) will be the left-stick while the right part of the tank drive will be controlled by joystick #2 (the 2nd xbox controller). What you more likely want to do is use particular parts of a single joystick - a particular axis of joystick #1 for the left and a particular part/axis of joystick #1 for the right.

One of my students (holly4win) posted in a separate thread today about a "joystick investigator" program our team wrote which you might find useful to getting this information - see the thread at http://www.chiefdelphi.com/forums/sh...d.php?t=103156

Thanks,
bob
__________________
~~~~~~~~~~~~~~~~~~~
Bob Wolff - Software from the old-school
Mentor / C / C++ guy
Team 1967 - The Janksters - San Jose, CA
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 14:39.

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