Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   INFRARED SENSORS (http://www.chiefdelphi.com/forums/showthread.php?t=85054)

krudeboy51 08-04-2010 06:18

INFRARED SENSORS
 
can any one please assist me on how to program an infrared sensor in autonomous mode, and give a sample code for it in windriver c++?? (i never learned how to program any)


Quote:

is it possible to use an if statement in void autonomous??
should the infrared sensor be wired to the digital sidecar as a digital input, or a pwm port?

Alan Anderson 08-04-2010 08:33

Re: INFRARED SENSORS
 
"Programming" an input is just a matter of reading its value and testing it to decide what the program should do. What do you want the program to do?

What output does the sensor provide? If it's the equivalent of a switch, it goes to a digital input. If it's a varying voltage related to the distance from the sensor to the target, it goes to an analog input.

You can do anything in the autonomous routine that you would do in teleoperated mode.

PWM pins on the Digital Sidecar are outputs only. They can't read sensors.

krudeboy51 08-04-2010 15:15

Re: INFRARED SENSORS
 
Quote:

Originally Posted by Alan Anderson (Post 949883)
"Programming" an input is just a matter of reading its value and testing it to decide what the program should do. What do you want the program to do?

i want when the infrared sensor is interrupted the robot stops, i declared in class and in public as a digital input, but i dont know how to write a code for it, all i have is:

Quote:

class:
DigitalInput *InfraredSensor;
public:
InfraredSensor = new DigitalInput(1);
void Autonomous:
if (InfraredSensor->????())
{
myRobot->Set(0.0);
but i dont know what to put where the question marks are.

Alan Anderson 08-04-2010 15:42

Re: INFRARED SENSORS
 
InfraredSensor->Get() will return the state of the input. This method is featured prominently in the documentation for the DigitalInput class, isn't it?

krudeboy51 08-04-2010 18:02

Re: INFRARED SENSORS
 
Quote:

Originally Posted by Alan Anderson (Post 950201)
InfraredSensor->Get() will return the state of the input. This method is featured prominently in the documentation for the DigitalInput class, isn't it?

one more question, what values should i set for the sensor?

Quote:

InfraredSensor->Get(?????))
or
InfraredSensor->Get()?????)
which one, and what should i put in the places where the question mark are?? should i put a number or true or false??

Alan Anderson 08-04-2010 21:18

Re: INFRARED SENSORS
 
Quote:

Originally Posted by krudeboy51 (Post 950349)
one more question, what values should i set for the sensor?

It will return a boolean value. Typically true means the signal on the DIO pin is a high voltage (5v) and false means it is a low voltage (0v). Since there is a pullup resistor on the input, an open circuit will read true and a switch closure to ground will read false.

I don't really understand the rest of your question, but the documentation should answer anything you need to know.

Al3+ 09-04-2010 01:59

Re: INFRARED SENSORS
 
InfraredSensor->Get() has no parameters, so nothing needs to go inside the parentheses. I think that was the question.

You want something like
Code:

if (InfraredSensor->Get())
  myRobot->Set(0.0);

This will set myRobot to 0 when the infrared beam is interrupted, assuming Get() returns true when interrupted. If it returns false, you'll have to flip it.

krudeboy51 09-04-2010 18:14

Re: INFRARED SENSORS
 
Thanks alot!! :)


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

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