import ioio.lib.api.DigitalOutput;
import ioio.lib.api.IOIO;
import ioio.lib.api.PulseInput;
import ioio.lib.api.PulseInput.PulseMode;
import ioio.lib.api.exception.ConnectionLostException;
public class UltraSonicSensors
{
private static final int LEFT_ULTRASONIC_INPUT_PIN = 35;
private static final int LEFT_STROBE_ULTRASONIC_OUTPUT_PIN = 15;
private final PulseInput leftInput;
private DigitalOutput leftStrobe;
private float leftDistance;
private IOIO ioio;
public UltraSonicSensors(IOIO ioio) throws ConnectionLostException
{
this.leftInput = ioio.openPulseInput(LEFT_ULTRASONIC_INPUT_PIN, PulseMode.POSITIVE);
this.leftStrobe = ioio.openDigitalOutput(LEFT_STROBE_ULTRASONIC_OUTPUT_PIN);
this.ioio = ioio;
}
public void read() throws ConnectionLostException, InterruptedException
{
read(leftStrobe, leftInput);
}
private void read(DigitalOutput strobe, PulseInput input) throws ConnectionLostException, InterruptedException
{
ioio.beginBatch();
strobe.write(true);
strobe.write(false);
ioio.endBatch();
this.leftDistance = input.getDuration();
}
public float getLeftDistance()
{
return leftDistance;
}
}
--
You received this message because you are subscribed to the Google Groups "ioio-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ioio-users+...@googlegroups.com.
To post to this group, send email to ioio-...@googlegroups.com.
Visit this group at http://groups.google.com/group/ioio-users.
For more options, visit https://groups.google.com/d/optout.
Can you send me the most "correct" version of your code that demonstrates the issue?
I can probably make the necessary changes to sync () if this is indeed a problem.
Thanks for the ideas. I've tried many combinations of synch, readBuffered...etc, but unfortunately it still reads very small numbers...probably measuring the last part of the trigger pulse. Is there any way that I can delay the read by a couple of hundred micro seconds? Could you do the..... sync() call "send" half inside the batch and "wait" half outside thing?Thanks for all the help. The kids are trying to use these sensors for iARoC 2014 (the International Autonomous Robot Competition) here in San Diego.
--
You received this message because you are subscribed to a topic in the Google Groups "ioio-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ioio-users/3MDLEEKtejY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ioio-users+...@googlegroups.com.
This code doesn't have the sync() call I proposed. It should come after the batch.
Your local leftDistance variable is shadowing the class field...
--
You received this message because you are subscribed to a topic in the Google Groups "ioio-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ioio-users/3MDLEEKtejY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ioio-users+...@googlegroups.com.
public void read() throws ConnectionLostException, InterruptedException {
ioio.beginBatch();
leftStrobe.write(false);
leftStrobe.write(true);
leftStrobe.write(false);
leftInput = ioio.openPulseInput(LEFT_ULTRASONIC_INPUT_PIN,
PulseMode.POSITIVE);
ioio.endBatch();
leftDistance = (int) (leftInput.getDurationBuffered() * 1000000);
leftInput.close();
SystemClock.sleep(100);
dashboard.log(leftDistance + "");
}
It makes one reading and then hangs up. How do I time out if I want stop waiting?Yes. This is what we tried before. I'm still under the impression that it should have worked but you've reported that it doesn't.
Earlier on this thread I answered this question. Essentially you can have a second thread interrupt the blocked thread to unblock it. A TimerTask is a convenient way to achieve this. You can wrap the whole process in a method that would look pretty much like the interface you purposed.
private int read(DigitalOutput strobe, PulseInput input, int inputPin) throws ConnectionLostException, InterruptedException // Order of following statements is very important...do not change{int distance = 0;ioio.beginBatch();strobe.write(true);input = ioio.openPulseInput(inputPin, PulseMode.POSITIVE);ioio.endBatch();SystemClock.sleep(40);strobe.write(false);distance += (int) (input.getDuration() * CONVERSION_FACTOR);input.close();return distance;}
public void readRight() throws ConnectionLostException, InterruptedException
{//This code works with the 4-pin sensor...don't change anything!
rightStrobe.write(true);
SystemClock.sleep(10);
rightStrobe.write(false);
rightDistance = (int) (rightInput.getDuration() * CONVERSION_FACTOR);
}
When you look at the waveforms, what do you see as the output pulse? My guess would be that it is very narrow, in the order of a couple of usec perhaps, and if that's indeed the case, it is likely because both messages comprising the pulse got collapsed into the same packet over one of the slower connections such as Bluetooth. In short, trying to achieve precise timing of any sort at this time scale is a bad idea. It would be possible to add a one-shot feature to the IOIO to achieve that. If you want this reading periodically, consider using a PwmOutput to keep triggering the sensor without your intervention at very precise pulse widths and period. Another option would be to use a version of those sensors that emits an analog voltage corresponding to the distance.
Visit this group at https://groups.google.com/group/ioio-users.
ioio.beginBatch();I get this beautiful result:
rightStrobe.write(true);
rightStrobe.write(false);
ioio.endBatch();
rightStrobe.write(true);
SystemClock.sleep(10);
rightStrobe.write(false);
I feel like I gave you my best advice, but you seem to insist on doing it in a way that's not supposed to work.
Use PWM output to generate periodic, precisely timed trigger pulses.
No threads involved and nothing asynchronous. You set the PWM once during setup(), then you getDuration() whenever you please.
Good question. Currently the only way to ensure this level of sync is the motion control API. Alternatively, if your time constants are coarse enough, you can open multiple PWM channels running at slow rates and insert delays between the open command (order of 10's of ms as you have seen with your experiments). The ideal solution would have been a one-shot function, which is easy to implement using an output compare module, but this doesn't currently exist.
You received this message because you are subscribed to a topic in the Google Groups "ioio-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ioio-users/3MDLEEKtejY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ioio-users+...@googlegroups.com.
Because there's no guarantee hour long it would take between when your command executed on the Android and when the actual pin voltage changes. What you're seeing when having a short (or no) delay between the commands is that sometimes they would end up actually getting executed a very short gap between them.
Coming to think of it, if you only care about minimum duration, you can add a ioio.sync() call after starting the pulse and before starting the delay. This will guarantee that the delay begins after the pin has already been set. This will allow you to set a 1ms sleep without the pulse collapsing, but no guarantees on maximum width, it may come out wider than 1ms.
I'm having difficulty bringing up one of my roomba boards with ioio cIrcutry on the board. It would be really nice if I could have a hex file of your blink program. I have a pickit3 that can load but nothing else works. I don't have a development environment set up for the pic so compiling would be a big job. Thanks.
You received this message because you are subscribed to a topic in the Google Groups "ioio-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ioio-users/3MDLEEKtejY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ioio-users+...@googlegroups.com.
Ok. I'll try to get it working on another Mac. I'll let you know what happens.
Sent from my iPhone
Can you just get it to work? Seems like a problem with a specific computer. I'm very regularly using a MacBook as well as Windows for this purpose. I've had reports on IOIODude 1.03 not working on Linux whereas 1.02 does, but I don't think it's that badly broken that you cannot get it to work with very little effort. It will be much more beneficial for you in the long term. My schedule doesn't really allow me to be very responsive to requests for building custom images for custom boards at the moment.
On Thu, Apr 21, 2016 at 5:28 PM, Vic Wintriss <sd...@me.com> wrote:
In using a Mac. Iodide doesn't seem to work.
Sent from my iPhone
Can you put on a bootloader and then use the blink ioioapp file with IOIODude?
On Thu, Apr 21, 2016 at 4:57 PM, Vic Wintriss <vic.wi...@gmail.com> wrote:
I'm having difficulty bringing up one of my roomba boards with ioio cIrcutry on the board. It would be really nice if I could have a hex file of your blink program. I have a pickit3 that can load but nothing else works. I don't have a development environment set up for the pic so compiling would be a big job. Thanks.
--
You received this message because you are subscribed to the Google Groups "ioio-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ioio-users+unsubscribe@googlegroups.com.
To post to this group, send email to ioio-...@googlegroups.com.
Visit this group at https://groups.google.com/group/ioio-users.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to a topic in the Google Groups "ioio-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ioio-users/3MDLEEKtejY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ioio-users+unsubscribe@googlegroups.com.
To post to this group, send email to ioio-...@googlegroups.com.
Visit this group at https://groups.google.com/group/ioio-users.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "ioio-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ioio-users+unsubscribe@googlegroups.com.
To post to this group, send email to ioio-...@googlegroups.com.
Visit this group at https://groups.google.com/group/ioio-users.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to a topic in the Google Groups "ioio-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ioio-users/3MDLEEKtejY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ioio-users+unsubscribe@googlegroups.com.
Yes