Code better not harder

It has been a long time

It has been a long time since I have written my last post. I would say I have accomplished the minimum prerequisite of what I wanted to do with fpv, either micro or mini quads. I have built my own quads with my own selected components. They are not ideal or the best that it can be, as I only have few months of experience building and flying a DIY. But they are not bad either.

I can’t believe COVID isn’t over yet, but that doesn’t stop me to build and fly. However, the pace of building and flying has plateaued for a moment, until I can find the right moment again, after I finished the most important step in my life, which is to buy my own property: my first house. I won’t talk about that process here, as it would make this post very long.

What did I learn so far?

I have built two racing quads with 5-inch frame configuration, 6S (six Lithium Polymer battery cells) powered motors, ESC (Electronic Speed Controller), and FC (Flight Controller). I could write the details of my build, but I have written one of my builds on my DVR recordings here:

My first 5-inch build was HGLRC Wind 5 Lite frame with HGLRC tower stack F722 FC + 45A 4-in-1 ESC. However, due to my blunder, the FC, radio receiver (Archer RS), and the VTX was fried just before I was about to fly it. I have tested with smoke stopper and multimeter before I plug it in directly to the battery. But, possibly due to messy wirings (as the stack is very tight) it caused a short circuit. I wasn’t actually sure what was the cause.

While my second build is a Five33 Switchback frame with the same HGLRC electronics, as recorded on the above video.

Lesson learned:

  1. In a tower stack configuration, make sure to have enough space between the ESC <-> FC JST connector. If you like to layout the motor wires on top of the ESC, make sure this doesn’t occupy the space of the JST connector. Otherwise, it may cause signal connection issues between the FC & ESC.
  2. My recommendation for motor wirings is to use something like racewire which connects to the ESC motor pads in between each of the motor. A WS2812 LED board can be used for the same purpose as well. This will make motor replacement easier, and the overall wiring to be much cleaner. In this case you only need to re-solder the racewire / LED board pads near the end of each arm.
  3. Do some initial pre-configuration on your ESC firmware if you’re running 6S. This is to prevent the voltage / current spikes that’s likely to happen on a higher powered build. In addition to soldering Low ESR capacitor at the battery lead. On BLHeli_32 firmware you might need to reduce rampup power and setting Demag compensation to High. Checkout Mini Quad Test Bench for detailed explanation of BLHeli_32 configuration.
  4. Always do a continuity check on your battery lead, and between the (+) of your battery lead to each of the motor pins of your 4-in-1 ESC, then do the same for the (-) lead. This must be done before and after soldering all the motors and XT60 / XT30 connectors. I have shorted one motor pin on a brand new T-Motor Ultra F55A mini 4-in-1 ESC. Which could not be known what was the root cause if I didn’t do this continuity check before soldering.
  5. A lot of Betaflight filtering guide tend to advise 5-inch quad to reduce filtering, by moving the D-term and Gyro low-pass filter sliders to 1.5 to reduce delay. Don’t do this if your motor is warm even at 1.3 silder value. I have blown up one FET in an ESC of my HGLRC Wind 5 quad, because it slightly hit a tree branch, and one motor was stuck. In this case the motor will heat up, and without enough filtering, it may fry one of the ESC. I replaced this with the T-Motor F55A ESC, but one of the FETs broke again :(

For some reason, I encountered these issues only on a high-powered 6S build. I didn’t have these weird issues on a 4S build. It signifies the extra care required when you’re building, configuring or flying a higher voltage build such as 6S and above.

I did however encounter video electrical noise issue on an All-In-One board powered by 4S where one board has the FC + ESC, but that’s happening at different component. It’s a common issue where the closer the video signal is to the source of noise in power supply, the more likely it will be disturbed. I cleaned up the wirings and installed a 25V 1000uF Panasonic FM Low ESR capacitor. But, it’s not a severe problem that require me to replace my FC / ESC / Motor.

In conclusion, a lot of these annoying issues can be prevented as we have more clean wirings, solder joints, and experience in troubleshooting electronics of our own build.

Micro or Mini quad?

I have been flying only 3-inch propeller size quadcopters so far, as it’s the first one that catches my eye as it has the right size and the right power & speed for my circumstances. A 5-inch propeller size would theoretically fly better and further, and it’s the most common size being used by racers and professional FPV pilots. But, have we ever wonder why there are more and more micro-to-mini size?

This is made more apparent with micro long range explorer such as the Flywoo Explorer and GEPRC Crocodile Baby.

To clarify the terms about the size of quadcopters, mini quad refers to mostly quadcopter frames with size of around 200mm - 300mm of diagonal wheelbase, while a micro is mostly 100mm or less, but sometimes it can be used for sizes in between 100mm to 200mm. But, for most people, it’s much simpler to refer to mini quad as the ones equipped with 5-inch propellers size, and micros can be used for those who are sized less than 100mm up to 3-inch.

I found it a little bit inconsistent and can be confusing to refer to Brushless Whoop or Tiny Whoop propeller sizes with milimeters while referring to Toothpick or larger propeller sizes with inches. Then, we always refer to frame sizes in milimeters :). But, as time goes by everyone in this industry got used to these inconsistencies. I assume it’s because the manufacturers have to cater to the US market with Imperial units, and those outside US who are using metric units. It’s easy to get the specifications mixed up.

