View unanswered posts | View active topics It is currently Tue Sep 23, 2014 2:24 am






Reply to topic  [ 3 posts ] 
Using US Sensors in 'Single Shot Mode' 
Author Message
Rookie
User avatar

Joined: Tue Aug 11, 2009 11:49 pm
Posts: 38
Location: Tasmania, the Land Down Under, the Land Downunder!
Post Using US Sensors in 'Single Shot Mode'
I'm trying to use multiple Ultrasonic Sensors on a project, programmed with RobotC.

When using US Sensors in 'Event Capture Mode' with NXC I use:
Code:
    I2CWrite(US1, 0×41, 0×01);     // Set US1 Sensor in Event Capture Mode
    Dist1 = SensorUS(US1);
    Wait(50);
    I2CWrite(US1, 0×41, 0×00);     // Set US1 Sensor to Off
    DIS1 = NumToStr(Dist1);
    TextOut(0, LCD_LINE3, "US Sensor1 " + DIS1 + "   ");

But when it comes to RobotC I'm stumped. The best I could come up with using RobotC that compiled was:
Code:
    sendI2CMsg(US1, 0x41, 0x01);                     // Set US1 Sensor in Event Capture Mode
    wait1Msec(50);
    Dist1 = SensorValue[US1];
    sendI2CMsg(US1, 0x41, 0x00);                     // Turn off Sonar Sensor on Digital ports 1
    nxtDisplayTextLine(1, "US1:    ", "%d", Dist1);


Can anyone please point me in the right direction?

_________________
regards

Sparra Mc


Image


Last edited by sparramc on Fri Jul 06, 2012 5:48 am, edited 2 times in total.



Wed Jul 04, 2012 1:29 am
Profile WWW
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3223
Location: Rotterdam, The Netherlands
Post Re: Using US Sensors in 'Event Capture Mode'
Ray,

Have a look at the LEGOUS driver that comes with my suite. I have two functions in there:
Code:
/**
 * Get the distance values from the sensor
 * @param link the US port number
 * @return distance from the sensor or 255 if no valid range has been specified.
 */
int USreadDist(tSensors link)

Code:
/**
 * Configure the US sensor for Event Capture mode
 * @param link the US port number
 * @return true if no error occured, false if it did
 */
bool USsetEventCapture(tSensors link)

I haven't tested this, but what you could do is simply set it up for event capture and then call USreadDist() to get the data from it.
There is also:
Code:
/**
 * Turn the sensor off.
 * @param link the US port number
 * @return true if no error occured, false if it did
 */
bool USsetOff(tSensors link)

and a few others you might find useful :)

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Wed Jul 04, 2012 1:41 am
Profile WWW
Rookie
User avatar

Joined: Tue Aug 11, 2009 11:49 pm
Posts: 38
Location: Tasmania, the Land Down Under, the Land Downunder!
Post Solved: Using US Sensors in 'Single Shot Mode'
Thanx Xander.

Using Multiple Utrasonic (Sonar) Sensors together you need to configure the Sensors to use Single Shot Mode.

Code:
#pragma config(Sensor, S1,     US1,            sensorI2CCustom9V)
#pragma config(Sensor, S2,     US2,            sensorI2CCustom9V)
#pragma config(Sensor, S3,     US3,            sensorI2CCustom9V)
#pragma config(Sensor, S4,     US4,            sensorI2CCustom9V)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

/* Xander Soldaat's 'Third Party Driver' for the LEGO Sonar */
#include "drivers/LEGOUS-driver.h" 

task main()
{
  while(true)
  {
    nxtDisplayClearTextLine(5);
    USsetSingleMode(US1);                 // Set US1 Sensor in Single Shot Mode
    wait1Msec(50);                        // Wait to Capture Distance Value
    Dist1 = USreadDist(US1);              // Read the Sonar Sensor's Distance Value
    nxtDisplayTextLine(5, "%d", Dist1);
    USsetOff(US1);                        // Turn off Sonar Sensor on Digital ports 1
   }
}


More details at 'Blog'.

_________________
regards

Sparra Mc


Image


Fri Jul 06, 2012 5:18 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

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.