<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Tyler Kim</title>
    <description>The latest articles on DEV Community by Tyler Kim (@tylertaewook).</description>
    <link>https://dev.to/tylertaewook</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F603852%2F6f6cc1c9-ead1-49e2-8951-3e8a43e52ca2.png</url>
      <title>DEV Community: Tyler Kim</title>
      <link>https://dev.to/tylertaewook</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tylertaewook"/>
    <language>en</language>
    <item>
      <title>Understanding and Implementing Proximal Policy Optimization (Schulman et al., 2017)</title>
      <dc:creator>Tyler Kim</dc:creator>
      <pubDate>Thu, 06 May 2021 00:56:42 +0000</pubDate>
      <link>https://dev.to/tylertaewook/understanding-and-implementing-proximal-policy-optimization-schulman-et-al-2017-20on</link>
      <guid>https://dev.to/tylertaewook/understanding-and-implementing-proximal-policy-optimization-schulman-et-al-2017-20on</guid>
      <description>&lt;p&gt;Research in policy gradient methods has been prevalent in recent years, with algorithms such as TRPO, GAE, and A2C/A3C showing state-of-the-art performance over traditional methods such as Q-learning. One of the core algorithms in this policy gradient/actor-critic field is &lt;strong&gt;Proximal Policy Optimization Algorithm&lt;/strong&gt; implemented by OpenAI.&lt;/p&gt;

&lt;p&gt;In this post, I try to accomplish the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Discuss the motives behind PPO by providing a beginner-friendly overview of Policy Gradient Methods and Trust Region Methods(TRPO)&lt;/li&gt;
&lt;li&gt;Understand the core contribution of PPO: &lt;strong&gt;Clipped Surrogate Objective&lt;/strong&gt; and &lt;strong&gt;Multiple Epochs Policy Update&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  &lt;strong&gt;Motives&lt;/strong&gt;
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Destructive Policy Updates
&lt;/h2&gt;

&lt;p&gt;We first need to understand the optimization objective of Policy Gradient methods defined as following:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0pTL8J8D--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lxdvqu1lno5xulbujb9l.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0pTL8J8D--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lxdvqu1lno5xulbujb9l.jpeg" alt="policyloss"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The policy is our neural network that takes the state observation from an environment as an input and suggest actions to take as an output. The advantage is an estimation, hence the hat over A, of the relative value for selected action in current state. It is computed as &lt;em&gt;discounted reward(Q) - value function&lt;/em&gt;, where value function basically gives an estimate of discounted sum of reward. When training, this neural net representing the value function will frequently be updated using the experience our agent collects in an environment. However, that also means the &lt;strong&gt;value estimate will be very noisy due to the variance caused by the network&lt;/strong&gt;; network is not always going to predict the exact value of that state.&lt;/p&gt;

&lt;p&gt;Multiplying log probabilities of policy's output and advantage function gives us a clever optimization function. If advantage is positive, meaning the actions the agent took in the sample trajectory resulted in better than average return, policy gradient would be positive to increase the probability of selecting these actions again when we encounter a similar state. If advantage is negative, policy gradient would be negative to do the exact opposite.&lt;/p&gt;

&lt;p&gt;As much appealing it is to constantly perform gradient descent steps in one batch of collected experience, it will often update the parameters so far outside of the range that leads to &lt;strong&gt;"destructively large policy updates."&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Trust Region Policy Optimization
&lt;/h2&gt;

&lt;p&gt;One of the approaches to prevent such destructive policy updates was &lt;em&gt;&lt;a href="https://arxiv.org/abs/1502.05477"&gt;Trust Region Policy Optimization (Schulman et al, 2015)&lt;/a&gt;&lt;/em&gt;. In this paper, authors implemented an algorithm to limit the policy gradient step so it does not move too much away from the original policy, causing overly large updates that often ruin the policy altogether.&lt;/p&gt;

&lt;p&gt;First, we define r(θ) as the probability ratio between the action under current policy and the action under the previous policy.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YHE3B0cw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fxmddi7va3pwkvsl4ua4.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YHE3B0cw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fxmddi7va3pwkvsl4ua4.jpeg" alt="trpo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Given a sequence of sampled actions and states, r(θ) will be greater than one if the particular action is more probable for the current policy than it is for the old policy. It will be between 0 and 1 when the action is less probable for our current policy.&lt;/p&gt;