The main reason so far is as clearly described by BetaFPV:

BETAFPV is one of the premiere drone companies in the world — fueling FPV racing and freestyle communities worldwide with cutting edge products and gear. We know all about the quaddiction, which is a fun way of saying we’re hooked on drones too. Our products empower newbies and pros to build and rip drones with little effort or cost. Our primary focus is micro quadcopters (called whoops) and the accessories you need to make yours fly well and look good. We love sharing the joy this hobby brings with others. Micro drones are the best way to begin. Micros are not heavily regulated or restricted worldwide. They can be flown almost anywhere. We sell hundreds of high quality products with customers all over the world.

But, from my experience how does someone actually scale up from flying a tiny whoop to a powerful racing drone being used in actual race or any other purpose? That’s where 3-inches quad comes in, and also the recently becoming popular 4-inches long range explorer. A simulator such as DRL or VelociDrone can only simulate so much, but it will not be able to mimic the actual experience of flying FPV with all the equipment, and environment. Flying indoors might be an experience that’s closer to a simulator, but outdoors flying takes more risk and environment sensing. Although, it can be a similar experience if you can successfully simulate the same quad with the same characteristics.

Another reason for flying 3-inches is simply it’s just difficult to find a place that’s legal to fly, where there’s no crowd, and reasonably far away from people and cars. If you live near the wilderness, you’re lucky and you can fly your 5-inches or even 7-inches with more freedom. But not for most people. That’s the drawbacks of city life, people have become less adventurous, and curiosity has become lower, although the economic and education level are higher. Not simply because of choice, it’s also because there’s no choice but to survive and adapt to the existing environment.

But, to be more honest 3-inches or even smaller quads are more compact, lightweight, and portable. It’s just easier to handle, and I don’t need large capacity batteries to have fun with it. Although I need more battery capacity if I’m flying one of those 4-inches long range explorer.

It's not about flying

2 months has gone by, and due to various circumstances, bad timing, rain, and coronavirus doom & gloom, I haven’t flown at all. But, I have flown in the simulator a lot more. On the other side, I have heard from FPV pilots that freestyle or racing, or whatever we’d like to call it is not only about flying. But isn’’t flying a core part of the experience and the main reason why we got interested in the first place? Let’s assume that it’s.

If flying is the ultimate goal, then just spend extra money to buy a good quality assembled quad such as Mr Steele’s Apex or JohnnyFPV’s bundle and keep practicing. With enough effort, shouldn’t anyone be able to acquire the same level of success and experience? But does the tool defines the person behind the tool? Yes, if the person is the one building it, but what if there’s more than one quad with varying styles built by the same person, a team, or a company?

After a while, everyone is unique in this hobby / profession. That’s the interesting part of craftsmanship. JohhnyFPV is not and never be the same as Mr Steele, Joshua Bardwell, Le Drib, Alex Vanover, Quadmovr, Boris B, Team BlackSheep (TBS) or Drone Racing League (DRL). Also, there are few others less known ones such as PhantomFPV, which has his own unique style of teaching:

