View Single Post
  #10   Spotlight this post!  
Unread 14-01-2013, 13:02
billbo911's Avatar
billbo911 billbo911 is offline
I prefer you give a perfect effort.
AKA: That's "Mr. Bill"
FRC #2073 (EagleForce)
Team Role: Mentor
 
Join Date: Mar 2005
Rookie Year: 2005
Location: Elk Grove, Ca.
Posts: 2,358
billbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond repute
Re: Disc Lauching Velocity

I've "refined" my Chronometer sketch (read that as "I now have it working correctly"). After testing it, I found it wasn't quite what I wanted, so I fixed it.

Please enjoy!

Code:
/*******************************************************************************************
* This Sketch is for a Chronometer that uses the "micros" function to capture two points in*
* time and determines how much time has elapsed between them in microseconds. By knowing    *
* the distance between the to sensors, the velocity of the object can be determined.       *
* Bill Kendall, Jan. 11, 2013                                                              *
*******************************************************************************************/

float SENSOR_DIST = 6;  //This value is the distance between the sensors in inches
float distance;
unsigned long event1 = 0; // value in 'micros" at the time of this first trigger
unsigned long event2 = 0; // value in 'micros" at the time of this second trigger
int firstint = 0;  //Set to 1 if Interrupt 0 has occurred
int calculate = 0;  // If set to 1, a calculation and display of the velocity will occur
unsigned long duration = 0; // Amount of elapsed time between events
float velocity = 0;

void setup (void)
{
attachInterrupt (0, ISR0, FALLING);  // Interupt 0 (pin 2) calls "ISR0" Thie is the first trigger
attachInterrupt (1, ISR1, FALLING);  // Interupt 1 (pin 3) calls "ISR1" This is the second trigger
distance = (SENSOR_DIST/12.0); // Convert sensor spacing to feet
Serial.begin(115200); // connect to the serial port

}

void ISR0 (void)
{
  event1 = micros(); // record the microseconds counter
  firstint = 1;
}

void ISR1 (void)
{
  event2 = micros(); // record the microseconds counter
  calculate = 1;
}


void loop (void)
{
  if (calculate == 1 && firstint == 1)
  {
    RunMath ();    
  }
  delay (500);
}

void RunMath (void)
{
  duration = (event2 - event1); // elapsed time between triggers in u seconds
  velocity = (((distance)*1000000)/(duration));  // Calculate velocity in feet per second
  Serial.print("The projectile is moving at ");
  Serial.print (velocity,2);
  Serial.println(" ft./sec.");
  calculate = 0;
  firstint = 0;
 }
__________________
CalGames 2009 Autonomous Champion Award winner
Sacramento 2010 Creativity in Design winner, Sacramento 2010 Quarter finalist
2011 Sacramento Finalist, 2011 Madtown Engineering Inspiration Award.
2012 Sacramento Semi-Finals, 2012 Sacramento Innovation in Control Award, 2012 SVR Judges Award.
2012 CalGames Autonomous Challenge Award winner ($$$).
2014 2X Rockwell Automation: Innovation in Control Award (CVR and SAC). Curie Division Gracious Professionalism Award.
2014 Capital City Classic Winner AND Runner Up. Madtown Throwdown: Runner up.
2015 Innovation in Control Award, Sacramento.
2016 Chezy Champs Finalist, 2016 MTTD Finalist
Reply With Quote