&lt;p&gt;Now if we multiply this r(θ) with the previously mentioned advantage function, we get the TRPO's objective in a more readable format:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--I44U93xP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cqnlql1bjcvmvskrr7tj.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--I44U93xP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cqnlql1bjcvmvskrr7tj.jpeg" alt="trpo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this TRPO method, we notice that it is actually quite similar to the vanilla policy gradient method on the left. In fact, the only difference here is that the log operator is replaced with the probability of the action of current policy divided by the probability of the action under previous policy. Optimizing this objective function is identical otherwise.&lt;/p&gt;

&lt;p&gt;Additionally, TRPO added a KL constraint limit the gradient step from moving the policy too far away from original policy. This results in the gradient staying in the region where we know everything works fine, hence the name 'trust region.' However, this KL constraint is known to add a overhead to our optimization process which sometimes lead to an undesirable training behavior.&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;strong&gt;PPO&lt;/strong&gt;
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Clipped Surrogate Objective
&lt;/h2&gt;

&lt;p&gt;With the motives mentioned above, Proximal Policy Optimization attempts to simplify the optimization process while retaining the advantages of TRPO. One of this paper's main contribution is the clipped surrogate objective:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_skoR4hu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ei8qt1hdgo9ewfgyjiw0.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_skoR4hu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ei8qt1hdgo9ewfgyjiw0.jpeg" alt="trpo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here, we compute an expectation over the minimum of two terms: &lt;em&gt;normal PG objective&lt;/em&gt; and &lt;em&gt;clipped PG objective&lt;/em&gt;. The key component comes from the second term where a normal PG objective is truncated with a clipping operation between 1-epsilon and 1+epsilon, epsilon being the hyperparameter.&lt;/p&gt;

&lt;p&gt;Because of the min operation, this objective behaves differently when advantage estimate is positive or negative.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4CSRc-Fw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p559riwdtpb94jxchrf2.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4CSRc-Fw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p559riwdtpb94jxchrf2.jpeg" alt="trpo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's first take a look at the left figure depecting postive advantage: the case when selected action had better-than-expected effect on the outcome. In the graph, the loss function flattens out when &lt;em&gt;r&lt;/em&gt; gets too high or when action is a lot more likely under current policy than it was under old policy. We do not want to overdo the action update by taking a step too far, so we 'clip' the objective to prevent this as well as blocking the gradient with a flat line.&lt;/p&gt;

&lt;p&gt;The same applies to the right figure when advantage estimate is negative. The loss function would flatten out when &lt;em&gt;r&lt;/em&gt; goes near zero, meaning particular action is much less likely on current policy.&lt;/p&gt;

&lt;p&gt;As clever this approach is, the clipping operation also helps us out for 'undoing' policy's mistakes. For example, the highlighted part in the right figure shows the region where last gradient step made the selected action a lot more probable while also making the policy worse as shown with a negative advantage. Thankfully, our clipping operation will kindly tell the gradient to walk the other direction in proportional to amount we messed up. This is the only part where the first term inside &lt;code&gt;min()&lt;/code&gt;  is lower than the second term, acting as a backup plan. And the most beautiful part is that PPO does all of this without having to compute additional KL constraints.&lt;/p&gt;

&lt;p&gt;All of these ideas can be summarized in the final loss function by summing this clipped PPO objective and two additional terms:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3fE1P1dg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b0li9mepq9kejekuuek0.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3fE1P1dg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b0li9mepq9kejekuuek0.jpeg" alt="trpo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The c1 and c2 are hyperparameters. The first term is a mean square error of value function in charge of updating the baseline network. The second term, which may look unfamiliar, is an entropy term used to ensure enough exploration for our agents. This term will push the policy to behave more spontaneously until the other part of the objective starts dominating.&lt;/p&gt;

&lt;h2&gt;
  
  
  Multiple Epochs for Policy Updating
&lt;/h2&gt;

&lt;p&gt;Finally, let's take a look at the algorithm altogether and its beauty of parallel actors:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mRB0fmmk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8w5kbcyezwdqj3m5ce7g.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mRB0fmmk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8w5kbcyezwdqj3m5ce7g.jpeg" alt="algorithm"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Algorithm consists of two large threads: the beige-thread and the green-thread. The beige-threads collect data, calculate advantage estimates, and sample mini-batches for the green-thread to use. One special take: these are done by &lt;em&gt;N&lt;/em&gt; parallel actors each doing their own tasks independently.&lt;/p&gt;