J-TRUE FPV that I’ve just recently been watching:

I’m really impressed with this one in particular:

Each has developed their own unique style after a long time. Now, we’d like to think that the style was developed due to how they practiced flying. A pilot is just someone who flies an aircraft? Right? That’s probably right, but only to a limited degree. We have to understand that there’s a reason why each of them has their own preferences of quadcopter configuration, flight controller tuning, radio transmitter, goggles, FPV camera, motors, frame and propeller size, and weight. For example, Mr Steele prefers a CCD technology in an FPV camera due to lower latency, while the majority of popular FPV cameras are equipped with CMOS technology, probably because they are cheaper. PhantomFPV prefers a small-sized radio transmitter, and he’s yet to reveal the reason why.

I can feel in the simulator how a DRL Racer 4, which is the racing quad used by DRL is heavier, and it needs a slightly different handling. I don’t prefer that most of the time, compared to a smaller and more popular quad with a 5-inch propeller size at about 500-600 grams, while DRL Racer 4 is 7-inch and about 1 kg in weight.

Each of these configuration and components affect the feel of flying, and not everyone prefers the same configuration, it really depends. Also, a beginner or someone who doesn’t fly often may not need a very specific configuration. That’s where we can start to explore why it’s more than just flying.

From what I’ve learned so far, I acknowledge that a lot of them are DIY engineers with a relatively good experience in DIY electronics, embedded software, radio control, or RF engineering, and just a basic understanding of aerodynamics. That’s especially true of Betaflight developers, TBS or DRL. But, it really is a different world, although related from the software industry that I came from.

In the software industry, we put personal computers and mobile device as the core of activity, as if they are the most important element of developing software. Which we should have known that it’s not, but we are often out-of-touch from the users who used our software, and this is not necessarily always bad, as in modern software products there are too many layers on the technical and business side, and each developer of a particular layer (let’s say database, graphics engine, with the exception of user interface) do not necessarily need to interact with an end user or even use the final product of such software.

As software run everywhere, even in flight controllers! There are embedded software engineers that write software for flight controllers of course, and these people can be pilots or not. But, I’m pretty sure there should be pilots among Betaflight developers, otherwise they won’t be able to form opinions and ideas on how a flight controller should work.

That’s the great thing about this industry, and somehow the core technology just magically exist for beginners such as myself. It certainly has a steep learning curve, and a lot of gray areas regarding regulations (Radio Frequency usage and UAV). Also, an easy-to-use software is not very common here. With the slight exception of Betaflight configurator, the majority of supporting software being used for FPV system is not made for the average user.

Investing huge amount of effort to make the software much better and easy to use in this industry is risky, and probably could only be afforded by companies such as DJI or DRL. Even TBS won’t go as far as producing software for the masses. Skydio, on the other side focuses on autonomous drone, which is what they should be doing.

Now, to summarize should someone learn to build a racing quad in this hobby? The answer is yes. There’s a lot of step-by-step tutorials available. It’s not necessary to build a meticulously engineered product to be sold, or you’ll waste a lot of time and money, just enough to fly freestyle and racing. Then go from there as experience accumulates.

Freestyle or Racing?

When I started the hobby, I am aware that there are two ways of flying FPV which is racing and freestyle. Drone racing has been going on for a while with professional competition all over the world such as DRL and MultiGP. But, freestyle doesn’t seem to have a specific venue, because as the name suggests, it’s free flying with style.

I would like to explore a bit on how does someone who started with FPV approach these two styles of flying. In racing, there are specific tracks, obstacles, goals, and time tracker. It’s structured, and the goal is obvious: to be the fastest to finish the track. But does that mean being the fastest is all it takes? Depends on what it means to be fast. I have been using the DRL (Drone Racing League) simulator, and have participated in the 2020 Tryout tracks, which is a course in Drone Park, and as someone who is just starting, it’s extremely hard to get to the top. Even on a simulator, not the real race.

How difficult is it to race at Drone Park?

