Author Topic: sharp ir code  (Read 1803 times)

0 Members and 1 Guest are viewing this topic.

Offline michaelghayesTopic starter

  • Jr. Member
  • **
  • Posts: 9
  • Helpful? 0
sharp ir code
« on: January 31, 2009, 01:07:48 AM »
i was wondering if someone could take the time to show me the code for using the sensor data from a sharo ir range finder.  I have everything hooked up on my robot and i can control the servos and make it moved in a preprogramed way, but i haven't figured out how to make the sensor do anything.  (im using an axon controller if that helps)
 there are 2 things id like to be able to do, and if i see the code for them i think i can figure everything else out

1)
I want to have the axon send the range that the ir sensor is perceiving through hyperterminal about once per second (not to fast) in inches or centimeters if possible.

2) I want to know how to get the range in cm or inches as a function so i can have somthing like

void control(void)
   {

   long unsigned int wheel_left=500;
   long unsigned int wheel_right=500;

   while(1)
   {
   
if(sensor() > 20){
   strait(100);
   }
   else
{
   reverse(100);
}
}

void strait(int s)
   {
      for (count = 1; count <= s; count++){
   wheel_left(1200);
   wheel_right(200);
   delay_ms(15);
}
}

void reverse(int rv)
   {
      for (count = 1; count <= rv; count++){
   
   wheel_left(400);
   wheel_right(1000);
   delay_ms(15);
   }
   }

unsigned int sensor(void)
       {
      ?????? what would i put in here to have this return the value of the sensor (on the header pin 0 (axon controller top row, im not sure what its called header I think)??????
}

etc...

could this work and if so, how would i do the sensor data thing, i have no idea how to read the sensors, and i don't know if i need to define them in hardware.c or in the sensors.c, please any help would be very helpful thanks

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,658
  • Helpful? 169
    • Society of Robots
Re: sharp ir code
« Reply #1 on: January 31, 2009, 07:24:28 AM »
You will find all code here:
http://www.societyofrobots.com/axon/axon_function_list.shtml

The default photovore code has lots of examples with lots of comments.

here are a few examples for you:
Code: [Select]
//create a variable
int sharp_IR;

//read raw data from sharp IR on pin 0
sharp_IR=a2dConvert8bit(0);

//or read Sharp IR data and convert to cm on pin 0
//if you were using the GP2D12 sensor, put that at the end, etc
sharp_IR=sharp_IR_interpret_GP2D12(0);
sharp_IR=sharp_IR_interpret_GP2Y0A02YK(0);
sharp_IR=sharp_IR_interpret_GP2D15(0);

//print the data to Hyperterminal
rprintf("value = %d\r\n",sharp_IR);


Offline michaelghayesTopic starter

  • Jr. Member
  • **
  • Posts: 9
  • Helpful? 0
Re: sharp ir code
« Reply #2 on: January 31, 2009, 03:48:56 PM »
thanks, that was really helpful and alot easier than i thought, i should be able to figure stuff out now :)

 


Get Your Ad Here