&lt;p&gt;Running multiple epochs of gradient descent on samples was uncommon because of the risk of destructively large policy updates. However, with the help of PPO's Clipped Surrogate Objective, we can take advantage of parallel actors to improve on sample efficiency.&lt;/p&gt;

&lt;p&gt;Every once in a while, green-thread will fire and run Stochastic Gradient Descent on our clipped loss function. Another special take? We can run &lt;em&gt;K&lt;/em&gt; epochs of optimization on the same trajectory sample. This was also hard to do pre-PPO due to the risk of taking large steps on local samples, but PPO prevents this while allowing us to learn more from each trajectory.&lt;/p&gt;

</description>
      <category>machinelearning</category>
      <category>tutorial</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>Orbitron: Reinventing the wheels and its control algorithm</title>
      <dc:creator>Tyler Kim</dc:creator>
      <pubDate>Fri, 02 Apr 2021 04:50:42 +0000</pubDate>
      <link>https://dev.to/tylertaewook/orbitron-reinventing-the-wheels-and-its-control-algorithm-24ba</link>
      <guid>https://dev.to/tylertaewook/orbitron-reinventing-the-wheels-and-its-control-algorithm-24ba</guid>
      <description>&lt;p&gt;Being a heavy Sci-fi fan myself, I always wondered: how would those spherical wheels from &lt;em&gt;Tron&lt;/em&gt; and &lt;em&gt;I-Robot&lt;/em&gt; work in real life?&lt;br&gt;
And this simple thought began the 6-month journey of &lt;strong&gt;Project Orbitron&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Now, this project consisted of two major goals upon start:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Building a vehicle with spherical wheels that implement a 4 wheel independent steering/driving (4WIS/D) system using Arduino&lt;/li&gt;
&lt;li&gt;Developing an intuitive control algorithm for 4WIS/D vehicle in Mathematica&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This article will showcase my vehicle prototype Orbitron along with a short story behind the building scene. Then, I'll introduce you to the highlight: a clever algorithm I built to control Orbitron seamlessly.&lt;/p&gt;

&lt;p&gt;You can also check out this maker portfolio video I made for my college application or check out the Github repo containing the full code.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/WXjisSnfGTI"&gt;
&lt;/iframe&gt;
&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--i3JOwpme--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/github-logo-ba8488d21cd8ee1fee097b8410db9deaa41d0ca30b004c0c63de0a479114156f.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/tylertaewook"&gt;
        tylertaewook
      &lt;/a&gt; / &lt;a href="https://github.com/tylertaewook/project-orbitron"&gt;
        project-orbitron
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      A unique control algorithm in Mathematica for 4WIS/WID vehicles; patent-pending
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;br&gt;
&lt;p&gt;
  &lt;a href="https://github.com/tylertaewook/project-orbitron"&gt;
     &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--raNlKwEg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://raw.githubusercontent.com/tylertaewook/project-orbitron/main/images/logo.png" alt="Logo" width="100" height="100"&gt;
  &lt;/a&gt;
  &lt;/p&gt;
&lt;h3&gt;
Project Orbitron&lt;/h3&gt;
  &lt;p&gt;
    A 4WIS/4WID Vehicle with Spherical Wheels &amp;amp; A unique control algorithm in Mathematica
    &lt;/p&gt;
&lt;p&gt;
      December 2017 - May 2018
    &lt;br&gt;
    &lt;a href="https://github.com/tylertaewook/project-orbitron"&gt;&lt;strong&gt;Explore the docs »&lt;/strong&gt;&lt;/a&gt;
    &lt;br&gt;
    &lt;br&gt;
    &lt;a href="https://youtu.be/WXjisSnfGTI" rel="nofollow"&gt;View Demo&lt;/a&gt;
    ·
    &lt;a href="https://github.com/tylertaewook/project-orbitron/issues"&gt;Report Bug&lt;/a&gt;
    ·
    &lt;a href="https://github.com/tylertaewook/project-orbitron/issues"&gt;Request Feature&lt;/a&gt;
  &lt;/p&gt;
