View Single Post
  #7   Spotlight this post!  
Unread 07-02-2011, 13:04
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 667
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
Re: How do you use X-Box 360 controllers in C++?

I scanned through the code in the Xbox360 class and didn't really find any reason for needing any custom math. The only methods that need some math are to return the joystick values in polar coordinates instead of the cartesian coordinates (i.e. returning magnitude/angle instead of returning X and Y). There are two things you can do:
  • If you don't really need polar coordinates, you can simply remove the methods from the class: GetLeftAngle, GetRightAngle, GetLeftMagnitude and GetRightMagnitude. Then you can remove the reference of custom math. Note: if you think you need polar coordinates because you have a mecanum drive train, you really don't. The WPI library for mecanum support is doing all the math for you. So you can just call the Mecanum_Cartesian method passing it X, Y and rotation.
  • If you do really need polar coordinates translation. You can use the built-in math library. I don't see why you need custom math. In any case, I would just use the following macros to translate cartesian coordinates into polar coordinates:
Code:
#define MAGNITUDE(x,y)          sqrt(pow(x, 2) + pow(y, 2))
#define RADIANS_TO_DEGREES(n)   ((n)*180.0/PI)
// Forward is 0-radian
#define DIR_RADIANS(x,y)        ((((x) == 0.0) && ((y) == 0.0))? 0.0: atan2(x, y))
#define DIR_DEGREES(x,y)        RADIANS_TO_DEGREES(DIR_RADIANS(x, y))
__________________

Last edited by mikets : 07-02-2011 at 13:10.
Reply With Quote