As you can see from the video, the track is the most challenging I’ve ever seen compared to DRL tracks in previous years, as it involves multi-directional full-throttle maneuver, power-loops, corkscrew, and more. A slight interruption to flow will just ruin everything and it will definitely drop your lap time. I could finish the track but with about 2-3 of the time it takes compared to the #1 in the leaderboard. Also, it’s very difficult to do inverted power loop, while staying on track with full throttle. Alpha Pilot? Let’s just say robotics and AI will need to learn animal instinct before it can compete with the best FPV pilots.

In comparison, flying freestyle is about learning tricks and maneuver in various interesting location and spots. The goal is mostly about how each style transition smoothly to the next style. What is a good style is also subjective, but in general if you have a very good and precise control of how to fly a racing quad, you can transition to freestyle easily. Because the dynamics are similar, just the goals are different.

I found that practicing racing skills are hard but more motivating than a non-targeted practice of freestyle tricks. This is especially true in a simulator (DRL or VelociDrone), where you don’t really have real-world immersion. In the real world, practically it’s easier to fly freestyle in most cases. Thus, I tend to view freestyle as a relaxation or exploration flying that you couldn’t do with racing. It’s likely that the better someone is at racing, the better someone could be at freestyle.

FPV - How did I get started?

If you are a drone pilot or have been working with drones, quadcopter or fixed wing, I am sure you have heard of FPV, and this post is not targeted towards those who are already in the hobby. With a quick search one can find a lot of tutorials, articles, and even complete training on how to become an FPV pilot. I am writing mostly to give another perspective on how did someone get started on it. Although, I have to state beforehand that my experience is neither unique nor it’s a good way to start with FPV.

Before that I would like to provide a few information where you can seriously learn and understand the process of entering the hobby, building a racing / freestyle quad, and becoming an FPV pilot for racing, freestyle, or however you want to do it for. The sky and your hard-work is the only limit.

  1. OscarLiang: My favorite tutorial and reviews site on anything FPV-related. The writings are very comprehensive and easy to understand compared to a few others who can be too technical, incomplete, too verbose, boring, or lacking in details.
  2. Propwashed: Similar level of comprehensiveness to OscarLiang. I do read specific articles such as How to fly in Rate mode?, PID Tuning guide, LiPo battery guide, and all the technical materials needed to fly a racing quad. But, there can be a few posts that could only be found in OscarLiang. Such as the review or benchmarks of various FPV gears and electronic components.
  3. GetFPV: Also similar to the above two sites. They might also have specific articles that I could not find elsewhere. The difference is GetFPV is also a shop for FPV gears or products. Although, I haven’t really compare them side-by-side. I found that OscarLiang reviewed more products and have more variation on the topics being discussed.
  4. FPV Know-it-All: Created by none other than Joshua Bardwell himself. I do enjoy his explanation of various topics in a friendly manner and easy to understand for beginners. Everyone should watch his PID Tuning Masterclass. But, he seem to be only producing videos, not written articles.
  5. Ethix: Steele Davis a.k.a Mr. Steele is a part of them. His videos and piloting skills are what I would consider as crazy but in a positive way. Although there’s a lot to be learned from his content, he doesn’t seem to write articles or provide a comprehensive guide for beginners. There’s however a few guidelines on FPV.
  6. Johnny FPV: Johnny Schaer, he’s a racer and FPV pilot. I think he has one of the most spectacular videos ever made with FPV. He doesn’t have lots of tutorials or content for learning, but definitely you can learn his equipment setup, and even buy the same set of equipment. But, even though you do, it doesnt’t mean you can match his quality of work.
  7. Sozo: The YouTube channel has videos mostly for long range expedition. It also has tutorials for FPV and racing pilot, accompanied with LiftOff simulator.
  8. TheJumperWire: Not very specific to FPV, but more on electronics, quadcopter, and programming it. The author, Sean Kelly has been working with bitcraze on Crazyflie which is a famous programmable and open source quadcopter platform to do research on autonomous drone. I enjoy his series of articles on LiPo battery characteristics.
  9. Drone Racing League: A leading organization that promotes drone racing all over the world. They have racing competition. All you need to do is download the simulator, practice, and enter a race. If you just want to be a racer. This is where to start.
  10. There’s definitely more, but I can’t recall them.