&lt;h2&gt;
Table of Contents&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://raw.githubusercontent.com/tylertaewook/project-orbitron/main/#about-the-project"&gt;About the Project&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://raw.githubusercontent.com/tylertaewook/project-orbitron/main/#orbitron"&gt;Orbitron&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://raw.githubusercontent.com/tylertaewook/project-orbitron/main/#algorithm"&gt;Algorithm&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://raw.githubusercontent.com/tylertaewook/project-orbitron/main/#build-notes"&gt;Build Notes&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://raw.githubusercontent.com/tylertaewook/project-orbitron/main/#spherical-wheels"&gt;Spherical Wheels&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://raw.githubusercontent.com/tylertaewook/project-orbitron/main/#main-body"&gt;Main Body&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href="https://raw.githubusercontent.com/tylertaewook/project-orbitron/main/#research"&gt;Research&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://raw.githubusercontent.com/tylertaewook/project-orbitron/main/#contact"&gt;Contact&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://raw.githubusercontent.com/tylertaewook/project-orbitron/main/#acknowledgements"&gt;Acknowledgements&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;================================================================&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="https://youtu.be/WXjisSnfGTI" rel="nofollow"&gt;[LINK - MAKER PORTFOLIO]&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;================================================================&lt;/p&gt;
&lt;h2&gt;
About The Project&lt;/h2&gt;
&lt;p&gt;Project Orbitron is an independent build/research project featuring a vehicle with spherical wheels named ORBITRON and a unique control algorithm.
The project began as a simple yet powerful urge to build a vehicle with spherical wheels after being inspired by &lt;a href="https://youtu.be/oSFYwDDVgac" rel="nofollow"&gt;Goodyear 360&lt;/a&gt; but soon evolved into a research project under Kent Guild, academic society at Kent School, after realizing vehicle's potential. After presenting a project proposal in front of Kent Pre-Engineering Department, Project Orbitron was granted with $1,000 fund.&lt;/p&gt;
&lt;p&gt;The finished algorithm is going through a patent process as of October 2020…&lt;/p&gt;
&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/tylertaewook/project-orbitron"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;h1&gt;
  
  
  Orbitron
&lt;/h1&gt;

&lt;p&gt;As I mentioned above, ORBITRON is a vehicle with spherical wheels, hence the name 'ORB'itron. Unfortunately, I was &lt;em&gt;a bit&lt;/em&gt; under-qualified to suspend wheels in mid-air with electromagnets, as many sci-fi movies suggested. Instead, I implemented a 4 Wheel Independent Steering/Driving (4WIS/D) system: a steering system for a four-wheeled vehicle that allows for separate speed and direction controls for each wheel.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qvpr5F3q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/njfaaykq0a4e6md4yr20.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qvpr5F3q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/njfaaykq0a4e6md4yr20.png" alt="preview"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Structure
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Wheels
&lt;/h3&gt;

&lt;p&gt;After an initial sketch of the wheel's frame, I modeled the same design in Fusion 360. I designed the frame to house two separate motors, each controlling speed and direction, to steer and drive the wheels independently from others.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MfbMw6EB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/me49fpx81wvg4gxgd82z.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MfbMw6EB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/me49fpx81wvg4gxgd82z.jpg" alt="designwheel"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I used a 60mm EVA-foam ball as wheels since they were light yet sturdy enough to support the vehicle.&lt;br&gt;
The HS-785HB servo with a built-in gearbox on the top controls the wheel’s direction by turning the motor's entire rectangular structure. The 170-RPM Econ Gear Motor directly connected to sphere's shaft takes care of driving the wheel and controlling the speed.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--J0AOcyJH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lvok6be2jiqc0jwtcm6x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--J0AOcyJH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lvok6be2jiqc0jwtcm6x.png" alt="wheel"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Body
&lt;/h3&gt;

&lt;p&gt;Designing the body was relatively simple, as it was simply a rectangular board supporting the wheel frames.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ygMcuP2---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6fwd2aid20n1y96mg7ie.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ygMcuP2---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6fwd2aid20n1y96mg7ie.jpg" alt="designbody"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I built the body out of MDF board at first, but it proved to be too heavy. So I changed into Foamex board supported by PVC pipes which was much lighter and stronger.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NlRm2Ize--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t5epdp0b6exqsrg1rw4c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NlRm2Ize--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t5epdp0b6exqsrg1rw4c.png" alt="structure"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To continue working on this project during summer vacation when I flied back to Korea, I carefully designed the board to be foldable to make overseas shipping easier. This way, I just had to detach the wheel frames, fold the board up, and cover with bubble wraps when shipping.&lt;/p&gt;

&lt;h2&gt;
  
  
  Electronics
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Arduino
&lt;/h3&gt;

