My code ran on the International Space Station

One year, my robotics class and I entered into a satellite programming competition run by MIT and NASA. We finished 12th in 2D and 80th in 3D.

Three months later, our code ran on hardware in the International Space Station, 250 miles above Earth, moving at 17,500 miles an hour. An astronaut was running the match. Our satellite lost twice.

Here’s how it all happened and how much of the code was actually mine.

Zero Robotics

MIT and NASA run a competition called Zero Robotics. Code runs on satellites called SPHERES,1 basically these colorful volleyball-sized robots that have been on the ISS for almost a decade. They fly around inside the space station with small gas thrusters. NASA uses them to test docking algorithms and formation flight. The space station is pretty much the only place you can run these experiments.

And every fall, MIT hands the control to students.

Two astronauts in the Kibo module of the International Space Station, one reaching for a SPHERES satellite floating in front of him, the other holding a cameraSPHERES in the Kibo module during a Zero Robotics session, about a year and a half before ours. Those satellites are running students’ code. Photo from NASA.

The competition runs from September to December. Our year, the game was called SpySPHERES, and the premise was interesting. One of NASA’s old satellites had broken up in low Earth orbit and is holding valuable data. Two rival fictitious corporations, BLU and RED, had to race to salvage it.2 Our satellite was meant to collect the data, recharge in the sunlight, and then score points by photographing the rival satellite, all while avoiding being photographed yourself. The game manual opens with, “Hello again employees, the game has changed.”

The cover of the Zero Robotics HS Tournament 2015 Game Manual, version 2.1.0, with two SPHERES satellites wearing spy fedoras and sunglasses in front of a globe, ringed by the words Spy Spheres 2015The manual showing two satellites in fedoras.

It might be easier to just show you.

SpySPHERES. Tap anywhere to fire a thruster in that direction. Your momentum will keep going forever, but your fuel can run out. The rival turns to face you, so you have to sneak into the shaded cone behind it and photograph it. The actual version of our code did this in three dimensions.

But the SPHERES aren’t teleoperated. You write C code that’s meant to fly autonomously. Your program only gets one life per match, and once the game has started, you can’t touch your code.

Rounds run in an online simulation, first in two dimensions and then full 3D. At the end, the top alliances’ code advances to a live championship on the International Space Station. Programs run on real SPHERES satellites, and an astronaut lets it run while everyone watches from Earth.

This grew out of my FIRST Robotics team, the W.A.R. Lords, Team 2485. We were 93 students the year I was president. Zero Robotics was played with our robotics programming class as a project in the fall. I wrote a very small amount of the code. Most of it was written by other people. The star of our team was a guy named Nicholas.

Programming for space

Writing code for a satellite in space is hard.

Unlike Earth, on the ISS you can’t just run your code again. Your program gets its one chance, its one supply of fuel, and that’s it. Even though you’ll try to simulate everything before the match, the real world always ends up being a bit different.

Two iPhone notifications from Feenstra, Wendy on the Zr-hs-2015-teamleads list, subject Server: “Hi Teams, The simulation servers are overloaded. Please wait 30 minutes before submitting a simul…” and then “You may continue with simulations. The servers have caught up with the requests.”Emails from my camera roll the week of the 3D deadline. There was only one simulator for us to run on, so it would constantly get overloaded.

The game was pretty hard. Since fuel is limited, you have to be very conscientious about what paths you take. The game had light and dark zones, and you could only recharge your energy by being in a light zone. Code size was also limited because the CPU on the SPHERES was pretty small, so every byte was critical. Time is limited because matches are so short, so you have to win quickly.

In a way, it was sort of like code golf. Engineering rarely has discipline like that. I miss the simplicity of a challenge with such tight restraints.

Getting a bit lucky

The truth about how we got onto the space station involved quite a bit of luck.

In the 2D version, we actually did very well. We finished 12th in the world out of 146 teams, but the 3D round was much harder for us. We finished 80th out of 128.3 Thankfully, that’s not where the season ended.

That’s because of the structure of the competition. In the finals round, teams had to form alliances of three. The top-placing teams that picked us probably did so because we had finished well in the 2D round, but also because so many of the other high-placing teams had already been picked.

One team was BACON from Charlottesville High School in Virginia, which finished second in the world in the original 3D round. The other one was Zanneio Stardust from Piraeus, Greece, which finished first in the world in 2D. We got a bit lucky to be on a team with two of the best in the world.

Alliance formats definitely have a bit of luck, but I think you need a certain amount of skill to get picked at all.

We formed a Google Group for the three of us, and for the next 6 weeks, we coded together across 9 time zones. The Greek team was constantly emailing us at strange hours.

An email from Pantelis Bouboulis to the BACON Zanneio 2485 ZeroRobotics group, subject Re: New Code!, reading: Hi guys! Just finished from a two-hour team meeting. We compiled a new code (Z-05d) that goes faster for the score items and gets energy from the light. Then it moves for the mirror (it gets the mirror in dark) and finally for any other scores. Although I am not satisfied with this, it runs well. The same problem happens with your code as well. In many cases Z-05d can beat your own code because it throws the other sphere out.Three days before the alliance deadline, our strategy was to grab the data, charge in the light, take the mirror in the dark, and then try to push the other satellite out of bounds.

Our main strategy came from the Greek team. We changed it about 25 times that month. The Virginia team also added a smart hugging maneuver, and we slipped in a few pieces of our own. You can read the full 407-line code.4 Here’s what it did right before taking a photograph.