Also, I have to mention Team BlackSheep and VelociDrone where one is an FPV shop that has been a pioneer in the hobby, and VelociDrone which has been one of the go-to simulators to practice racing, freestyle, or online race. There are others such as LiftOff or DRL (Drone Racing League) simulator, but I haven’t personally used them, because I haven’t got the chance or a high-end gaming computer to also try them out.

Next, how did I get started? As I have mentioned before, I was brought into the hobby after I was involved with a project on autonomous drone with DJI Matrice 100 using ROS. Afterwards, I discovered FPV while searching for parts and components to custom build a quadcopter. But because I do not have a personal space or workbench to work with electronics, I decided not to build one for now, and instead bought a BNF 3-inch quadcopter built by GEPRC from Banggood.

A 3-inch quadcopter is a good balance between being able to fly freestyle, racing and but not throwing yourself immediately to higher-powered 5-inch or 7-inch ones which will require larger capacity LiPo batteries with more weight, size, and more experience on how to handle its speed and range. The bigger quads (although they are still mini-quad) can give a false sense of inspiration, and then you started to take more risks without having a good sense of how it flies, how it’s being tuned, and how to manage all aspects of controlling it.

If I could restart I would start with micro quads that are often referred to as Whoops such as the Emax TinyHawk, Eachine Trashcan, Beta65 / 75 / 85 from BetaFPV. They are good for flying indoors, and getting a feel of flying FPV without flight assistance from sensors such as GPS or Optical Flow to hold its position for hovering. But, I don’t want to spend extra money unless if I actually have a chance to fly indoors — which is unlikely as indoor space tend to be occupied by people — unless if I join a race. Although, they are okay for outdoors too, I’d rather use a Toothpick, 3-inch or larger.

It’s recommended to practice with simulator before flying the real quad, but only after a few flights with my first 3-inch, then I started to really feel how real-life flying is compared to simulator. Aside from physics, real flying require more awareness of the environment, and the configuration of the hardware or flight controller (BetaFlight):

  • LiPo battery characteristics, balanced charging, discharged, what is storage voltage, etc. is very important
  • Electronics and how to recognize symptoms when things are broken (motors, capacitors blowed up, short circuit)
  • Basics of Radio Frequency Communication
  • What’s the difference between TBS transceiver vs FrSky
  • Why do some people need long range transceiver at 900 MHz
  • What kind of antenna to use (Pagoda, Leaf, RHCP or LHCP polarized, SMA or RP-SMA connector)
  • FPV frequency selection on video transmitter (VTX), which channel, band, and transmission power numbers and how it’s being regulated. In Singapore the limit is 100mW, otherwise you would need permission.
  • Without watching the recorded video of my real flight — VelociDrone doesn’t do recording automatically — I wouldn’t be aware of my weaknesses.
  • Throttle management is different on a 3-inch compared to 5-inch. With smaller propellers I have to make sure that throttle doesn’t drop for too long at low altitude, otherwise the quad can easily drop to the ground and flip.
  • VelociDrone’s smallest mini quad is a 4-inch. Although they have micro quads, it’s still not a 2-3 inch quad.
  • The list doesn’t stop here while on the simulator you can simply ignore regulation, hardware, electronics, and focus on flying.

I realized that having an understanding of the fundamentals of building a quadcopter does help with developing an interest on FPV. But, having a good understanding or even mastery of the technology doesn’t always translate to an interest in racing or freestyle flying. First and foremost FPV requires time, a certain personality trait and adventurous mindset. Because there is not much rationale behind practicing hard to learn the basics of high speed racing and acrobatic movements other than a sense of adventure and curiosity. Not to mention understanding the regulation of Unmanned Aerial Vehicle in countries you’re flying in.

Some people are either simply lazy (it does require hard work), or their lifestyle doesn’t lead them into that direction. With all the news of people landing drones at the airport and spying at people’s home, it discouraged people from understanding the various aspects of the hobby whether it’s quadcopter, FPV, or fixed wing. The result is the activity tend to be associated with pranks and immaturity, while in reality the hobby has a lot more variation in it other than people who bought drones for photography or videography.

