View unanswered posts | View active topics It is currently Sun Apr 20, 2014 2:33 pm






Reply to topic  [ 11 posts ] 
lego-ultrasound.h problem 
Author Message
Novice

Joined: Sun Feb 24, 2008 6:15 pm
Posts: 50
Post lego-ultrasound.h problem
HI,

I'm trying to use the lego-ultrasound driver in order to have single shot and read multi distances. But i've a problem.
The function USreadDistances and USsetSingleMode return always false! the error is : ERR_COMM_BUS_ERR. The port S3 is parameter as a sensorI2CCustom.
if i use the robotc function and parameter my sensor as a Sonar i get good results...
Do i need to use a specific function before call USreadDistances and USsetSingleMode ?
The sample include with the driver is for the HTMux ...


Regards

Thibaud.

_________________
My Eurobot team website :
http://blog.mlrobotic.com/


My MOCs :
http://nxtgen.6mablog.com


Sat Apr 27, 2013 4:05 pm
Profile WWW
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3107
Location: Rotterdam, The Netherlands
Post Re: lego-ultrasound.h problem
Could you show me the entire program?

= 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]


Sat Apr 27, 2013 4:07 pm
Profile WWW
Novice

Joined: Sun Feb 24, 2008 6:15 pm
Posts: 50
Post Re: lego-ultrasound.h problem
sure!

Code:
#pragma config(Sensor, S1,     pressure,       sensorNone)
#pragma config(Sensor, S2,     clawLimit,      sensorReflection)
#pragma config(Sensor, S3,     distance,       sensorI2CCustom)
#pragma config(Motor,  motorA,          updown,        tmotorNXT, openLoop, reversed)
#pragma config(Motor,  motorB,          openclose,     tmotorNXT, openLoop)
#pragma config(Motor,  motorC,          compressor,    tmotorNXT, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#include "drivers\lego-ultrasound.h"


#define TEST_US 1

int _distance;

void initSensors()
{
//   USreset(distance);
   USsetSingleMode(distance);
}

tByteArray _dists;
int getDistance()
{

   
   unsigned int temp = 255;
//int d = SensorValue[distance];
//return d;}
//while(time1[T1] < 500 &&  !USsetSingleMode(distance))
//   {
//      wait10Msec(5);
//   }
   //USsetSingleMode(distance);
   wait1Msec(200);
   bool toto = USreadDistances(distance, _dists);

   int temp2 = USreadDist(distance);


      for(int i = 0; i <8; i++)
      {
         if(_dists[i] != 255 && _dists[i] <= temp && _dists[i] >0)
           temp  = _dists[i];
      }
      writeDebugStreamLine("%d", toto);
       writeDebugStreamLine("%d %d %d %d %d %d %d %d", _dists[0], _dists[1], _dists[2], _dists[3], _dists[4], _dists[5], _dists[6], _dists[7]);

  _distance = temp;
  ClearTimer(T1);

 //   if(_distance == 0)
 //      _distance = 255;
    return _distance;
}


task main()
{

   if( TEST_US)
   {
      int d = 0;
      clearDebugStream();
      initSensors();
      while(1)
      {
         //nxtDisplayClearTextLine(1);
      USsetSingleMode(distance);
      wait1Msec(100);
      bool toto = USreadDistances(distance, _dists);
      writeDebugStreamLine("%d", toto);
      writeDebugStreamLine("%d %d %d %d %d %d %d %d", _dists[0], _dists[1], _dists[2], _dists[3], _dists[4], _dists[5], _dists[6], _dists[7]);
      
         //d = getDistance();
         //nxtDisplayClearTextLine(1);nxtDisplayClearTextLine(2);
         //nxtDisplayClearTextLine(3);nxtDisplayClearTextLine(4);
         //nxtDisplayClearTextLine(5);   nxtDisplayClearTextLine(6);nxtDisplayClearTextLine(7);
         //nxtDisplayTextLine(4,"dist %d", d);
         wait1Msec(500);

      }
   }

}

_________________
My Eurobot team website :
http://blog.mlrobotic.com/


My MOCs :
http://nxtgen.6mablog.com


Sat Apr 27, 2013 4:13 pm
Profile WWW
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3107
Location: Rotterdam, The Netherlands
Post Re: lego-ultrasound.h problem
Are you using driver suite 3.3.x and ROBOTC 3.60? I will do some testing with this tomorrow (it's 22:00 here).

= 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]


Sat Apr 27, 2013 4:16 pm
Profile WWW
Novice

