Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   Flipping the X - axis (http://www.chiefdelphi.com/forums/showthread.php?t=105228)

cddp14 30-03-2012 11:00

Flipping the X - axis
 
Ok. this a simple problem that I know I am just overlooking a small detail. For this years robot we what to be able to push a button to be able to make the back of the robot to become the front and vice versa during TeleOp mode. The only problem is that the x-axis of doesn't adjust when the switch is made. when the robot is reversed and you move the joystick to the left the robot turns to the right and vice versa. Here is my code below:
MyBase->ArcadeDrive(Driver);
if(Driver->GetRawButton(6))// reverse direction of robot
{

MyBase->SetInvertedMotor(RobotDrive::kRearLeftMotor, true);
MyBase->SetInvertedMotor(RobotDrive::kFrontLeftMotor,true );
MyBase->SetInvertedMotor(RobotDrive::kRearRightMotor, true);
MyBase->SetInvertedMotor(RobotDrive::kFrontRightMotor,tru e);

}
if(Driver->GetRawButton(7))// normal configuration
{

MyBase->SetInvertedMotor(RobotDrive::kRearRightMotor, false);
MyBase->SetInvertedMotor(RobotDrive::kFrontRightMotor,fal se);
MyBase->SetInvertedMotor(RobotDrive::kRearLeftMotor, false);
MyBase->SetInvertedMotor(RobotDrive::kFrontLeftMotor,fals e);


}
How can I get the X- axis to switch with the reversal? Thanks in advance. Also, I am using WindRiver.

FrankJ 30-03-2012 11:18

Re: Flipping the X - axis
 
You need to also switch around your motors.
left side & right side swaps
Left front becomes right rear
left rear becomes right front
ETC

For a simple tank drive might be easier to swap & invert the joy sticks inputs into the motors.

Ether 30-03-2012 12:59

Re: Flipping the X - axis
 
Quote:

Originally Posted by cddp14 (Post 1151561)
.

Instead of inverting the motors, just try changing the sign of the joystick X and Y values before feeding them into the arcade algorithm


cddp14 30-03-2012 14:17

Re: Flipping the X - axis
 
Quote:

Originally Posted by Ether (Post 1151589)
Instead of inverting the motors, just try changing the sign of the joystick X and Y values before feeding them into the arcade algorithm


I have looked into doing that but I have not had any success. any sample code would be helpful

Ether 30-03-2012 14:51

Re: Flipping the X - axis
 
Quote:

Originally Posted by cddp14 (Post 1151607)
I have looked into doing that but I have not had any success. any sample code would be helpful

sample code? not to be flippant, but this is what I meant:

Code:

Y = -Y;
X = -X;



Alan Anderson 30-03-2012 16:07

Re: Flipping the X - axis
 
Quote:

Originally Posted by Ether (Post 1151626)
sample code? not to be flippant, but this is what I meant:

Code:

Y = -Y;
X = -X;



Maybe you don't realize that the single-argument ArcadeDrive() method he's using doesn't provide anywhere to do this inversion. The sample code he's asking for is how to get around that lack. By the way, it's only the Y axis that needs to be inverted. The originally posted code is already getting the effect of inverting both axes by running all the motors in the other direction.

Try this: (warning -- untested)
Code:

if(Driver->GetRawButton(6)) // reversed direction of robot
{
    directionInverted = true;
}
if(Driver->GetRawButton(7)) // normal configuration
{
    directionInverted = false;
}
if(directionInverted)
{
    MyBase->ArcadeDrive(-Driver->GetY(),Driver->GetX(),false);
}
else
{
    MyBase->ArcadeDrive(Driver);
}

You'll have to declare directionInverted as a static boolean variable, with an initial value of false.

cddp14 30-03-2012 17:23

Re: Flipping the X - axis
 
Quote:

Originally Posted by Alan Anderson (Post 1151646)
Maybe you don't realize that the single-argument ArcadeDrive() method he's using doesn't provide anywhere to do this inversion. The sample code he's asking for is how to get around that lack. By the way, it's only the Y axis that needs to be inverted. The originally posted code is already getting the effect of inverting both axes by running all the motors in the other direction.

Try this: (warning -- untested)
Code:

if(Driver->GetRawButton(6)) // reversed direction of robot
{
    directionInverted = true;
}
if(Driver->GetRawButton(7)) // normal configuration
{
    directionInverted = false;
}
if(directionInverted)
{
    MyBase->ArcadeDrive(-Driver->GetY(),Driver->GetX(),false);
}
else
{
    MyBase->ArcadeDrive(Driver);
}

You'll have to declare directionInverted as a static boolean variable, with an initial value of false.

This worked!!! Thanks!!!:)


All times are GMT -5. The time now is 17:36.

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