Go to Post A charged battery beats a dead battery any day. - Al Skierkiewicz [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
  #1   Spotlight this post!  
Unread 10-05-2010, 14:56
whatabouteve whatabouteve is offline
Registered User
AKA: Dean Keithly
FRC #0245 (Adambots)
Team Role: Leadership
 
Join Date: Jan 2009
Rookie Year: 2007
Location: Rochester Hills,MI
Posts: 45
whatabouteve is an unknown quantity at this point
Sine and Cosine in C++

Hey i'm one of the programmers from team 245 the Adambots and we are trying to use the gyro and accelerometer together to determine distances traveled with our robot.

Since we are not expert programmers, we are wondering how to use sin and cos to find distances traveled using vectors.

Note: we just need the syntax for the use of these functions.
Reply With Quote
  #2   Spotlight this post!  
Unread 10-05-2010, 15:03
byteit101's Avatar
byteit101 byteit101 is offline
WPILib maintainer (WPI)
AKA: Patrick Plenefisch
no team (The Cat Attack (Formerly))
Team Role: Programmer
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Worcester
Posts: 699
byteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of light
Re: Sine and Cosine in C++

float x=sin(radian);
float y=cos(radian);
from
www.cplusplus.com/reference/clibrary/cmath/sin/
and
www.cplusplus.com/reference/clibrary/cmath/cos/

*note: you may need to #include <math.h>
__________________
Bubble Wrap: programmers rewards
Watchdog.Kill();
printf("Watchdog is Dead, Celebrate!");
How to make a self aware robot: while (∞) cout<<(sqrt(-∞)/-0);
Previously FRC 451 (The Cat Attack)
Now part of the class of 2016 at WPI & helping on WPILib
Reply With Quote
  #3   Spotlight this post!  
Unread 10-05-2010, 17:03
Robototes2412's Avatar
Robototes2412 Robototes2412 is offline
1 * 4 != 14
FRC #2412 (Robototes)
Team Role: Programmer
 
Join Date: Jan 2010
Rookie Year: 2007
Location: Bellevue
Posts: 312
Robototes2412 is on a distinguished road
Re: Sine and Cosine in C++

you absolutely have to import math.h, unless you're using gnulibc which has math.h byitself
Reply With Quote
  #4   Spotlight this post!  
Unread 11-05-2010, 00:04
slavik262's Avatar
slavik262 slavik262 is offline
We do what we must because we can.
AKA: Matt Kline
FRC #0537 (Charger Robotics)
Team Role: Alumni
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Sussex, WI
Posts: 310
slavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to behold
Send a message via AIM to slavik262
Re: Sine and Cosine in C++

Or you can use the C++ wrapper for math.h and do
#include <cmath>
__________________
Reply With Quote
  #5   Spotlight this post!  
Unread 11-05-2010, 01:50
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: Sine and Cosine in C++

We used the accelerometer to determine the distance travelled by doing a double integration on acceleration. We wrote a generic accelerometer module that will give you accel/vel/distance on all three axes. Then we defined a macro called MAGNITUDE that will take the x and y vectors and gives you distance magnitude and also the macro DIR_DEGREE to calculate the heading.

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))
Our accelerometer code can be found at
http://proj.titanrobotics.net/hg/Frc...inc/TrcAccel.h

But be careful when using the double integrator code. The accelerometer has noise, so even if the robot sits still, you may end up with an increasing velocity if you sit long enough. Our code doesn't enable the accelerometer integration until right before we need it. And it clears the integrator right before we enable it so it clears the cumulated error. It also does zero-G calibration at the beginning initialization phase to eliminate the DC offset of the accelerometer. Also be mindful on situation that if your robot gets bumped or accelerates/decelerates too fast, it could saturate the accelerometer output so to give you error on your integraton. With all those limitations in mind, it will give you decent results for a short period of time.
__________________
Reply With Quote
  #6   Spotlight this post!  
Unread 11-05-2010, 10:36
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,044
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Sine and Cosine in C++

Quote:
Originally Posted by mikets View Post
Also be mindful on situation that if your robot gets bumped or accelerates/decelerates too fast, it could saturate the accelerometer output so to give you error on your integraton. With all those limitations in mind, it will give you decent results for a short period of time.
Does your code try to do anything to compensate for gravity when going over the bumps?


~
Reply With Quote
  #7   Spotlight this post!  
Unread 11-05-2010, 10:58
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: Sine and Cosine in C++

No, our code was primarily used for autonomous period. And we did not plan to go over the bump. Like I said, if you hit the bump, the impact will probably saturate the accelerometer and render the reading inaccurate. We know the limitation of the code and only use it within its limit. In any case, the accelerometer library code will give you the accel/vel/distance for all the axes. So in theory, you could take the z-axis data and do some compensation with it. But we did not do that in our main code.
__________________
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Thanks to 1742 and 1209/Congrats to 2410, 935, and 1987 vhcook Thanks and/or Congrats 4 28-03-2010 15:50
Boilermaker Regional - WFFA and Volunteer Award and the Trio! Chris Fultz Thanks and/or Congrats 1 21-03-2010 14:05
Congratulations and Thank you to Team 341, 694 and 3204! AnibaS Thanks and/or Congrats 2 18-03-2010 07:40
Thank You and Congrats to Teams 20, 2079, 195, and 1124! Chris is me Thanks and/or Congrats 12 16-03-2010 09:16
Visual Basic. Using a loop to solve the cosine function. sanddrag Programming 2 10-03-2006 11:45


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

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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