//picture taking stuff
//Normal Picture
if ((((tt==0)&(energy>1.2f)&(photos_taken<=1)
        &(game.isFacingOther())&(!oponent_in_dark)&(game.isCameraOn()))
        && (game.getPicPoints()>0))
        |((energy<1) | ((TIME>150)&(photos_taken==0))|((tt>8)&(o_distance<0.35f)))) {
    game.takePic();
}

Here’s a small piece that came from us. Nicholas sent the alliance this file with some other stuff on December 12th, and it’s in every revision thereafter, including what flew on the space station.

//rescales a vector a --> l*a
void vrescale(float *vector, float local)
{
    vector[0] *= local;
    vector[1] *= local;
    vector[2] *= local;
}

This is the code of ours that ran on the ISS. Still quite cool, in my humble opinion.

The finals on the ISS

In the alliance round, we placed fourth out of 14. Here’s the email announcement.

An email to the group “BACON Zanneio 2485 ZeroRobotics 2015-2016,” subject “Alliance Celebration Thread,” reading “We got fourth place!! Congratulations to everyone! Our performance was only possible through the hard work that both teams put into this. Hopefully, we will do even better in the ISS finals!”7:02 p.m., the night the results were released. The email, of course, was addressed to our alliance. “Both teams” is pretty vicious. 💀

Our code was finally frozen at midnight Eastern, 5 days before Christmas. The Virginia team said they’d been up late testing and that “the final code is the product of real collaboration.” The Greek lead wrote back: “Of course when you play on the ISS anything can happen! Whatever the result we enjoyed the process!” I like that attitude.

The final ran on a Monday morning in January at 4:30 a.m. Eastern: a webcast from a lecture hall at MIT during a blizzard. On the ISS, Scott Kelly and Mikhail Kornienko, 10 months into their orbit, set up the satellites in the Kibo module.5 Then the match played out with the satellites running the students’ code, and ours was in there.

We lost both matches: 2-8 against an alliance which was seeded 8th, and 1-2 against an alliance seeded 12th.6 We were knocked out before anyone had even woken up.

Unfortunately, MIT’s recording of the webcast lived on a server that doesn’t resolve anymore, and the Wayback Machine never picked it up, so the footage seems to be gone forever. Bummer, but I still won’t forget that day. It was a very cool experience.

A local paper wrote about us, and I used their headline in my UC application essay: “My programming skills have, as a local newspaper put it, propelled me into space.”

The Times of San Diego article, headlined “Coding Skills Propel Francis Parker Students into Space,” by Hoa Quach, February 12 2016, with a photo of the school captioned “Courtesy of Francis Parker,” opening “Francis Parker’s Zero Robotics Team has made it to outer space.”Times of San Diego: “Francis Parker’s Zero Robotics Team has made it to outer space.” It says the final round was “refereed by astronauts,” which is amazing. None of us were named in the article.

I think that headline really did help me get into Stanford. It also sort of helped me view my ambitions as bigger. Who’s to say that the code we write has to stay on our phones? The space industry has become a real and feasible career path.

Our code made it to space. It lost twice and then came back. I have written a lot of software since then, but I don’t think anything else has made it that far out. Yet.

Footnotes

  1. Synchronized Position Hold, Engage, Reorient, Experimental Satellites. NASA and the U.S. government in general are the GOATs of acronyms. The game’s manual cover art has two spies wearing fedoras.

  2. The game’s backstory talks about Alvar Saenz-Otero as CEO of BLU Industries, and RED is “led by their CEO Evil Alvar.” Alvar Saenz-Otero is the real MIT scientist who led the SPHERES program for many years. He made himself both the hero and the villain.

  3. MIT took the leaderboard down a while ago, but the Wayback Machine still has it. 2D, which finished on October 3rd, had Zanneio Stardust at 1st, Team 2485, us, at 12th, and BACON at 45th. 3D, which ended on October 31st, had BACON at 2nd, Zanneio at 23rd, and Team 2485 at 80th. The alliance round, which ended on December 5th, had BACON, Zanneio, and 2485 at 4th of 27. In my college app, I was able to say we were 4th in the world, though on our own we were 80th. The power of collaboration and a smaller denominator.

  4. MIT’s results page links to every finalist’s flight code, but the labels on the page are stale text from the year before, so you have to follow each alliance’s link down into its own download. I almost accidentally quoted another team’s code in this post. It debug-prints “WAR NEVER CHANGES” three times, which I thought was something that our team, the W.A.R. Lords, had written, but it was instead from an alliance called Space::Yabadabad0rs!

  5. NASA’s ISS blog post for that day said “One-Year Crew members Scott Kelly and Mikhail Kornienko set up a pair of bowling ball-sized satellites in Japan’s Kibo lab module for a student competition.” The paper said that the round was refereed by astronauts, and NASA said that they had set up bowling balls. What a great high school experience.

  6. Bracket B-1: BACON Zanneio 2485 lost to SHA-2468, 2 to 8, and then Echelon, 1 to 2. The co-champions were CrabNebulaMVZeroVADARS and TheFermiFloatingTeamTachyonsJuggler. The alliance team names grew very long because they had to accommodate three different teams. MIT posted four-times-speed video of both of our matches on a Google Drive, but it’s now access restricted. If they ever grant me access, I’ll post it here.