Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   Absolute Value of Joystick position (http://www.chiefdelphi.com/forums/showthread.php?t=103479)

DavisC 21-02-2012 10:46

Absolute Value of Joystick position
 
The joysticks I have are somewhat off center slightly so the drive motors are constantly running at like .05 as an example.

This is what I am trying to do below but I think the Abs() function converts it to an Integer. How can I use it on a float (or should I resort to more "or's" in the "if's"

Code:

if(abs(J_stick1.GetY()) <= .05 || abs(J_stick2.GetY()) <= .05)
    R_myRobot.Drive(0.0, 0.0);


Ether 21-02-2012 10:59

Re: Absolute Value of Joystick position
 
Quote:

Originally Posted by DavisC (Post 1131591)
This is what I am trying to do below but I think the Abs() function converts it to an Integer.

My copy of K&R says that fabs()* should be part of the C ANSI standard library.


* fabs() = floating point absolute value




DavisC 21-02-2012 12:09

Re: Absolute Value of Joystick position
 
Quote:

error: `fabs' undeclared (first use this function)
This is the message I get when trying to use fabs() where i have abs() in the previous post

RufflesRidge 21-02-2012 12:12

Re: Absolute Value of Joystick position
 
Quote:

Originally Posted by DavisC (Post 1131658)
This is the message I get when trying to use fabs() where i have abs() in the previous post

Sounds like you are missing this:
Code:

#include "Math.h"

DavisC 21-02-2012 18:17

Re: Absolute Value of Joystick position
 
Thanks, I built it and it didn't produce an error. I will have to wait to test in a week because we sealed the bot and we are making an extra bot.

I will see if i can test it on this 1 scrap bot some day before then hopefully.

Thanks,
Davis


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

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