Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   Very basic programming issue (http://www.chiefdelphi.com/forums/showthread.php?t=82712)

abpahl 15-02-2010 11:40

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?

Mr. Lim 15-02-2010 11:55

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.

abpahl 15-02-2010 12:05

Re: Very basic programming issue
 
Thanks, that is exactly what was needed!

Radical Pi 15-02-2010 23:41

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

byteit101 16-02-2010 15:56

Re: Very basic programming issue
 
Quote:

Originally Posted by Radical Pi (Post 921038)
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)


All times are GMT -5. The time now is 13:34.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi