IntelAcademic DIY 06 Maestro Bluetooth Card

32
Intel Do-It-Yourself Challenge Maestro Pololu card + Bluetooth Cédric Andreolli www.Intel-Software-Academic-Program.com [email protected] Intel Software 2013-02-08

Transcript of IntelAcademic DIY 06 Maestro Bluetooth Card

Page 1: IntelAcademic DIY 06 Maestro Bluetooth Card

Intel Do-It-Yourself ChallengeMaestro Pololu card + Bluetooth

Cédric Andreolliwww.Intel-Software-Academic-Program.com

[email protected] Software

2013-02-08

Page 2: IntelAcademic DIY 06 Maestro Bluetooth Card

Agenda

Page 3: IntelAcademic DIY 06 Maestro Bluetooth Card

Agenda

Introduction

How does it work ?

Sending commands via bluetooth

Adapting the project

Conclusion

Page 4: IntelAcademic DIY 06 Maestro Bluetooth Card

Introduction

Page 5: IntelAcademic DIY 06 Maestro Bluetooth Card

Introduction

We still want to use the micro Maestro card but we want to avoid using a USB cable.

This new approach offers many advantages :

- The USB cable can't be unplugged with unexpected vibrations

- The robot/drone will be lighter

- The Android phone will not have to be USB host

Page 6: IntelAcademic DIY 06 Maestro Bluetooth Card

Introduction

In the previous course, we learned how to build:

Page 7: IntelAcademic DIY 06 Maestro Bluetooth Card

Introduction

In this course, we will learn how to build:

Page 8: IntelAcademic DIY 06 Maestro Bluetooth Card

How does it work ?

Page 9: IntelAcademic DIY 06 Maestro Bluetooth Card

How does it work ?

We must use a bluetooth card.

You can use cheap cards such as the JY-MCU Bluetooth Wireless Serial Port Module (=~ 8$).

This card must be plugged with the micro maestro.

Page 10: IntelAcademic DIY 06 Maestro Bluetooth Card

How does it work ?

The Intel phone send the commands via bluetooth, the bluetooth card receives those commands and send them to the micro maestro card via serial port.

Page 11: IntelAcademic DIY 06 Maestro Bluetooth Card

Sending commands via bluetooth

Page 12: IntelAcademic DIY 06 Maestro Bluetooth Card

Sending commands via bluetooth

The android application will have to deal with bluetooth communications.

Bluetooth communications use sockets.

All the documentation can be found : http://developer.android.com/guide/topics/connectivity/bluetooth.html

Page 13: IntelAcademic DIY 06 Maestro Bluetooth Card

Sending commands via bluetooth

The Android interface:

BluetoothAdapter: Allows to get a reference on the bluetooth devices.

BluetoothDevice: Represents a device with bluetooth activated.

BluetoothSocket: A socket that allows to send data on a device.

We will only need those interfaces !

Page 14: IntelAcademic DIY 06 Maestro Bluetooth Card

Sending commands via bluetooth

Step 1: Retrieve the bluetooth adapter

Step 2: Get the list of bounded devices

Step 3: Iterates over those devices

Page 15: IntelAcademic DIY 06 Maestro Bluetooth Card

Sending commands via bluetooth

Step 4: Connect to the device

The UUID can be found in the documentation

Page 16: IntelAcademic DIY 06 Maestro Bluetooth Card

Sending commands via bluetooth

Once you have the output stream, you are ready to use the socket.

Sending a message via bluetooth is straight forward. Android provides high level interfaces to do it !

Page 17: IntelAcademic DIY 06 Maestro Bluetooth Card

Adapting the project

Page 18: IntelAcademic DIY 06 Maestro Bluetooth Card

Adapting the project

The previous project worked with a USB connection. It could be interesting to keep this possibility.

The best way is to create an interface !

Let's call this interface IMessageSender.

Page 19: IntelAcademic DIY 06 Maestro Bluetooth Card

Adapting the project

The IMessageSender interface provides a set of usefull methods that we will use to control a drone.

This interface must be implemented for the USB and for the bluetooth.

Page 20: IntelAcademic DIY 06 Maestro Bluetooth Card

Adapting the project

The bluetooth implementation is straight forward has we saw previously.

We just need to add few overhead to check that variables are correctly initialized.

The following slide shows the constructor of the class BluetoothMessageSender that implements IMessageSender.

Page 21: IntelAcademic DIY 06 Maestro Bluetooth Card

Adapting the project

Page 22: IntelAcademic DIY 06 Maestro Bluetooth Card

Adapting the project

Best practices !

Create a constant instead of using directly the UUID in the function call.

Log the errors and display them to let you know if something goes wrong.

Page 23: IntelAcademic DIY 06 Maestro Bluetooth Card

Adapting the project

How to send a command via bluetooth ?

We've seen that the bluetooth interface allows us to communicate via sockets.

We only need to write the appropriate set of bytes on the socket.

The commands can be found in the maestro documentation.

Page 24: IntelAcademic DIY 06 Maestro Bluetooth Card

Adapting the project

Here is a screenshot of the Pololu official documentation.

Page 25: IntelAcademic DIY 06 Maestro Bluetooth Card

Adapting the project

The Pololu card can understand different protocols. Our following examples will use the MINI SSC protocol.

This protocol requires short messages.

The following example shows how to reset the position of a servo motor to it's neutral point (127 because the range of the servo goes from 0 to 255).

Page 26: IntelAcademic DIY 06 Maestro Bluetooth Card

Adapting the project

We can now implement the method :

The parameter position is a value between 0 and 100. We need to rescale this value between 0 and 255 :

Page 27: IntelAcademic DIY 06 Maestro Bluetooth Card

Adapting the project

The full method :

Page 28: IntelAcademic DIY 06 Maestro Bluetooth Card

Adapting the project

Implement the interface for USB

We will not explain the USB implementation in details here (see previous course).

Use the constructor to initialize the USB connection.

Then re-implement each function of the IMessageSender interface.

Page 29: IntelAcademic DIY 06 Maestro Bluetooth Card

Conclusion

Page 30: IntelAcademic DIY 06 Maestro Bluetooth Card

Conclusion

Through the 2 previous set of slides, we've seen how to develop a server application that controls the pololu card via bluetooth or via USB.

Those courses are also a good illustration of the Android course.

You should be able to program some nice Android applications right now !

Page 31: IntelAcademic DIY 06 Maestro Bluetooth Card
Page 32: IntelAcademic DIY 06 Maestro Bluetooth Card

License Creative Commons - By 3.0

You are free:

to Share — to copy, distribute and transmit the work

to Remix — to adapt the work

to make commercial use of the work

Under the following conditions:

Attribution — You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work).

With the understanding that:

Waiver — Any of the above conditions can be waived if you get permission from the copyright holder.

Public Domain — Where the work or any of its elements is in the public domain under applicable law, that status is in no way affected by the license.

Other Rights — In no way are any of the following rights affected by the license:

Your fair dealing or fair use rights, or other applicable copyright exceptions and limitations; The author's moral rights; Rights other persons may have either in the work itself or in how the work is used, such as publicity or privacy rights.

Notice — For any reuse or distribution, you must make clear to others the license terms of this work. The best way to do this is with a link to this web page.

http://creativecommons.org/licenses/by/3.0/