Ok, Ok, I know I said I would go work on the Arduino code today, but its Sunday and Im being lazy. I thought I would at least link my proposed changes that I will test tomorrow.
First off, the if else code is slightly off
What I had:
if(LocalNewFlag & PITCH_FLAG)
{ // below the code will limit user input differently at various distances from the wall
// this should, in theory, limit the user input for a slow deceleration towards an obsticle and avoid it if
// the quad copter should drift towards the wall after limiting the users input to nill
// this still allows the user to perform other movements unchecked. That means the user could possibly fly at max // speed along a wall while maintaining a 1.5 to 2 ft range from the
// wall if the user gives some input towards the wall with the other direction.
if((distancef && distanceb >= 246) || (distancef && distanceb <=0 )) // if outside the range of 1 cm to 245(10 ft) //ignore ultrasonic data
{
servoChannel1.writeMicroseconds(PITCH_IN_LOCAL);
} else if(distancef < distanceb) // checks to see which distance is closer that involves this channel
{
if(distancef < 45) // distances in cm danger close check accounts for drifting and inertia toward the wall
{
servoChannel1.writeMicroseconds(1400); // back away from the wall
}
else if(distancef < 60) // this one is the distance from the obsticle that we dont want user input to move that // direction
{
servoChannel1.writeMicroseconds(1500); // no user input
}
else if(distancef < 122) // closest distance that a user can still control the quad to move toward the wall
{
if(PITCH_IN_LOCAL > 1550) // limits the user to max of movement in this direction of very slow
{
servoChannel1.writeMicroseconds(1550);
}
else
{
servoChannel1.writeMicroseconds(PITCH_IN_LOCAL); // allows the user to slowly close on the obsticle
}
}
else if(distancef < 183) // less limited and further away from the wall currently at the 6 ft range
{
if(PITCH_IN_LOCAL > 1600)
{
servoChannel1.writeMicroseconds(1600); // same as before limits users max to slow approach
}
else
{
servoChannel1.writeMicroseconds(PITCH_IN_LOCAL);
}
}
else if(distancef < 245) // even less limited further still from the wall currently at 8 ft range
{
if(PITCH_IN_LOCAL > 1650)
{
servoChannel1.writeMicroseconds(1650); // same as before limits users max to slightly faster approach
}
else
{
servoChannel1.writeMicroseconds(PITCH_IN_LOCAL);
}
}
}
else
What I think will work better(some of this has been tested)
if(LocalNewFlag & PITCH_FLAG)
{ if(distancef <= distanceb) // checks to see which distance is closer that involves this channel
{
if(distancef < 45) // distances in cm danger close check accounts for drifting and inertia toward the wall
{
if(PITCH_IN_LOCAL > 1400)
{ servoChannel1.writeMicroseconds(1400); // back away from the wall
}
else
{
servoChannel1.writeMicroseconds(PITCH_IN_LOCAL);
}
}
else if(distancef < 60) { if(PITCH_IN_LOCAL > 1500)
{ servoChannel1.writeMicroseconds(1500); // back away from the wall
}
else
{
servoChannel1.writeMicroseconds(PITCH_IN_LOCAL);
}
}
else if(distancef < 122) // closest distance that a user can still control the quad to move toward the wall { if(PITCH_IN_LOCAL > 1550) // limits the user to max of movement in this direction of very slow { servoChannel1.writeMicroseconds(1550); } else { servoChannel1.writeMicroseconds(PITCH_IN_LOCAL); // allows the user to slowly close on the obsticle } } else if(distancef < 183) // less limited and further away from the wall currently at the 6 ft range { if(PITCH_IN_LOCAL > 1600) { servoChannel1.writeMicroseconds(1600); // same as before limits users max to slow approach } else { servoChannel1.writeMicroseconds(PITCH_IN_LOCAL); } } else if(distancef < 245) // even less limited further still from the wall currently at 8 ft range { if(PITCH_IN_LOCAL > 1650) { servoChannel1.writeMicroseconds(1650); // same as before limits users max to slightly faster approach } else { servoChannel1.writeMicroseconds(PITCH_IN_LOCAL); } } else
{
servoChannel1.writeMicroseconds(PITCH_IN_LOCAL);
}
}
else
blah blah blah from above with similar changes
These changes that I have highlighted in yellow did fix the logic problems I was having while using static distances.
Now what do I think may be going wrong with my ultrasonics. Possibly the way I have defined the loop
What I have:
#define pingcnt 6 // define number of pings to loop through for ultrasonic pings
int avgf[pingcnt]; //array for front ultrasonc sensor
int avgb[pingcnt]; //array for rear ultrasonc sensor
int avgr[pingcnt]; //array for right ultrasonc sensor
int avgl[pingcnt]; //array for left ultrasonc sensor
What I am going to try Monday
int pingcnt = 6; // define number of pings to loop through for ultrasonic pings
int avgf[pingcnt]; //array for front ultrasonc sensor
int avgb[pingcnt]; //array for rear ultrasonc sensor
int avgr[pingcnt]; //array for right ultrasonc sensor
int avgl[pingcnt]; //array for left ultrasonc sensor
Simple change really. I hope that I am correct in assuming that I was stupidly trying to define a constant number incorrectly. I don't really know why I tried using the #define instead of making it an int variable anyway. I will still need to tweak the code a bit more.
I did see that there was a problem when just assigning values to the distances within the segment of the code that the interrupts were off. I'm not sure why that is, further testing will be required. I would rather ping my ultrasonics without having pesky interrupts doing their thing and you know, interrupting them.
Since the nature of how the RC signals are being utilized, they are constantly being updated whether the user is changing the hand held controller or not. That stick position is still being sent and updated. So the stick sitting at 1500 is going to update to 1500 even if it was 1500 during the previous loop. Sorry if I lost anyone reading this there.
Well back to being lazy today. More to come later this week.