2020: symmetrical year

It has been a long time since I wrote anything, and I have decided that I had to at least once in 2020. As it’s the only year in my lifetime that is symmetrical. Do numbers mean anything? Probably yes or no, either way I have recently worked on more robotics related software than a consumer app on iOS. I still wrote an iOS app to interface with a backend running on a headless computer such as Raspberry Pi, Intel NUC, NVIDIA Jetson or it can be any kind of computer. I have to admit there aren’t many nice solution out there. Because most robotics software came out from research lab, and it doesn’t often consider smartphone as their frontend. There isn’t a lot of software engineers working in the robotics industry apparently for a valid reason.

If we talk about robotics, probably an arm manipulator, roomba-like differential drive, humanoid, or a dog robot came into our imagination. But, those are not the only robot. A “drone” can be a robot. A car could also be a robot. The only element needed to drive this is sequence of commands to achieve semi or fully autonomous behaviour, without us controlling every aspect of their movement.

Now, I thought robotics is cool. Yes, it’s cool to have a computer to move on its own. But, when we delegate our responsibilities to autonomous robots, our job is done. We don’t consider them as exciting anymore. Who would be excited with a washing machine for an example? Unless a robot could interact with us like a human or animal does, it’s boring.

As I have worked with drones for a few months, another world has revealed itself to me. The first drone I have touched is a DJI Matrice 100. It’s an amazing piece of equipment, as I never worked with an aircraft before. However, after a while as any other piece of equipment, it’s not something that I get excited over.

I guess the main reason is the difficulty with which to use it on various activities. It’s too large, noisy, and although it’s programmable, how far can we get with it without years of work, to make it on par to the latest and significantly cheaper drone on the market?

Then, I have also tried the newer DJI Mavic 2 Pro. It’s much better, more stable, and easier to control. It does what it’s designed to do (flying, taking photos and videos), but it’s not an open platform where you can replace the hardware or software. But, just last year Skydio 2 was released. It has far better autonomous flying capabilities, and for some reason they’d rather state that it’s using NVIDIA Jetson TX2 as a computer. This is not the case with Mavic. Though DJI is using an Ambarella vision processor, they don’t advertise it anywhere in their marketing materials. Skydio is another drone targeted at Mavic’s customer base, and it’s also not a programmable drone, though it might be in the future. I assume any product equipped with NVIDIA Jetson series board need to provide some attribution. This is also the case with DJI Matrice 2xx series.

Now, if I need a fully autonomous drone or I prefer to call it quadcopter — as it’s a multirotor with 4 motors driving its propellers — the only way is by building it myself. But, while I have a thought of doing that, I found that quite a few of DIY builders are doing it for racing or freestyle flying with an FPV (First Person View) goggles. I found this activity to be very active and growing, and you can search on the internet to find various setup of racing / freestyle quad with various configuration. It’s also an art in flying in remote areas, nature, abandoned space, and video shooting at its best.

I could consider that a racing / freestyle quad and FPV goggles has pushed the miniaturization in electronics and innovation in radio transmission technology which an autonomous drone project has not achieved so far or they are moving at a slower rate. The differentiating factor is the kind of people or flyers that used them. An autonomous drone require heavy computation, and there aren’t a lot of hobbyist in programming and electronics, while an FPV hobby on the other hand is more appealing to anyone who is seeking an adrenaline rush. Anyone with little background in electronics and software can enter the hobby with persistent practice. There’s always those who seek thrill, thus there are always demands. It’s not very hard to manufacture electronics that could drive motors aggressively. But, it’s very hard to manufacture electronics that can simultaneously drive motors and do a lot of heavy matrix calculations in real time, in other words to put a GPU on a mini or micro quadcopter.

The other side of casual user is probably better served with a stable drone that flies by itself, which is so far only Skydio that could achieve this. Any Mavic series so far is relatively okay at obstacle avoidance but it’s very limited, you need to fly it at a certain height to track you. Also you can’t send Mavic for an autonomous mission without good GPS signal. Because in order to move itself without GPS it needs a point of reference. At the moment it’s just the person flying it, another person, or a car. While ideally it should build a map of its environment from its own motion and visual processing a.k.a SLAM, and that’s what Skydio is doing so far and why it has an amazing tracking and obstacle avoidance capability.

