Code your drone: How to add additional hardware to Flyver
The Flyver team continues to do amazing work growing their offerings and we are excited to be partnering with them in sharing their insights. For those of you familiar with Flyver, or those of you with a software development background looking to make your drone do some amazing things, read on and, in this article you will learn how to add additional hardware to Flyver.
In Flyver all sensors and outputs are connected to the Flyver Message Queue. This makes the system very flexible and scalable, allowing for all kinds of devices to work with the SDK
Flyver Configuration I
IOIO OTG Sensors
Android / Java
Adding new IOIO sensors requires basic knowledge about input/outputs. This article assumes familiarity with the topic and that the user will be able to select the right pins.
Wire your sensor to the IOIO OTG board.
- Add a new class under FlyverCore -> statedata -> IOOISensors
- Extend the IOIOSensor class.
- Register pins under setup(). Details could be find under the IOIO OTG documentation
- Write your input data gathering under the loop of process(). Details could be find under the IOIO OTG documentation
- Send data thorough the message queue with sendData(Object); This data follows the selected topic and could be obtained back from anywhere though the consumer interface of the message queue.
- Initialize sensor under FlyverCore -> BaseApp.java
Existing sensor implementations There are already implementations of few sensors which could be used and modified easily. FlyverCore -> statedata -> IOIOSensors
Example:
public class UsRangeFinder extends IOIOSensor{
private int triggerPin;
private int echoPin;
float distance;
private PwmOutput trigger; // Ultrasonic range finder trigger
private PulseInput echo; // Ultrasoni range finder echo
public UsRangeFinder(String TOPIC, int triggerPin, int echoPin) {
super(TOPIC);
this.triggerPin = triggerPin;
this.echoPin = echoPin;
}
@Override
public void setup(IOIO ioio_) throws ConnectionLostException {
echo = ioio_.openPulseInput(echoPin, PulseInput.PulseMode.POSITIVE);
trigger = ioio_.openPwmOutput(triggerPin,16);
}
@Override
public void process(IOIO ioio_) throws ConnectionLostException, InterruptedException {
trigger.setPulseWidth(8000);
distance = (echo.getDuration() * 1000 * 1000 ) / 29f / 2f;
if (distance>2 && distance < 700){
sendData(distance);
}
}
}
Getting the sensor data example
public class FloorDistanceSensor implements FlyverMQConsumer {
float distance;
/* Constants */
public static String TOPIC = “distance”;
/* End of */
public LocationServicesSubsciber(){
MainController.getInstance().getMessageQueue().registerConsumer(this, TOPIC);
}
@Override
public void dataReceived(FlyverMQMessage message) {
distance = (Float) message.data;
}
}
IOIO OTG Outputs
- Add a new class under FlyverCore -> microcontrollers -> IOOIOutputs
- Extend the IOIOOutput class.
- Register pins under setup(). Details could be find under the IOIO OTG documentation
- Write your output data under the loop of process(). Details could be find under theIOIO OTG documentation
- Initialize output under FlyverCore -> BaseApp.java
Android USB Devices
Android naturally supports many USB devices which could be used. At this moment Flyver SDK does not have support for devices which are not supported by Android. Support of depth cameras, infrared cameras and more is expected.