View unanswered posts | View active topics It is currently Thu Nov 27, 2014 8:15 pm






Reply to topic  [ 20 posts ]  Go to page Previous  1, 2
ultrasonic sensor single shot function needed 
Author Message
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post Re: ultrasonic sensor single shot function needed
hello,
I guess my two pings actually won't be made too fast:

Code:
SensorType(S1, SensorSonarPing): // defines single ping US sensor (1x fire, then listen)
SensorType(S2, SensorSonarPing):
int svar[2];

while (true); {  // this loop will appear only inside a single task which can be set to "idle"
  sVar[0]=SensorValue (0); // 1x US ping (1x fire, then listen), assign result to a local var
  wait1mSec(50);
  sVar[1]=SensorValue (1);
  wait1mSec(100);}

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Sat Sep 27, 2008 4:53 am
Profile
Creator
Creator

Joined: Fri Feb 09, 2007 9:21 am
Posts: 615
Post Re: ultrasonic sensor single shot function needed
Ford Prefect wrote:
hello,
I guess my two pings actually won't be made too fast:

Code:
SensorType(S1, SensorSonarPing): // defines single ping US sensor (1x fire, then listen)
SensorType(S2, SensorSonarPing):
int svar[2];

while (true); {  // this loop will appear only inside a single task which can be set to "idle"
  sVar[0]=SensorValue (0); // 1x US ping (1x fire, then listen), assign result to a local var
  wait1mSec(50);
  sVar[1]=SensorValue (1);
  wait1mSec(100);}

This is not going to do what you intended.

When you set up a sensor as "ultrasonic type" you "turn on" a background firmware device driver that runs continuously polling the ultrasonic sensors. It first starts the sensor hardware into "continuous poll mode". When you reference "SensorValue" it simply retrieves the last value polled by the device driver; it does not suspend your program while it does a I2C read to poll the sensor. The actual I2C reads of the sensor are done by the background task independent of the user's program.

This is different than the NXT-G code to operate a ultrasonic sensor. It does not have the background device driver. When you use a NXT-G block to get the value of a ultrasonic sensor (or any other I2C sensor type) it actually does an I2C message to read value from the sensor. This read -- which takes 4 milliseconds or so -- is done within the NXT-G block. During this time, your program is "stalled". The NXT-G code is not using "single shot mode"; on the first read, it sets the sensor up into "autonomous continuous poll mode".


NOTE: Your sample code uses the type "SensorSonarPing". My assumption is that this is just a typo as it is not a valid sensor type.


Sat Sep 27, 2008 5:37 pm
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post Re: ultrasonic sensor single shot function needed
Quote:
NOTE: Your sample code uses the type "SensorSonarPing". My assumption is that this is just a typo as it is not a valid sensor type.
YES, sure!
This SensorSonarPing should be a NEW sensor type which HAS the single shot function that I need - and the "continuous poll mode" is suspended by this. It simply
- sends a sonar ping
- then switches to "listen mode" and waits for an echo to come ("sonar event")
- and returns the FIRST sonar echo delay time to the read function SensorValue(port)

this is how I imagine it COULD happen, it's sort of a model - don't know how to implement this...

do you? :?

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Sat Sep 27, 2008 5:56 pm
Profile
Creator
Creator

Joined: Fri Feb 09, 2007 9:21 am
Posts: 615
Post Re: ultrasonic sensor single shot function needed
Ford Prefect wrote:
This SensorSonarPing should be a NEW sensor type which HAS the single shot function that I need - and the "continuous poll mode" is suspended by this. It simply
- sends a sonar ping
- then switches to "listen mode" and waits for an echo to come ("sonar event")
- and returns the FIRST sonar echo delay time to the read function SensorValue(port)

this is how I imagine it COULD happen, it's sort of a model - don't know how to implement this...

do you? :?

There are several programs in the "Samples" folder that can get you started.

Look at the file "New Sensor Driver.c" and also "I2C Coding Examples.c". The first is pretty close to what you want to do.


Sat Sep 27, 2008 11:00 pm
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post Re: ultrasonic sensor single shot function needed
hello,
sorry, I neither have this folder, nor these kind of programs (1.40 public), nor can I work with I2C code, I don't understand this - it's too complicated for me.
I just want the sensor
- to fire once
- and to listen to the shortest echo that returns

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Sun Sep 28, 2008 5:38 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 20 posts ]  Go to page Previous  1, 2

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.