Re: Ultrasonic sensor interactions

"John Hansen" <[email protected]> Mon, 22 May 2006 21:50:26 GMT
Newsgroups gmane.comp.hardware.lego.robotics
Organization None
Message-ID <[email protected]>
In lugnet.robotics, Philippe Hurbain wrote:
>>> At low level sample rate can be changed - and even a single
>>> shot mode is available - but presently NXT-G doesn't give
>>> access to these features
>>
>>    Have you been able to verify this? I know there are FW commands that claim to
>> do this, but I've not seen it provably done as yet. And would *love* to hear
>> it's possible.
>
> Yes, that's theoretical, I have yet to do detailed testing. Perhaps John Barnes
> already did that?
>

I can confirm that the 0x2, 0x41, 0x0 "off" command does, indeed, turn off the
clicking sound that you can hear coming from the US sensor.  

I can also confirm that the 0x2, 0x40, 0xNN "set measurement interval" command
does set the measurement interval to the specified value.  Setting it to 0xff
makes the clicking slow to about once every 2.5 seconds.

dseg	segment
;------- definitions -------

TCommLSWrite	struct
 Result		sbyte
 Port		byte
 Buffer		byte[]
 ReturnLen	byte
TCommLSWrite	ends

;------- declarations -------
thePort byte 0
lswArgs TCommLSWrite
bufUSInterval byte[] 0x2, 0x40, 0xff // set interval to max value (255)

dseg	ends
; -------------- program code --------------
thread main
// configure the sensor type
	setin	IN_TYPE_LOWSPEED_9V, thePort, Type
	setin	IN_MODE_RAW, thePort, InputMode
        // set the UltraSonic sensor measurement interval
	mov	lswArgs.Port, thePort
	mov	lswArgs.Buffer, bufUSInterval
	set	lswArgs.ReturnLen, 0
	syscall	CommLSWrite, lswArgs
	exit
endt


(that's another 168 byte executable)

I can also confirm that setting the one-shot command triggers a single burst of
measurement each time the command is sent.

; -------------- variable declarations --------------
dseg	segment
;------- definitions -------

TCommLSWrite	struct
 Result		sbyte
 Port		byte
 Buffer		byte[]
 ReturnLen	byte
TCommLSWrite	ends

;------- declarations -------
thePort byte 0
lswArgs TCommLSWrite
bufUS1Shot byte[] 0x2, 0x41, 0x1 // one-shot mode
w15ra sbyte -1

dseg	ends
; -------------- program code --------------
thread main
// configure the sensor type
  setin IN_TYPE_LOWSPEED_9V, thePort, Type
  setin IN_MODE_RAW, thePort, InputMode

Forever:
  // do a 1-shot
  mov lswArgs.Port, thePort
  mov lswArgs.Buffer, bufUS1Shot
  set lswArgs.ReturnLen, 0
  syscall CommLSWrite, lswArgs
  
  subcall wait1500, w15ra

  jmp Forever
  
  exit
endt

thread wait1500
dseg segment
  now  dword
  then dword
dseg ends
	gettick now
	add then, now, 1500
waiting:
	gettick now
	brcmp LT, waiting, now, then

	subret w15ra
endt

That's a 226 byte executable.  

I would predict that the event capture mode (0x2, 0x41, 0x3) would work as
advertised as well and that when multiple sensors are around it would adjust the
measurement interval to avoid conflict.  How well that works in practice will
require some testing.  Unfortunately, NXT-G is hard-coded to use continuous
measurement mode (0x2, 0x41, 0x2) so running one of these tiny programs to
configure a different mode would be useless because the configuration of the
sensor will be immediately overwritten by the first NXT-G program that uses the
US sensor.

John Hansen