Hello

I was trying to get the PIR sensor working on my InMoov. I saw some method about it in InMoov.java but it was no worky.

Today I have dig into the code to found out what's going on and it look like it's stuck in a between state with the arduino MRLComm change. Things are not hard to fix, but i'm a bit confuse about wich way to go

 

I have manage to get it kinda worky, but not sure I have follow the right way. So i'm asking the captains for some guidance.

So here my comments about it

 public void startPIR(String port, int pin) throws IOException {
  speakBlocking(String.format("starting pee. eye. are. sensor on port %s pin %d", port, pin));
  if (arduinos.containsKey(port)) {
   Arduino arduino = arduinos.get(port);
   arduino.connect(port);
   arduino.setSampleRate(8000);
--> this do nothing, see comment about SampleRate
   arduino.digitalReadPollingStart(pin); --> Required some change in MRLComm to get worky, but never seem to trigger from here in my test
   pirPin = pin;
   arduino.addListener("publishPin", this.getName(), "publishPin"); --> This is working, but since digitalRead... is not, nothing happen

  } else {
   // FIXME - SHOULD ALLOW STARTUP AND LATER ACCESS VIA PORT ONCE OTHER
   // STARTS CHECK MAP FIRST
   log.error(String.format("%s arduino not found - start some other system first (head, arm, hand)", port));
  }

}

 

I have need to make a few change in MRLComm.ino to have it worky. The method for digitalReadPollingStart is all comment out and there is nothing reading digital pins.

I have add

#define SENSOR_TYPE_DIGITAL_PIN_READER 3
 
and duplicate the code for analogReadPolling, replacing word analog by digital
 
then set the SENSOR_MAX value to it's original value define by the board. The InMoov nervo board have PIR connected to pin 23 so it won't be working with SENSOR_MAX limited to 20
 
This is worky, but I was a bit confuse because there is a SENSOR_TYPE_PIN defined that may have been define for that purpose, but that is override by SENSOR_TYPE_ANALOG_PIN_READER
 
about arduino.digitalReadPollingStart(pin). It don't seem to do anything in the InMoov.java startPIR method.
I have try to start the digitalReadPolling from my inMoov python script using a service that share the arduino, but that still don't work. But if I wait that everything load up, then open a new python script and run the command: i01.mouthControl.arduino.digitalReadPollingStart(23), everything start to work like a charm (motor detaching after a time inactivity, and attaching when the PIR activate), but I really don't understand why it was not working in the InMoov.java and when set in my main script.
 
about SET_SAMPLE_RATE
the arduino.setSampleRate method set a variable in the MRLComm.ino, but that variable is not used anywhere in the code. the SENSOR_TYPE_ANALOG_PIN_READER (and the DIGITAL_PIN_READER that I have create) use pin.rateModulus to control the sample rate. I think pin.rateModulus is a better way to go, but there is no method to set it's value (except when defining PULSE sensor). By default it's set to 1 wich made the arduino report the reading of the pin every loop, that the value of the pin reading change or not.
 
Sorry for the very long post
 
Christian

Hi moz4r

 

this is the MRLComm I use to activate the digital read in MRL. It only report back when the value of the pin change (but for a PIR sensor that's what you need)

http://beliweb.net:8088/test/MRLComm32a.mod.txt

and my python script that I use to test it

from datetime import datetime
from time import sleep
arduino = Runtime.createAndStart("arduino","Arduino")
arduino.setBoardMega()
arduino.connect("COM15")
 
def pinData(pin):
       print str(pin.value)+"-"+str(pin.pin)
 
arduino.addListener("publishPin","python","pinData")
sleep(2)
arduino.digitalReadPollingStart(23)
 
I hope it help you
Christian