Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   Why isn't my slowdown working? (http://www.chiefdelphi.com/forums/showthread.php?t=135725)

414cnewq 03-12-2015 03:44 PM

Why isn't my slowdown working?
 
Okay. I have this code to add joystick sensitivity(it seems to work):
void joystickSanatizer(float*x, float*y){
//Pointers All the Way!!! #starmaster
if(*x<0){
*x*=*x;
*x*=0-1;
}
else *x*=*x;
if(*y<0){
*y*=*y;
*y*=0-1;
}
else *y*=*y;
}
in TeleopPeriodic:
float joyx=stick->GetRawAxis(0);
float joyy=stick->GetRawAxis(1);
joystickSanatizer(&joyx, &joyy);
if(stick->GetRawButton(10)){
multiplier=0.4;
}
else multiplier=1;
and then, after some unrelated code:
rBot->ArcadeDrive(joyy*multiplier, joyx*multiplier);
Where stick is an XBox 360 controller and rBot is a a RobotDrive object

The point of this code is to slow down the robot... but it doesn't.
Can someone help me fix this code or give me another way to slow down the robot.

otherguy 03-12-2015 04:12 PM

Re: Why isn't my slowdown working?
 
Have you added debug print statements for you code to see if your inputs and outputs make sense?
THat might help you get a quick sanity check of where your code is going wrong.


Is there's a reason you don't want to do something a little simpler?

Code:

float joyx = stick->GetRawAxis(0);
float joyy = stick->GetRawAxis(1);
 
if(stick->GetRawButton(10)){
  multiplier = 0.4;
} else {
  multiplier = 1;
}
rBot->ArcadeDrive(joyy * multiplier, joyx * multiplier);

Just change your multiplier variable to affect commanded rate of travel.

It doesn't give you X^2 scaling, but not sure you need that.


Keeping the x^2 implementation:
Code:

float joyx = stick->GetRawAxis(0);
float joyy = stick->GetRawAxis(1);

//#nostarmaster
joyx = joyx * abs(joyx);
joyy = joyy * abs(joyy);

if(stick->GetRawButton(10)){
  multiplier = 0.4;
} else {
  multiplier = 1;
}
rBot->ArcadeDrive(joyy * multiplier, joyx * multiplier);

I think this one does exactly what you were trying to do in your code.

GeeTwo 03-12-2015 05:24 PM

Re: Why isn't my slowdown working?
 
Or even simpler, with squaring:
Code:

float joyx=stick->GetRawAxis(0);
float joyy=stick->GetRawAxis(1);
multiplier = stick->GetRawButton(10) ? 0.4 : 1;

rBot->ArcadeDrive(joyy*abs(joyy)*multiplier, joyx*abs(joyx)*multiplier);


414cnewq 03-12-2015 05:53 PM

Re: Why isn't my slowdown working?
 
Well, there's another portion of my code affected by the slowdown (the tote pickup motor) that is affected by the slowdown:
outside TeleopPeriodic:
float motorpower;
inside:
if(stick->GetRawButton(10))
motorpower=0.4;
else
motorpower=1;
later in TeleopPeriodic(where vmc is a talon object):
vmc->Set(motorpower);
and that does not work.
any thoughts?

otherguy 03-12-2015 11:40 PM

Re: Why isn't my slowdown working?
 
Can you share an actual excerpt from your code?

Can you elaborate on "doesn't work"? What action are you performing and how is the robot responding that leads you to the conclusion that it's not doing what you want?

The 'code' looks reasonable, but you haven't really described what is happening, just that what happened isn't want you expected.

414cnewq 03-17-2015 03:30 PM

Re: Why isn't my slowdown working?
 
Quote:

Originally Posted by 414cnewq (Post 1457064)
Well, there's another portion of my code affected by the slowdown (the tote pickup motor) that is affected by the slowdown:
outside TeleopPeriodic:
float motorpower;
inside:
if(stick->GetRawButton(10))
motorpower=0.4;
else
motorpower=1;
later in TeleopPeriodic(where vmc is a talon object):
vmc->Set(motorpower);
and that does not work.
any thoughts?

What I mean by it doesn't work is that the motor doesn't slow down. It keeps at the same speed.

JefferMC 03-17-2015 09:52 PM

Re: Why isn't my slowdown working?
 
Are you sure you're pushing "Button #10"?


All times are GMT -5. The time now is 10:30 AM.

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