What is the Mars Curiosity Rover's software built in?
The Mars Curiosity rover has landed successfully, and one of the promo videos "7 minutes of terror" brags about there being 500,000 lines of code. It's a complicated problem, no doubt. But that is a lot of code, surely there was a pretty big programming effort behind it. Does anyone know anything about this project? I can only imagine it's some kind of embedded C.
Good point, sure, it's probably got a breadth of technology associated with it. I want to know more about all of that :)
Which part? The spacecraft? The rover? Instruments? The ground system? As other comments indicate, there are probably several languages used in the different components. It's not out of the question that assembler was used for some of the time critical components.
Since it's a government project I am guessing Forth, MUMPS 2011, and RPG V, with management interfaces built in Object COBOL, and motor control in Postscript.
I think Roverbasic, a new language purportedly designed by the JPL, but it will turn out to be actualy written by Microsoft.
To be honest, when I saw the 500kloc figure I caught myself thinking "Only?" It could have been realistic had it been Haskell, but having read a bit about previous projects and their low level languages, this seemed way too low. The 2.5mio loc C code cited below are more believable.
Some of the sub-questions you asked were not answered in the other question before. That has been fixed :)
@Philip K It might be the 500kloc is for the descent software only. The keynotes in the answer of drhorrible divides the MSL into 3 different stages, running different software, 1. the flight (earth to mars) 2. The descent and landing 3. The rover itself, roving around.
@PhilipK I'm thinking 500k LOC is with the comments and extra blank lines stripped out - so, 500k _functional_ LOC, but 2.5m lines total in the codebase. ;)
A more interesting question that *"in what language?"* is *"with what process?"*. It's the process that make the difference, and NASA has been using a rigorous one for decades now.
It was all written in LISP. Nasa is trusting LISP's backtracking to infer all the correct decisions to make.
This overview was really interesting, talking about the tech behind its software and instruments: http://www.extremetech.com/extreme/134041-inside-nasas-curiosity-its-an-apple-airport-extreme-with-wheels
For an insight into NASA software engineering culture and practices, there's a great article from 1996: http://www.fastcompany.com/28121/they-write-right-stuff
It's running 2.5 million lines of C on a RAD750 processor manufactured by BAE. The JPL has a bit more information but I do suspect many of the details are not publicized. It does appear that the testing scripts were written in Python.
The underlying operating system is Wind River's VxWorks RTOS. The RTOS in question can be programmed in C, C++, Ada or Java. However, only C and C++ are standard to the OS, Ada and Java are supported by extensions. Wind River supplies a tremendous amount of detail as to the hows and whys of VxWorks.
The underlying chipset is almost absurdly robust. Its specs may not seem like much at first but it is allowed to have one and only one "bluescreen" every 15 years. Bear in mind, this is under bombardment from radiation that would kill a human many times over. In space, robustness wins out over speed. Of course, robustness like that comes at a cost. In this case, it's a cool $200,000 to $500,000.
An Erlang programmer talks about the features of the computers and codebase on Curiosity.
Hmmm... it still is a surprise to me that such an important mission isn't running as closer to Machine Code e.g. Assembler...
JPL C language coding standards, specifically for embedded environments instead of "ground software" as they call it. http://lars-lab.jpl.nasa.gov/JPL_Coding_Standard_C.pdf
@Dynamic: It's such an important mission that NASA wouldn't risk it. Humans writing assembly make more errors, that's a measured fact.
It's really all done in C? I thought NASA tended to avoid C on the grounds that its performance comes at the cost of being far too easy to shoot yourself in the foot with it, and preferred higher level languages with more robust error detection.
@GordonM: I guess NASA makes a lot of re-use of existing, mature code, developed in the last decades for previous missions. So it is more amazing the code is not written in Fortran.
Compiled C code is machine code, assembly language is machine code, I don't see the difference. There isn't a huge performance difference when you get down to it.
NASA are extermely careful with their code. Everything (EVERYTHING) is done in the spec first and is repeatedly reviewed, checked and refined. When it is put into the life code stream it is almost a cut and paste of the spec's reference. The test scripts are given at least as much attention as the code is and no 'flashy' or clever code tricks are allowed unless they are critically needed.
Whoa, C. Colour me surprised. I would have assumed some strictly checked language without such things as pointers or undefined behaviour.
One shouldn't judge a language only by what a minimal compiler allows. Have you *seen* any of today's "static" code analyzers? (They aren't exactly static anymore.)
As for why they need to largely stick with C; if you look at the Rad750's datasheet, the fastest version on offer is only a 200mhz chip. Since it's not mentioned, I assume it's also only single core. That's not much hardware to give room for higher level languages overhead.
@Amarghosh: yeah, and see how well your cell phone works when it goes through a high-radiation environment such as outer space :)
@KonradRudolph check the JPL Coding standard. No dynamic allocation is one of the rules.
@Dan That’s a fallacy. Higher-level languages don’t necessarily come with an overhead. Consider Ocaml. More importantly, the coding standards used here (JPL …) mandate many redundant checks which take a lot out of the speed advantage that C otherwise has. As a result, C’s performance advantages vanishes in a puff of smoke. The real reason for using C is most probably the potential of fine-grained control over allocation but again I’d have expected specialised higher-level languages to offer this.
@Stefan No, not everything at NASA has the same set of code standards. But every project involving software engineering has the same set of process standards. See NPR7150. http://nodis3.gsfc.nasa.gov/displayDir.cfm?t=NPR&;c=7150&s=2 and even then this depends on the class of the software. Class A software usually involved keeping Humans alive in space. But class H software is general purpose desktop software. Class H software does not require verification and validation, but class A does.
@SeanMcCauliff, thanks. I read a doc about their software standards, I guess it only refered to a certain class but I assumed it was all of their software.
Looks like much of that C code (at least all the FSM parts) had been generated from a high level DSL.
@Dynamic _especially_ for an important mission you want all the extra help that higher languages can give you.
@TMN If you had any experience with Ada you'd find it is a very safe language and leaves very little to chance, encouraging engineers to actually think about the code they write; hence it being used often in safety critical systems along with formal notation (Z is quite popular). To bypass the design intentions of Ada is not easy, yet the developers went out their way and did just this.
Why all the implicit assumption that performance is paramount? Consider the speed at which the rover travels and the speed of it's various servos, it doesn't have to be lightning, real-time, nanosecond fast. Nor is concurrency a major issue, it can pretty much do most of it's task serially (run motor 1 second, turn camera, turn wheel, run motor 0,5 seconds etc). Stability and precision, I would think, are far more important.
@pap:nano-second speed isn't necessarily the issue, but real-time is. Stuff has to happen pretty much exactly when it is supposed to happen. This is why VxWorks is a popular choice for embedded real-time systems. VxWorks has great support for C, and ok support for C++. I never used it with Java, but suspect that to make that real-time they'd have to make it non-standard. Anyways, my point is that VxWorks probably drove the language decision.
@KonradRudolph : if they ban dynamic allocation in C (for various reasons) then you'll never get it written in .NET or Java, as those systems use dynamic allocation almost exclusively. Java for example has licence restrictions for using it to write critical system. The point of C is that you can guarantee exactly what is happening at any given point in execution, something expensive to do, but necessary if sending a field engineer to debug is impractical.
@gbjbaanb And you may notice that I suggested neither of those languages. What make you think I did?
@ThorbjørnRavnAndersen: Sorry, but high level languages suck for anything performance and safety oriented. They abstract away many things, but all of them have problems, every solution adds new layers of problems, and getting critical system to work is to remove problems, so any high language is an exact opposite of what you want to do. Good read - http://www.joelonsoftware.com/articles/LeakyAbstractions.html
@Coder So you essentially say that you need to write in machine code to have anything reliable in a critical system? Or is your conclusion something else?
@Coder False. You've ignored decades of progress in programming languages. There is actually the opposite argument: that if mission-critical software started getting written in higher level, functional languages, there would be fewer failures.
@Coder: The latest Air Traffic Control systems are written in Java for one example. Don't mix up system reliability with software reliability- the most reliable systems are made up of unreliable parts. Because the most reliable parts (hardware and software) can fail, the system is designed to work when they do. Because it works when they fail, they non longer need to be reliable. Todays highly reliable systems are made out of consumer grade components. This does not apply to spacecraft where you tend to only have 1 of each system, and only duplicate the most critical.
@ThorbjørnRavnAndersen: Almost, you need nop slides and stuff like that to fail when RAM error or cosmic ray creates a havoc in the memory. You really want to do any garbage collection in mission critical systems. Everything has to be super simple and easily checkable. Thinking that some high level gives you better reliability is very wrong. There are few things that might help when used sparingly, say templates, and things that downward suck, like exceptions.
@Coder I do not know if you program space crafts for a living. I don't so I found this small historic piece about Lisp on space crafts - _Debugging a program running on a $100M piece of hardware that is 100 million miles away is an interesting experience_ - http://www.flownet.com/gat/jpl-lisp.html
@ThorbjørnRavnAndersen: If you need to debug an app 100 million miles away, it's already a problem. And don't tell me you want to debug Java program 100 million miles away. Once under certain circumstances some weird JRE bug causes some weird behavior in garbage collector which causes chain reaction in all dynamic memory accounting, addressing and deletion. You won't even be able to re-flash the thing. And the article had one thing right - "one thing you would do - get rid of lisp". Shame that the author is a fanboy and doesn't get the core of the problem.
@Coder read the article. They found the bug and fixed it - and Lisp is not exactly assembly language.
@Ramhound "There isn't a huge performance difference when you get down to it.": I admit it is a while ago, but the last time I wrote the same program in C and assembly to compare for speed, the assembly program turned out to be twice as fast.