Android remote control app. Send up to three values over wifi using udp protocol



Download 21.74 Kb.
Date30.06.2017
Size21.74 Kb.
#22206
Hapti Remote Control Android App

Introduction


If you are a hobbyist or a robotics fan, you are going to like this android remote control app.

Send up to three values over wifi using UDP protocol.

And choose from three methods of input:


  • Touch

  • Slide

  • And even Tilt!

Plus receive information. This app’s integrated with Immersion MOTIV™ Haptic Effects so your phone vibrates based on feedback.

Android API 2.1 and above, open-source, and completely free

For more details on its features, see the next video in the series.

[made by Jonathan Abbott at CINVESTAV]


Features


We’re going to walk through the Hapti Remote Control Android App features to show how you really can customize the application for your needs.

We’re going to talk about:



  • The connections

  • The controls

  • The vibrations

  • The available languages

  • And advanced features such as artificial inertia

The Connections


Hapti can send up to three values that you can customize the order and the type. Say you want 3 floating point numbers - XYZ - big endian? Simple. Just make sure your output ranges can fit within the variable type.

Hapti uses UDP protocol. UDP protocol (as opposed to TCP protocol) doesn’t check that information arrived. But UDP protocol is fast and simple, and that’s why it is used here.


The Controls


The different options for controls really give this remote control app its power.

The Three Types of Input

Touch


Touching is pretty basic, wherever you put your finger on the screen, the position simply goes there. You can also add a simple return to center option, which makes it jump back to the starting position when you lift up your finger.

Slide


Sliding is useful for higher precision. You get the option of how the distance you slide relates to how much the actual position changes. For instance, .5 means that the pointer on the screen slides about half of the distance your finger does.

Tilt


Tilting lets you use the angle of the phone as input. Tilt also comes with its own special options.

  • The first option is ‘tilt lock’, which means that the position will only move if you are the touching the screen

  • The second option is whether you want position or velocity. With position, the position is just a linear scale from angle to position. With velocity, the velocity is proportional to how much you tilt the phone.

Note that with custom minimum and maximum angles, you can make the zero position be any angle. For X and Y tilt, I recommend smaller ranges of angles with the zero position close to zero degrees and I also recommend adding some artificial inertia under advanced options to limit jitteriness.

Other Control Options


For each coordinate, you can reverse the controls, set minimum and maximum values, and set a starting position. These limits and starting position match the actual output or value you want to send.

Note that the min and max values stay fixed; reversing just flips the output within the limits.


Vibrations


This android remote control app is haptic, meaning that you get touch sensation.

The app is integrated with Immersion MOTIV™ Haptic Effects so that you can have your phone vibrate based upon touching the screen or actual input such as forces.


Touch Feedback


There are literally over 120 different vibratory patterns that you can select from so that you first make contact with the screen, your phone vibrates. This is useful because it helps you to know if you’ve made contact and if you have the tendency to lift your finger off the controls.

Force Feedback


This application also vibrates to let you receive input or feedback. You can adjust the vibration intensity function as linear, exponential, square root, or on/off. You can also change the minimum value to eliminate effects of noise and the maximum value depending on your application. Integer values only.

Languages


This Android remote control application supports both English and Spanish.

Esté aplicación de control remoto de Androide incluye ambos español e inglés.

If other languages are desired, see the developer reference video.

Advanced Features

Appearance


You can change the orientation of the application, how much space is devoted to z control or the x/y control, and show a shadow position for z.

Artificial Inertia


If you want to slow down your robot, you can add artificial inertia.

The first most basic option is maximum speed.

The other option is a spring-mass-damper system. The app will automatically calculate the damping ratio ζ, the undamped natural frequency ω, and even what settings are needed to make it critically damped. Critically damped has the fastest spring-mass-damper response without overshoot.

You can optionally show the inertial position shown as a darkened image if desired.


Delays


If working with MATLAB, you may find it helpful to limit the rate at which you send data. The delays work on an “additional” rather than “on-the-go” basis.

The Socket Timeout option limits the amount of time the app will wait to receive input before restarting. Half a second is good. Large values may prevent the application from ending correctly.


Miscellaneous


Two other options are provided.

  • The reset option – view the option to start the position as the position ended from the previous time or from the start position in preferences. This may be useful if you accidently leave the application and want to resume from the same place.

  • Vibration duration – lets you determine how long to vibrate due to “force” feedback or until another packet is received.