Joined: Sun Feb 24, 2008 6:15 pm
Posts: 50
Post Re: lego-ultrasound.h problem
i'm using Robotc 3.60 and last version of driver suite. (here it's 22:20 ;)) thanks for your test!

_________________
My Eurobot team website :
http://blog.mlrobotic.com/


My MOCs :
http://nxtgen.6mablog.com


Sat Apr 27, 2013 4:22 pm
Profile WWW
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3107
Location: Rotterdam, The Netherlands
Post Re: lego-ultrasound.h problem
This program works for me:
Code:
#pragma config(Sensor, S1,     distance,       sensorI2CCustom)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#include "lego-ultrasound.h"

tByteArray _dists;

task main()
{
  clearDebugStream();
  while(1)
  {
    if(!USsetSingleMode(distance))
      writeDebugStreamLine("error: USsetSingleMode");
    wait1Msec(100);
    if (!USreadDistances(distance, _dists))
      writeDebugStreamLine("error: USreadDistances");
    writeDebugStreamLine("%3d %3d %3d %3d %3d %3d %3d %3d", _dists[0], _dists[1], _dists[2], _dists[3], _dists[4], _dists[5], _dists[6], _dists[7]);
    wait1Msec(500);
  }
}

This is what I see in my debuglog:
Code:
 21  32 255 255 255 255 255 255
 21  32 255 255 255 255 255 255
 21  33  48 255 255 255 255 255
 26 255 255 255 255 255 255 255
 14  16  33  48 255 255 255 255
 20  32 255 255 255 255 255 255
 21  32 255 255 255 255 255 255
 21 255 255 255 255 255 255 255
255 255 255 255 255 255 255 255
 21  36 255 255 255 255 255 255
 21  32  48 255 255 255 255 255

Looks fine to me. Are you sure you have the sensor connected properly? Maybe change the sensor for another, or the cable?

= 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]


Sun Apr 28, 2013 5:54 am
Profile WWW
Novice

Joined: Sun Feb 24, 2008 6:15 pm
Posts: 50
Post Re: lego-ultrasound.h problem
it's very strange, with your code i get good results!!!!
Code:
 27  40 255 255 255 255 255 255
 27  34 255 255 255 255 255 255
 27  32 255 255 255 255 255 255
 27  33 255 255 255 255 255 255
 28  32  53 255 255 255 255 255
 41 255 255 255 255 255 255 255
 29  32  48 255 255 255 255 255
 29  32  48 255 255 255 255 255
255 255 255 255 255 255 255 255
255 255 255 255 255 255 255 255
255 255 255 255 255 255 255 255
 60 255 255 255 255 255 255 255
255 255 255 255 255 255 255 255
 35  48  65 255 255 255 255 255
  9  24  32 255 255 255 255 255
  9  25 255 255 255 255 255 255
  9  25 255 255 255 255 255 255
  9  25 255 255 255 255 255 255
 

thanks for your tests

_________________
My Eurobot team website :
http://blog.mlrobotic.com/


My MOCs :
http://nxtgen.6mablog.com


Sun Apr 28, 2013 7:08 am
Profile WWW
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3107
Location: Rotterdam, The Netherlands
Post Re: lego-ultrasound.h problem
I did have to sacrifice a goat to get it working, but after that, it was all smooth sailing.

= 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]


Sun Apr 28, 2013 7:29 am
Profile WWW
Novice

Joined: Sun Feb 24, 2008 6:15 pm
Posts: 50
Post Re: lego-ultrasound.h problem
Sacrifice a goat... Excellent idea I will remember it!

:lol:

_________________
My Eurobot team website :
http://blog.mlrobotic.com/


My MOCs :
http://nxtgen.6mablog.com


Sun Apr 28, 2013 10:34 am
Profile WWW
Rookie

Joined: Mon Jun 06, 2011 5:13 am
Posts: 5
Post Re: lego-ultrasound.h problem
In Thibaud's code, there is 300ms between "USsetSingleMode(distance)" and "USreadDistances(distance, _dists)"
in Xander's code there is 100ms between "USsetSingleMode(distance)" and "USreadDistances(distance, _dists)"

This difference can explain the two behaviors ?


Thu May 02, 2013 11:23 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3107
Location: Rotterdam, The Netherlands
Post Re: lego-ultrasound.h problem
Maybe :) I don't know. As far as I know the 0x42 (and up) registers contain the last 8 measured values, they shouldn't change until the next singleshot command.

= 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]


Thu May 02, 2013 12:15 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 11 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.