&lt;p&gt;I won't go into too much detail in the wirings here. Shortly put, the Arduino Mega is connected to XBee shield for wireless communication, two Motor Drivers for controlling the driving motors, and four servo motors for steering each wheel.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bglzFTUy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x479heffwftaalj2167e.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bglzFTUy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x479heffwftaalj2167e.jpg" alt="electronics"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Controls
&lt;/h3&gt;

&lt;p&gt;While building, I developed a simple C# WinForms application to ensure each component was functioning properly. This app would send alphabet signals through XBee wireless module, and Orbitron would perform pre-set movements such as rotating all servos 180 degrees when received 'r' character.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--izIAroK4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/45s7hjpt5ol8dtpzfk0p.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--izIAroK4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/45s7hjpt5ol8dtpzfk0p.jpeg" alt="test_GUI"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Algorithm
&lt;/h1&gt;

&lt;p&gt;The real beauty of this project was the algorithm development. The following writings will summarize my paper: &lt;strong&gt;&lt;a href="https://tylertaewook.github.io/static/media/orbitron-paper.506633ba.pdf"&gt;"Intuitive Control Algorithm Development of 4WIS/4WID Using a SpaceMouse"&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;4WIS/D system of the Orbitron enables more versatile motion for vehicles that needs to navigate in tight spaces but controlling two parameters, direction and speed, for each wheel results in eight parameters in need of simultaneous control.&lt;/p&gt;

&lt;p&gt;So our goal was simple: &lt;strong&gt;to develop an algorithm that achieves an Intuitive control that abstracts away the complexity, allowing for a full realization of the vehicle's capabilities.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Algorithm Setup
&lt;/h2&gt;

&lt;p&gt;We chose 3Dconnexion's SpaceMouse (SpaceNavigator) as a controller as it was designed for intuitive navigation on 3D space in CAD.&lt;/p&gt;

&lt;p&gt;Connecting the SpaceMouse with Mathematica gave us six numbers ranging from -1 to +1 based on the mouse's position, which became the raw input data for our algorithm.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5ZX38oLh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0l6u06nnhfkvpgpo4vdw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5ZX38oLh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0l6u06nnhfkvpgpo4vdw.png" alt="Algorithm Setup"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The algorithm’s main job is to translate these six variables from the SpaceMouse to eight variables, each of which represents either angle or speed of a wheel. The algorithm is responsible for calculating variable transformations and records the sets of timestamped variables in a CSV file. We then use a serial regulator, a C# application I've developed, to deliver the set of variables at a proper time without overfeeding data to the prototype.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--enePst1t--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w6qcjjywwm7hfowx90ad.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--enePst1t--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w6qcjjywwm7hfowx90ad.png" alt="alg_GUI"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When Mathematica Notebook is executed, the interface on the right is continuously updated based on the user’s input. All the arrows shown in this interface are color-coded differently to distinguish each other more effortlessly. Four labels are shown next to each wheel to display updated angle and speed values.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Green Concentric Circles&lt;/strong&gt;: each represent the radius of curvature of each wheel and the center of the vehicle. This can be applied to vehicles with any number of wheels, but just with more curvature circles.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Blue Arrow&lt;/strong&gt;: motion of the vehicle's center&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Gray Arrow&lt;/strong&gt;: acts as base for red/pink arrows; always fixed along the vehicle body's angle&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Pink Arrow&lt;/strong&gt;: tangent line of the green circle; angle between the gray arrow and pink arrow is used to determine each wheel's angle&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Red Arrow&lt;/strong&gt;: actual trajectory of the vehicle; As user controls the mouse, arrows' length will always represent the relative velocity of each wheel.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Implementing Different Steering Modes
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GNhy-v8W--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7str7w6qungjltntfld5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GNhy-v8W--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7str7w6qungjltntfld5.png" alt="steeringmodes"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;While the conventional steering system only involves Ackerman Steering, 4WIS/4WID can have three different steering modes: AFRS, Crab Steering, and Spinning. Our algorithm supports all three steering modes and allows us to simultaneously control all four wheels without any danger of movement conflicts. We do so by computing both the wheel’s direction and speed based on the wheel’s angular velocity during a turn. This prevents any conflicts between the signals that can result in a vehicle slipping.&lt;/p&gt;

&lt;h3&gt;
  
  
  Crab Steering
&lt;/h3&gt;

