IR sensor implementation problem

Hi-,

Recently I tried to add IR sensors to APM board for obstacle avoidance. I am using an APM1 board, and an expansion port on the IMU shield board to receive analog-in data from an IR sensor. A Maxsonar is hook up too.

Then I used the visual micro debugger to read out the variable values. I found that SharpIR_dist kept being 20 without any change, which means the IR sensor is never working. Any help? Thanks in advance.

The codes I added in the program are as below:
In the ArduCopter.pde:
#define SharpIR_trigger 60
#define CONFIG_SHARPIR_SOURCE_ADC_CHANNEL 6 // on expansion ports

ModeFilterInt16_Size5 SharpIR_mode_filter(2);
AP_AnalogSource_ADC SharpIR_analog_source(&adc, CONFIG_SHARPIR_SOURCE_ADC_CHANNEL, 1);
AP_RangeFinder_SharpGP2Y SharpIR(&SharpIR_analog_source, &SharpIR_mode_filter);

static int16_t SharpIR_dist;
static bool obstacle = false;

SharpIR_dist = SharpIR.read();
if(SharpIR_dist <= SharpIR_trigger) // obstacle detected in front
obstacle = true;
else
obstacle = false;

In the Attitude.pde:
if(obstacle)
target_angle += 3000; // increase roll angle by 30 deg if obstacle detected, to keep away from the obstacle

A debugging screen capture is attached.

Thanks,-yangbo

irsensor.jpg

You need to be a member of diydrones to add comments!

Join diydrones

Email me when people reply –

Replies

  • Hi! I try to implement my IR sensors on my code and wondered where you put those lines in Attitude.pde :

    if(obstacle)
    target_angle += 3000; // increase roll angle by 30 deg if obstacle detected, to keep away from the obstacle

    Did you create a new function for obstacle avoidance or did you just add those lines in an already existing function like "get_stabilize_roll"?

    I'm a beginner and i'm looking for some help! :)

    Cheers.

This reply was deleted.

Activity

Neville Rodrigues liked Neville Rodrigues's profile
Jun 30
Santiago Perez liked Santiago Perez's profile
Jun 21
More…