Go to Post I suppose this would be a bad time to reveal that Q and LookingForward are the same robot person hybrid thing... - EricVanWyk [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 15-02-2010, 11:40
abpahl abpahl is offline
Registered User
FRC #3407
 
Join Date: Feb 2010
Location: Shoreview, MN
Posts: 4
abpahl is an unknown quantity at this point
Very basic programming issue

First of all, I know almost nothing of programming. We spent a lot of time on debugging and troubleshooting, and I'm just now getting around to writing the code. I have a tiny issue that I don't know how to fix.

I'm building my code off the sample template, and having almost no C++ knowledge, I'm working completely off example.

My currently modified( not by much, just added a third motor) code is as follows:

Code:
#include "WPILib.h"
#include "vision/AxisCamera2010.h"
/**
 * This is a demo program showing the use of the RobotBase class.
 * The SimpleRobot class is the base of a robot application that will automatically call your
 * Autonomous and OperatorControl methods at the right time as controlled by the switches on
 * the driver station or the field controls.
 */ 
class RobotDemo : public SimpleRobot
{
	RobotDrive myRobot; // robot drive system
	Joystick stick;// only joystick
	Jaguar kicker; // call kicking motor

public:
	RobotDemo(void):
		myRobot(1, 2),	// these must be initialized in the same order
		stick(1),
		kicker(3)// the motor for kicking should be plugged into slot 3
		// as they are declared above.
	{
		GetWatchdog().SetExpiration(0.1);
	}

	/**
	 * Drive left & right motors for 2 seconds then stop
	 */
	void Autonomous(void)
	{
		// I edited this code for testing
		GetWatchdog().SetEnabled(false);
		myRobot.Drive(0.5, 0.0); 	// drive backwards half speed
		Wait(1.0); 			
		myRobot.Drive(0.0,0.0);//    stop for a bit
		Wait(1.0);
		myRobot.Drive(-5.0, 0.0);// go back to where you started
		Wait(1.0);
		myRobot.Drive(0.0,0.0);
}

	/**
	 * Runs the motors with arcade steering. 
	 */
	void OperatorControl(void)
	{

		
		GetWatchdog().SetEnabled(true);
		while (IsOperatorControl())
		{
			GetWatchdog().Feed();
			myRobot.ArcadeDrive(stick); // drive with arcade style (use right stick)
			if  (stick.GetTrigger()) // use trigger to activate kicking device (I added this bit)
				kicker.Set(1.0); // If trigger is pressed, full speed!
			else
				kicker.Set(.2); // Otherwise, go at 1/5 speed
			Wait(0.005);				// wait for a motor update time
		}
	}
};

START_ROBOT_CLASS(RobotDemo);
The issue is that the joystick is currently reversed. Forward and backwards are fine, but if you go left on the joystick, the robot goes right, and vice versa. Switching the PWM slots on the jaguars doesn't help, it just inverts forward and backwards. It seems like this would be very easy to fix, but I have no clue where to start.

Do I need to modify RobotDrive? And if so, where do I modify it? If I modify a file in WPIlib, will the new file get built into my project?
Reply With Quote
  #2   Spotlight this post!  
Unread 15-02-2010, 11:55
Mr. Lim Mr. Lim is offline
Registered User
AKA: Mr. Lim
no team
Team Role: Leadership
 
Join Date: Jan 2004
Rookie Year: 1998
Location: Toronto, Ontario
Posts: 1,125
Mr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond repute
Re: Very basic programming issue

Here's my take:

Set your PWM cables such that you get the following behaviour:

Forward and Backwards are reversed
Left and Right are reversed

Hopefully when you do this, you'll notice that PWM 1 -> Left and PWM 2 -> Right, just as it should be based on what your code says.

Power down the robot, and on ALL your drivetrain speed controllers, switch the red and black wires that lead to the motors. That will reverse their direction.

Other here might recommend extensive coding changes to make this change in programming, but seeing as how you'd said your programming expertise is low, I think this is your best fix! Just make sure you document that you flipped these wires so that the next person who hooks up your motors knows to reverse them.
__________________
In life, what you give, you keep. What you fail to give, you lose forever...
Reply With Quote
  #3   Spotlight this post!  
Unread 15-02-2010, 12:05
abpahl abpahl is offline
Registered User
FRC #3407
 
Join Date: Feb 2010
Location: Shoreview, MN
Posts: 4
abpahl is an unknown quantity at this point
Re: Very basic programming issue

Thanks, that is exactly what was needed!
Reply With Quote
  #4   Spotlight this post!  
Unread 15-02-2010, 23:41
Radical Pi Radical Pi is offline
Putting the Jumper in the Bumper
AKA: Ian Thompson
FRC #0639 (Code Red Robotics)
Team Role: Programmer
 
Join Date: Jan 2010
Rookie Year: 2010
Location: New York
Posts: 655
Radical Pi has a spectacular aura aboutRadical Pi has a spectacular aura aboutRadical Pi has a spectacular aura about
Re: Very basic programming issue

Actually, to fix it just add a - before the GetAxis on the joyticks and it will run the motors in the opposite directions. The joyticks are very un-intuitive and have forward as a negative value. In case you're wondering, the - simply does a mathematical negative on the value
__________________

"To have no errors would be life without meaning. No strugle, no joy"
"A network is only as strong as it's weakest linksys"
Reply With Quote
  #5   Spotlight this post!  
Unread 16-02-2010, 15:56
byteit101's Avatar
byteit101 byteit101 is offline
WPILib maintainer (WPI)
AKA: Patrick Plenefisch
no team (The Cat Attack (Formerly))
Team Role: Programmer
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Worcester
Posts: 699
byteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of light
Re: Very basic programming issue

Quote:
Originally Posted by Radical Pi View Post
Actually, to fix it just add a - before the GetAxis on the joyticks and it will run the motors in the opposite directions. The joyticks are very un-intuitive and have forward as a negative value. In case you're wondering, the - simply does a mathematical negative on the value
however, he is using the compressed form:
myRobot.ArcadeDrive(stick);
not
myRobot.ArcadeDrive(stick.GetY(), stick.GetX());
so your suggestion won't work (at least at this point)
__________________
Bubble Wrap: programmers rewards
Watchdog.Kill();
printf("Watchdog is Dead, Celebrate!");
How to make a self aware robot: while (∞) cout<<(sqrt(-∞)/-0);
Previously FRC 451 (The Cat Attack)
Now part of the class of 2016 at WPI & helping on WPILib
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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Very Basic: Get a program running on the cRio that will show video on Classmat isaacdl Control System 6 23-01-2010 17:33
very basic code help mikelowry C/C++ 20 18-09-2009 18:38
Very odd issue with WindRiver GGCO C/C++ 1 24-01-2009 01:21
BASIC programming John Gutmann Programming 3 17-05-2005 12:15
Very Basic Programming Question kewlkid382 Chit-Chat 5 18-01-2003 11:11


All times are GMT -5. The time now is 02:47.

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