&lt;p&gt;Crab steering is a special type of active four-wheel steering that operates by steering all wheels in the same direction and at the same angle.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tiyG4QBl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jkwo40w9ubculwinlogu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tiyG4QBl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jkwo40w9ubculwinlogu.png" alt="Crab Steering"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The algorithm uses the Crab steering mode whenever the user slides the SpaceMouse on the plane. In this specific example, when the mouse is facing upper right corner, all four wheels are angled in the direction the mouse is pointing at. All four wheels have the same speed which is computed as the tangential velocity of a circle with a very large radius.&lt;/p&gt;

&lt;h3&gt;
  
  
  Active Front and Rear Steering
&lt;/h3&gt;

&lt;p&gt;AFRS mechanism involves front and rear wheels turning independently for smaller turning radius and better cornering stability. In this steering mode, rear wheels change the way a vehicle turns based on driving parameters. Each wheel’s velocity is computed as the tangential velocity of a circle.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9nEF9h1B--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hs1j8508h9y4idafog6g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9nEF9h1B--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hs1j8508h9y4idafog6g.png" alt="AFRS1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The twisting motion of the SpaceMouse is responsible for changing the radius of the vehicle’s curvature. The core of the algorithm is that it considers every motion as a circular motion and computes each wheel’s velocity and angle tangent to that circle. The radius of curvature (𝒓) is calculated by the equation shown above, and the angle value (θ) is controlled with the twisting motion of the mouse.&lt;/p&gt;

&lt;p&gt;When the mouse is twisted clockwise, θ is increased, resulting in a larger curvature radius. When the mouse is twisted counterclockwise, θ is decreased, resulting in a smaller curvature radius. Negative θ will make the circle move in the other side of the vehicle.&lt;/p&gt;

&lt;p&gt;This principle also applies to straight motion in scenarios such as Crab Steering mode. Continuously twisting the mouse counterclockwise will make θ very small, leading the turning radius to be almost infinite. At this point, the vehicle’s motion will be considered to be a straight motion.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TZHAJau0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ce4u44801qcaz1owp0it.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TZHAJau0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ce4u44801qcaz1owp0it.png" alt="AFRS2"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In these examples, straight motion and curving motion are accomplished simultaneously. When twisting and shifting the mouse occurs at the same time, the vehicle can perform more complicated motion, such as moving forward with a gradually decreasing turning radius.&lt;/p&gt;

&lt;h3&gt;
  
  
  Spinning
&lt;/h3&gt;

&lt;p&gt;Also known as the Zero Turn mode, Spinning is the motion of a vehicle rotating with zero radius. It is easily accomplished by turning all wheels perpendicular to the center diagonal line and turning the wheels in the same direction.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WNvOAtis--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/52gqguh4x7hi1du7vf79.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WNvOAtis--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/52gqguh4x7hi1du7vf79.png" alt="Spinning"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When one of the two buttons on the side of the SpaceMouse is pressed, the vehicle rotates in the respective direction. As shown in the screenshots above, the vehicle turns in a clockwise direction when the right button is pressed, and the vehicle rotates in a counterclockwise direction when left button is pressed.&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;In six months, I built a prototype vehicle and experimentally confirmed that our algorithm successfully processes the driver’s intention conveyed by a SpaceMouse and cooperatively controls all four wheels so that they don’t conflict with each other to accomplish the intended motion.&lt;/p&gt;

&lt;p&gt;I have worked on several for-fun projects in Arduino before, but Project Orbitron was by far the largest and most complex one I have ever done. Building the prototype alone took the entire summer vacation and over $1,000 in the budget. I spent another three months developing the algorithm while teaching myself Mathematica and constantly tweaking Orbitron's settings.&lt;/p&gt;

&lt;p&gt;Upon finishing the project, I participated in a &lt;a href="https://kentnews.org/2382/features/an-outstanding-performance-at-the-71st-annual-connecticut-science-and-engineering-fair/"&gt;local science fair&lt;/a&gt; and presented my work to the &lt;a href="https://kentnews.org/2525/features/a-guild-presentation-by-tyler-kim-20/"&gt;Kent Guild&lt;/a&gt;, an academic society at my school.&lt;/p&gt;

&lt;p&gt;Project Orbitron has become the core experience/project of my journey and ended up being the main topic for my college essay. The prototype is currently displayed on the first floor of Kent School's Pre-Engineering Center, and my algorithm is going through a patent process in Korea. &lt;em&gt;(Application Number: KR 10-2019-0087022)&lt;/em&gt;&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