In the case of aggressive quadrotor movement such as drone racing, it might be possible in the future to have it in the form of pilot assistance system. But instead of helping to avoid obstacles — although that would be good too — imagine that a pilot could learn the optimized flight characteristics of a racing / freestyle quad as a feedback system to the manual flight in Acro or Rate mode via the remote control. With digital HD FPV system such as the latest one from DJI, this feedback information can be provided in real time via the goggles as well. Combined with a simulator system, professional pilot datasets, and flight logs, a pilot at any level is able to improve him / herself via this training-in-the-loop system.

Rewind view controller states (observables)

A pattern that was not immediately obvious when you began to use an Rx-based view controller setup is to undo/reset all of the observables that have been subscribed to after it re-appears.

This is a common behaviour in a navigation controller stack of view controllers. We might have various controls in a view controller, it could be a text field, text view, or anything that you might want to return to from the next controller in a navigation stack.

import UIKit
import RxSwift
import RxCocoa

final class FormViewController: UIViewController {
var disposeBag: DisposeBag = DisposeBag()

var completed: PublishSubject<Void>()

lazy var textField: UITextField = {
let textField = UITextField()
textField.autocorrectionType = .No
textField.autocapitalizationType = .None
textField.returnKeyType = .Done
return textField

func viewDidLoad() {

// We indicate that a certain action should be completed,
// once the text field's text reaches a certain length
.subscribeNext { text in
if text.length > 6 {

func viewWillAppear(animated: Bool) {

// Observe when returning
completed = PublishSubject<Void>()
.subscribeCompleted {
// A subscribed action is completed

func viewWillDisappear(animated: Bool) {

// Clean up all observables
disposeBag = DisposeBag()

Typically, we would want to do a certain action in a view controller, that could be observed, and it should be known when does it complete. One example is network request, but the above example is simplified to illustrate the idea of running an action that is triggered by an observed event (text field event). PublishSubject is a common example to represent an action subject that can be subscribed to and could subscribe to an observable.

In the snippet above, on view appearance, the action is being reset, and re-subscribed, while on view disappearance, the disposeBag is being re-created. Once it returns to this view controller from the navigation stack it will have the completed subject re-created and re-subscribed.

Without the above setup, a completed action remains completed and it will not emit anymore items that is being observed.

To think about it a little bit further, before Rx I often do not have an idea on how to “replay” a certain action within scenes of view controllers. Traditionally this can be done by re-creating whatever it’s an object responsible for such action (e.g. NSURLRequest).

It can always be done traditionally without Rx, but in that way there doesn’t seem to be a generalisation of idea in how to represent an action that can be anything.

Revisiting Size Classes

Articles on iOS size classes never went beyond the ideal that we have to think in terms of Any, Regular, Compact Horizontal or Vertical size classes for adaptive layout, instead of pixels and devices screen sizes.

Ever since size classes was introduced in iOS 8, I have always wondered, why do iPhone 4s, 5, and 6 are all under Compact Horizontal and Regular Vertical size classes?

While in reality they have different dimensions, and during design phase, we have to think about the dimensions of views and their subviews, together with the distances between them due to these varying screen sizes.

We could of course declare auto layout constraints programmatically with a multiplier based on screen width or height. But, from what I understood size classes are supposed to move us forward from this way of thinking towards designing layout specifically just for the abstractions of them. Until I encountered one article that describes my confusion on size classes:

Size Classes - Close, but Not Quite
By Kevin Packard @kevinpackard One Storyboard to Rule Them All At WWDC 14, Apple introduced Unified Storyboards and Size

Note that, the above article was posted about 2 years ago.

Exactly, if a designer should consider how an iPhone 4s is way shorter than an iPhone 6, resulting in individual layout design for each iPhone 4s, 5, 6, 6 plus. Then, aren’t we still doing what we are doing before size classes were introduced?

Well, I hope this will change in WWDC 2016.

Moving On

After about 4.5 years of working primarily as an iOS Software Engineer at 2359 Media — including server side development of VoicePing with node.js that I have been doing for a year — I am finally ready to move on to my next challenge to work as a Lead iOS Developer at Touché Singapore.

Touché core product is a seamless payment system together with a device using biometric (fingerprint) as an identity system. It’s something that I have never explored before, and it’s only recently that fingerprint based identity started to appear on mainstream devices such as iPhone (Touch ID) and then Android. Thus, it’s intriguing that they’ve managed to produced a standalone device and to continue pushing in that direction.

Working in a payment industry is something that has been in the back of my mind for quite a while, though I never got a chance to really understand how all the system works.

In relation to that, I have been increasingly comfortable with cards, digital, or online payment, and I hope someday cash and coins are no longer necessary.

This reminded me of the time when I visited Sweden (Uppsala, and sometimes Stockholm) for 3 months around 6 years ago, and that was the first time that I had witnessed for myself the widespread usage of cards, as opposed to cash. As can be read from here as well, which ignited my brain cells, though these thoughts have pretty much stayed there and ignored for the past 4 years.

On the contrary, after reading the Preface of bitcoin book from Princeton course, I have realised that the major advantage of using cash is the anonymity of transactions, and it’s independent of third party verification such as payment processors (Visa, MasterCard, or Banks, etc.).

I agree that these are the properties that don’t exist in a cashless system. But, we have moved on from a barter system, to cash, credit cards, and NFCs on smartphones, with a bit of sacrifice on our privacy and security. These made transactions much easier, and now it’s easier than ever to transfer money and purchase goods across the world. So, in the end the progress is really worth something.

Back to the topic of my career move, I would mostly still be doing mobile development on the iOS side, which is still exciting given the recent movements by Apple (Swift, open source, etc.), but in a new industry, a new team, and a new focus.

Playing around with Data Science

After a few influences here and there from colleagues, and how I kept hearing this buzzword time and time again. I am finally curious to understand what is data science all about.

I started with an online course from Coursera in my spare time as an introduction, then I’m currently in the process of finishing the R programming course at the end of October.

Overall, as a long time programmer, I consider the level of difficulty of the R programming assignments as easy. You don’t need to spend days to solve one of them. Mostly, it can be done in an hour or more within a day. Moreover, the course team are very generous in providing examples, and all of the lecture materials are very organized.

Though, it’s likely to get harder if I proceed to the next course in the data science specialization track. Which, I probably will. But before that, I’ve accidentally discovered data science on the command line by Jeroen Janssens which introduced a set of toolbox that I perceived as a more complete tooling than just utilizing R.

I generally believe that programming toolsets should not be confined to one environment, one editor, with their own custom interfaces or protocols written by a vendor that is not extensible or interoperable with another toolset. Although this is not the case with R, but I have seen other programming tools — which I can’t recall right now — that are built this way.

What about Python for data science? Yes, Python is a general purpose programming language, but I assume that the data science community are more productive within the R programming environment. Proven by how Johns Hopkins University are using R to teach data science. It would take more learning and time for those with little programming experience to solve these problems using Python.

The data scientists have done a lot for the R development tools. I have searched and peeked a bit into a few of the stuff that they had built. Though, honestly I haven’t explored what kind of tools or libraries in Python that is made for data science.

So, I’m thinking along the lines of using what is already been done on R, and we should be able to interface with it from a different programming environment.

For example:
An interactive application (desktop, web, mobile, whatever) that continuosly records data from user input, or other sources which is then formatted into CSV or data frames which is the data type that R usually interacts with.
These data should be fed into R programs that are being specifically written to do a unit of calculation. The raw data of the result should be sent back to the application which are optimized for user interface and visualization purpose.

We need this interfacing because I’m not sure that R tools (even though it has Shiny and other plotting libraries) are complete or well developed enough to be able to do advanced UI or visualization, it’s not their focus.
Regardless, it’s still very early for me to tell whether it’s even better to remove R from this sort of system. Because it does seem like it’s just a tool for data scientist, it’s not something that you’ll use for an automated stand alone performance critical system that will process and compute huge amounts of data.