Saturday, February 20, 2016

Intro to RCcontroller




As an open source hardware enthusiast who loves to control my hardware with an android phone, I have endured the pain of having to write a new application for every hardware project I make. I finally decided to write a single app that would be able to control almost any device I can dream of building. Of course I can do that if I have a micro-controller on the remote device doing wireless serial communication with an android phone. Android’s switches and buttons represent ON/OFF controls while the like of a seekbar represents PWM control. I call my app, RCcontroller™.

RCcontroller™ is an android application for remotely controlling and monitoring a hardware device via Bluetooth, WiFi or USB radio. Researchers, hobbyists and students can build their own controller consisting of buttons, switches, joysticks, etc. to control a device they have built. This is one of the most versatile and easy-to-use app for IoT and robotics. It is a complete WYSIWIG tool and requires no programming experience all to use. Just drag and drop controls onto the screen, select your mode of communication and you are done. You can now not only control your device but track its location, stream video from it (if your remote device has a camera) and do other forms of parameter monitoring. Each controller is basically a JSON file defining the number of controls and parameters as well as their properties. You can build and sell your hardware and all users need to do is to download your controller and they can now control what you have built.
Let’s now move on to all the features of the app and how we can create our own controller in less than 10 minutes
When we first open the application, we are asked for storage permissions. You must accept this in order to save recorded video. We then see a dark screen like this: 

Control Centre:
 


  1. Calendar: Displays current time and date.
  2. Record screen: This is used to record the screen. Useful for when you want to record a video stream.
  3. Toggle drag controls: Allows you to drag and drop controls to preferred location on the screen.
  4. Toggle display calendar: Allows you to show/hide calendar.
  5. Toggle map display: Used to show/hide map. For a controller to support maps, it needs to have longitude and latitude as part of its parameter list.
  6. Toggle OSD graphics display: Shows/Hides OSD graphics. To show the azimuth dial and compass, you should have Azimuth as part of the parameter list. To show pitch/roll dial, you should have pitch/roll as part of the parameter list.
  7. Toggle MJPEG video streaming: Starts or stops streaming MJPEG video.
  8. Toggle wireless communication: Engages/Disengages communication with remote device via Bluetooth, WiFi or USB radio.
  9. Open Settings: Starts the setting activity where you can share, edit, copy, delete controllers or add a new one. You also select the currently active controller from this activity.
  10. Toggle action bar visibility: This shows/hides all the buttons in order to make the screen emptier.
  11. Control area: The whole dark area is valid to contain all your controls and parameters as well as stream video with the controls on the surface.
 


Control Types:





  1. Button: Value is either on/off. Sends a 1/0 to remote device.
  2. Switch: Value is either on/off. Sends a 1/0 to remote device.
  3. ToggleButton: Value is either on/off. Sends a 1/0 to remote device.
  4. SeekBar: Sends values ranging from supplied min to max values to remote device.
  5. JoyStick: Sends values as pan,tilt (x,y coordinate of joystick thumb with relative to the joystick view) to remote device.
  6. DevicePitch: Sends the smartphone’s pitch in landscape mode to the remote device. The format of this control can only be frequent.
  7. DeviceRoll: Sends the smartphone’s roll in landscape mode to the remote device. The format of this control can only be frequent.
     
 The textView above each control is the name of the control and the next text view is the value. The value textView tells you the control's value (which is sent to the remote device).



 Control Format:

Note: Before I make any progress, I want to say there is a video demonstration of everything on this page, so if you don't understand, the video might help.

The control format is defined by how often the control values are sent (wirelessly) to the remote device. The order in which the values are sent is based on the order in which you added the controls when you were setting up the controller. The control format can either be seldom or frequent.

Seldom control values are only sent to the remote device when at least one of these control values changes. The command payload, ie, the data that is sent to the remote device has a prefix of “S” and a suffix of “\n”. So based on the number of controls, say 3 switches, the command payload, using random values, will be something like this: “S0,9,1\n”

Frequent control values are sent to the remote device after every delay interval. So if we are using either Bluetooth, WiFi or USB radio and the Bluetooth delay, WiFi delay or the USB transceiver delay is set to 50 ms, the frequent control values will be sent to the remote device every 50 milliseconds. This command payload has a prefix of “F” and a suffix of “\n”. So based on the number of controls, say 3 switches, the command payload, using random values, will be something like this: “F0,9,1\n”.

Note: A joystick sends two values; pan and tilt. So if we have for example a joystick followed by a button as frequent controls, the payload, using random values, will be like this: “F0,0,0\n”. With the first two values representing the pan and tilt of the joystick and the last value representing the state of the button either 1 or 0.

Parameters are values sent from the remote device to RCcontroller, on your smartphone. This would eventually show up as a list on the top right corner of the Control Center. The payload has a “P” prefix and “\n” suffix so, using random values, with 3 parameters being sent to RCcontroller, the payload should look like this: “P0,9,100\n”.



Enough with the theory, we can now do really cool stuff. Based on the kind of communication you want to perform with a remote device, click on one of the following links to see how RC controller works. Navigate to the bluetooth example post on the right pane.





 

No comments:

Post a Comment