Other information


To optimize the application you may want to limit other background tasks on your phone. Check your phone’s developer options.

In experimentation, we found that we were sending nearly 400 packets/s when we specified a 2.5 ms delay. However, the rate limiting factor was the rate at which new positions of touching the screen could be recorded. The actual rate of new information was about 90 Hz. Your phone may vary, and if you use artificial inertia, you should see new information more frequently.

If you want more options, you should watch the next video made for beginning developers.

[Made by Jonathan Abbott at CINVESTAV]


Hapti Android Remote Control App – Developer Details


This free open-source Android Remote Control App was designed to be customizable for other developers. It’s well commented, hopefully simply enough, and already pre-built with most options that you would desire.

I will quickly cover



  • A few additional things you might like to add

  • The basics of how this application works

  • How to get started coding with this application

A Few Additional Things You Might Like

Additional Languages


It would be easy to add additional languages in addition to English and Spanish. Simply copy the res-values folder and rename it values-xx (where xx corresponds to whichever language. Search online for “android localization list.”) Then change the text.

Different Bitmaps (Pictures)


Don’t like the color orange? Want other shapes? You can easy change this in the res/drawable. Remember the 3:4:6:8 scaling ratio and use PNG types to keep transparency.

Note: the ‘margins’ of the screen are currently set so the bitmaps will never go off the screen. So make the object boundaries clear.


Precise Time Waiting


Currently the delay is set up at an “additional” delay after each packet sent. It might be better to have an “on-the-go” delay that gives a precise time each packet is sent. This was previously avoided for simplicity and less calculation.

Warning Messages


There is currently only descriptive dialog text for EditText preferences. (Note: ListPreferences do not support dialogs). Having warning messages would be helpful.

Numerical Screen Output


Showing the position will slow down the screen refresh rate, but might be helpful for precision tasks. Furthermore, showing the confirmation of sending, receiving, and loading preferences would be nice.

Ping Test


This would be great to put in the connections options.

Change Structure


Some of the classes could have been moved outside of the main class. Originally avoided this because there are many global variables that get used frequently. It was easier to start with everything together. In Eclipse, press control, shift, / (divide) to collapse all and it is not so bad to read.

The Basics of How the Application Works


There are basically two parts: the main application and then all the preferences. This section here also describes some of the rational for the design.

The Main Application


The main application is one large java class with a number of threads and a few methods (some as methods within classes).

The layout is as follows:



  • Imports

  • public class RemoteControlApplication extends Activity implements OnTouchListener{

    • Lots to Initialize as global variables

    • onCreate – loads most preferences

    • onResume – starts threads

    • onPause – stops threads

    • onTouch – get position of pointers and do slide

    • InertiaAndTilt – combined inertial effects and tilt

    • MySurfaceView – draw to the screen

    • SendUDPData - send

    • ReceiveUDPData – receive and vibrate

    • Method: getLocalIpAddress() – used at beginning

    • Class+Methods: Screen2Coor – used frequently, transformation

    • Class+Methods: Coor2Screen – used frequently, transformation

    • Method: MakeByteBuffer() – used frequently, generate the bytes to send

One convention I used was that capital XYZ mean screen position and lower-case xyz mean real position. All screen positions are converted to real position, which is then retransformed back to screen position.

The Preferences


I used PreferenceActivity for the preferences for compatibility. The newer PreferenceFragment handles multiple preferences screens better, but may not have reverse compatibility. For this reason, I had to do some work in the java classes. One such example is listing all the keys of preferences for updated summaries. It’s a little tedious, but seemed to be the best method.

I could have used android:dependency to enable/ disable different preferences, but in order to maintain consistency with also referencing ListPreferences, this is all in java.


How to get started coding with this application


If you are new to programming in java for android, I would personally recommend thenewboston.org Android series. The first three tutorials will describe how to get all the necessary free software you need to begin programming. I went through about 70 of the 200 tutorials and then used online references (stackoverflow.com, developer.android.com, and others) for most specific questions. If you are just modifying small parts of this application, online references may be sufficient.

Download 21.74 Kb.

Share with your friends:




The database is protected by copyright ©ininet.org 2024
send message

    Main page