<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Saurabh Patel on Medium]]></title>
        <description><![CDATA[Stories by Saurabh Patel on Medium]]></description>
        <link>https://medium.com/@saurabhpatel?source=rss-7d91cb24886e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*mJGSjKmIIM6KkHxDmPl3wA.jpeg</url>
            <title>Stories by Saurabh Patel on Medium</title>
            <link>https://medium.com/@saurabhpatel?source=rss-7d91cb24886e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 12:16:15 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@saurabhpatel/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How I docked the Dragon SpaceX using Python]]></title>
            <link>https://medium.com/@saurabhpatel/how-i-docked-the-dragon-spacex-using-python-2938b78db0dc?source=rss-7d91cb24886e------2</link>
            <guid isPermaLink="false">https://medium.com/p/2938b78db0dc</guid>
            <category><![CDATA[space]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[spacex]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Saurabh Patel]]></dc:creator>
            <pubDate>Sat, 06 Jun 2020 11:08:40 GMT</pubDate>
            <atom:updated>2020-06-07T14:45:28.519Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>“Dragon SpaceX docking sequence is complete. Houston, we’ve a successful docking.”</blockquote><p>Recently, we have all witnessed the historical event of crew Dragon vehicle launch, rendezvous and successful docking. It has opened up a new chapter in space exploration since the retirement of the space shuttle program at NASA. I think it is a very commendable feat.</p><p>Luckily for <em>space enthusiasts</em>, SpaceX has provided a simulation interface of the Dragon for docking at the ISS, which is very similar to the actual interface in the Dragon vehicle. You can try your hand at docking <a href="https://iss-sim.spacex.com/">here</a>, and see if you can get aboard the ISS. You can go through the instructions to understand the objective, and how to operate it. It is like playing a video game, right ?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3v7OExHmsjJo0CugZkFA5w.png" /><figcaption>Screenshot of <a href="https://iss-sim.spacex.com/">https://iss-sim.spacex.com/</a></figcaption></figure><p>Here is a brief explanation of the objective and the controls. As you can see from the screenshot, we have two major components to deal with in our environment:</p><ol><li><strong>Rotational components(Roll, Pitch and Yaw)</strong> - These values show our rotational orientation relative to the ISS. We can control it using the rotation controls given on the bottom right corner of the screen. To visualise these movements, you can imagine a cylinder, rotating along three different axes while staying in the same position.</li><li><strong>Positional components(X, Y and Z)</strong> - These values show our translated position relative to the ISS. We can control them using the position controls given on the bottom left corner of the screen. Theses controls move our vehicle along X, Y and Z axis, and help us in bringing our vehicle closer to the ISS docking component.</li></ol><p>On the screen, green numbers show the corrections in our rotation (position) for a successful alignment, and the blue numbers are rates (speed) at which we are rotating (translating).</p><p>For a successful docking, we need to bring all the green numbers below <strong>0.2</strong>, and when we are close to the ISS, our speed should be under <strong>-0.2</strong>. The tricky bit here is controlling the positional components and the speed, when the vehicle is getting closer to the ISS. That requires some patience in the end, to avoid banging into the ISS at high speed (You might get banned from the Earth for that!!). It took me a couple of tries to get it docked successfully.</p><p>While playing around with it, I thought why not try to automate this process? Hence I created a bot to automate the docking process using Python and Selenium. The coming paragraphs are about the approach I used, the process and the ML algorithms I tried.</p><p>It is clear from the objective that the logic behind the process of automating is quite simple. We just have to take the vehicle readings as input, and use controls to correct our position and orientation. You can go to my <a href="https://bitbucket.org/srp201201051/dragon-docking/src/master/"><strong>Bitbucket repository</strong></a> to test and check out how the bot works.</p><p>The gist of the algorithm being used by the bot is as below:</p><pre>1. Get the vehicle&#39;s readings.<br>2. Check if the readings need any corrections.<br>3. If they do, then use the controls to fix the readings. Go back to step 1.<br>4. If they do not, then our readings are fixed.</pre><p>The bot uses above steps to fix the rotational readings first, and then the positional readings. A few important things to note down:</p><ul><li>During the simulation, gravity mode is on, so our positional readings might drift slowly over the time due to the Earth’s gravitational pull, even after we have corrected them.</li><li>We would like to prioritise fixing Y and Z readings first, as those dimensions should be aligned properly before moving forward on the X dimension. If they are no aligned, then we will most likely run into some other components of the ISS <em>or </em>we might even get past the ISS without docking. (There is also a possibility of running into the floating Tesla. I saw it around once 😂)</li></ul><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FdeEzWxRxlkM&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DdeEzWxRxlkM&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/d535eb1ac61f8f49bfced1242b46d823/href">https://medium.com/media/d535eb1ac61f8f49bfced1242b46d823/href</a></iframe><p>I also dabbled in supervised learning and reinforcement learning(RL) techniques to build agents to complete the docking process automatically. I got good results from supervised learning, but not so much with reinforcement learning(as I suspected). I would be curious to learn more about how to approach and solve this problem with reinforcement Learning technique, if anyone gets their hands dirty with RL. The current repo does not have my code for the ML techniques, which I will be updating soon. However, here is the approach that I followed.</p><p>Our main problem is divided in two subproblems - one is fixing the rotational readings, and the other is fixing the positional readings. Solution for each of them would be quite similar with minor changes details.</p><h4>Supervised Learning Technique</h4><p>For the supervised learning part, the outcome that I got is essentially same as building a fancy if-else model. First, I focused on generating the training data, that consists of the feature variables, and a target variable. In our framework, features would be the readings and rates/speed of the vehicle, and the target would be some value suggesting what controller buttons need to be pressed.</p><p>If we take all the combinations of possible feature values, then the number of combinations will be very large, as our features are continuous real numbers. If we consider around 1000 possible values for a feature, then the number of combinations for 3 features will be 1 billion. So, to reduce this features space, we can divide the continuous values in different ranges depending on the magnitude. Then, we can assign integer values(from -<em>a</em> to +<em>a</em>) to these ranges. These values represent if the required correction is very big/big/small/very small/no correction etc. If we take the value of <em>a</em> to be 3, then the number of combinations for 3 features will be 7*7*7 = 343, a huge reduction from 1 billion. Similarly, we can reduce features space for rates/speed, by taking only discrete values. This is possible to do because we do not have to react on every small change in the readings, which gives us the flexibility to take into consideration only a handful of discrete values of these features.</p><p>For the target value, we can use an integer with 6 bits, as we have 6 buttons to play with for each of our sub problem. Based on the set bits in the target value, we will be pressing the corresponding control buttons.</p><p>After using this technique, we can generate training data, and fit any supervised learning model on it. Then, using that model, we can run the simulation to achieve automated docking. I used DecisionTreeClassifier from sklearn, as it seemed like an obvious choice for the job.</p><h4>Reinforcement Learning Technique</h4><p>We have a limited degree of freedom to interact with our environment. So, this should be a really nice playground for data science enthusiasts to build some self-learning RL agent. As a beginner in this place, I believe these points are of interest to build an RL agent - <em>environment state, action space, reward function and episode termination condition. </em>The learning time and efficiency highly depends on how we frame these variables and functions. To reduce the complexity of the problem, we can leak some intelligence to our agent to help it learn and achieve the objective faster.</p><p>I tried training a DQN agent using Tensorflow without much success. But, here are a few pointers that might help someone who is just getting started:</p><ul><li>To effectively train the agent, we will need to run a lot of simulations. For that, I initially thought of running the selenium driver with headless option, so that the Firefox can keep running in the background, and the agent can keep training. But, the website requires WebGL drivers to function, so this option was useless. Training an agent while staring at the browser window does not sound like an efficient way, as it can take days to train the agent. <em>So,</em> <em>I ended up writing a python simulator that simulates the the SpaceX simulator. </em>It is not 100% accurate, but it is quite good enough to train the agent. The agent can interact and learn fast with this python simulator.</li><li>For the environment state and action space, I believe we can use a similar approach to what I mentioned in the supervised learning section. That will help reduce the combinations, and eventually help the agent learn faster without loosing accuracy.</li><li>For the reward function, we can use the Euclidean distance function to calculate the distance between the current state, and the final state. We can use more tweaks here to positively reinforce our desired behaviour in the agent.</li><li>We should also choose a smart policy to terminate an episode, that does not hinder the agent’s random exploration policy. At the same time, we would not like our agent to wander away in some other galaxy!! So, we can put an upper bound on the absolute value of the vehicle’s readings, and a threshold on the number of time steps.</li></ul><p>I will be publishing more updates as I make progress. Let me know your ideas, suggestions and feedback in the comments. This training will be very useful if someday you wake up in a capsule floating around the ISS. Let’s hope that day does not come, but just in case!! 😄</p><p>Edit1: I have committed the code for supervised learning framework on the Bitbucket repo. You can check it out.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2938b78db0dc" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>