Jump to content

Making your own code


Recommended Posts

Im not sure I mentioned it but I'm making my "model rocket" as a large liquid rocket so it's not like I'm in a rush. I want to make my own code because I really hate learning code. I mean I would rather stare at a brick wall for 1 hour than learn code for an hour, I'm not joking about that. But if I invent it I can make it for specially what I need and reduce file size hence how expensive my flight computer needs to be. I'm going to have a guidance system, an RCS, system and a stability program.  

Edited by Cheif Operations Director
Link to comment
Share on other sites

No formal language is actually difficult to learn. Grammar, syntax, it's all done in a few hours to days. Compared to German or Spanish, Chinese, Japanese ...

 

To write a well defined and behaved program is something different, though ... :-)

I'd recommend C for the beginning. Good for everything, simple, fast and just about to regain place 1 among the programming languages (tiobe). Here is an open source interpreter written in C (lua), often used in games etc. for scripting.

Edited by Green Baron
Link to comment
Share on other sites

http://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-42735-8-bit-AVR-Microcontroller-ATmega328-328P_Datasheet.pdf

Page 438

Or if you don't feel like opening it, that microconroller (ATmega328, the one that is used in quite a few Arduinos) is 4 x 4 x 0,9 mm. If that is small enough for you, Arduino is the way to go.

How do you expect to make your own programing language if you don't learn other stuff about programing languages? I mean, knowledge required to make a brand new programing language capable of interfacing with any hardware is certainly greater than just learning an existing language and using vast amount of other peoples work that does the hard part in the background without needing to understand that as well.

Believe it or not, but staring at the wall will not help you in making your own language, while an hour tinkering with Arduino will certainly get you a good deal towards the program you are describing. I am still confused why you think that making a new language and then writing the code in it is less work than just writing the code in an existing language.

What are you going to do about interfacing with your components? You talk about guidance, that would suggest inertial navigation, barometric altitude sensor and possibly GPS. Do you plan on building those systems from scratch as well or will you use off the shelf components/modules? I would guess off the shelf components since, let's be honest, there is absolutely zero chance of you developing your own GPS module. Do you know how those modules communicate with other devices? Have you even heard of I2C and SPI? Do you plan on writing your own libraries for that as well? I'm not saying that's impossible, far from it, but that part alone is more work than entire software you'd need for your rocket.

Let me be honest. You're at the peak of the Dunning Kruger graph.

Pick up a C or a C++ book or an online tutorial and order yourself a few Arduino Unos from ebay (perhaps a starter kit with a bunch of other electronic components included) and just play with that for a few days. It will open your eyes.

 

Link to comment
Share on other sites

Just now, kerbiloid said:

I mean are you going to physically make it by hands, or this is a model to "exist" in imagination and computer.

Real like in hands. 

19 minutes ago, Shpaget said:

http://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-42735-8-bit-AVR-Microcontroller-ATmega328-328P_Datasheet.pdf

Page 438

Or if you don't feel like opening it, that microconroller (ATmega328, the one that is used in quite a few Arduinos) is 4 x 4 x 0,9 mm. If that is small enough for you, Arduino is the way to go.

How do you expect to make your own programing language if you don't learn other stuff about programing languages? I mean, knowledge required to make a brand new programing language capable of interfacing with any hardware is certainly greater than just learning an existing language and using vast amount of other peoples work that does the hard part in the background without needing to understand that as well.

Believe it or not, but staring at the wall will not help you in making your own language, while an hour tinkering with Arduino will certainly get you a good deal towards the program you are describing. I am still confused why you think that making a new language and then writing the code in it is less work than just writing the code in an existing language.

What are you going to do about interfacing with your components? You talk about guidance, that would suggest inertial navigation, barometric altitude sensor and possibly GPS. Do you plan on building those systems from scratch as well or will you use off the shelf components/modules? I would guess off the shelf components since, let's be honest, there is absolutely zero chance of you developing your own GPS module. Do you know how those modules communicate with other devices? Have you even heard of I2C and SPI? Do you plan on writing your own libraries for that as well? I'm not saying that's impossible, far from it, but that part alone is more work than entire software you'd need for your rocket.

Let me be honest. You're at the peak of the Dunning Kruger graph.

Pick up a C or a C++ book or an online tutorial and order yourself a few Arduino Unos from ebay (perhaps a starter kit with a bunch of other electronic components included) and just play with that for a few days. It will open your eyes.

 

Ok I guess I'll give it one more chance

Link to comment
Share on other sites

47 minutes ago, Cheif Operations Director said:

I want to make my own code because I really hate learning code. I mean I would rather stare at a brick wall for 1 hour than learn code for an hour, I'm not joking about that.

This is like saying, "I want to build my own motorcycle from scratch because I really hate learning about motorcycles." If you're serious, then the best advice is to drop the project now, because you're going to spend much more than 1 hour to accomplish what you've proposed.

47 minutes ago, Cheif Operations Director said:

But if I invent it I can make it for specially what I need and reduce file size

You're very unlikely to "reduce file size" below what you'll get by compiling a well designed C program. Especially if you don't want to spend hours learning to code.

Link to comment
Share on other sites

1 hour ago, Cheif Operations Director said:

Im not sure I mentioned it but I'm making my "model rocket" as a large liquid rocket so it's not like I'm in a rush. I want to make my own code because I really hate learning code. I mean I would rather stare at a brick wall for 1 hour than learn code for an hour, I'm not joking about that. But if I invent it I can make it for specially what I need and reduce file size hence how expensive my flight computer needs to be. I'm going to have a guidance system, an RCS, system and a stability program.  

How much experience do you have in model rocketry (or engineering)?

It's good to have ambition but if you try too much too quickly you will become discouraged at how hard everything turns out to be, it's better to take baby steps at first and temper your ambitions.
This goes for writing a new programming language from scratch and for building a complex liquid fueled rocket. Meet up with your closest rocketry club, have fun with solid fueled rockets, mess around with Arduino/RPi guidance to get the grips of it, and make your way up slowly.

Quote

I want to make my own code because I really hate learning code. I mean I would rather stare at a brick wall for 1 hour than learn code for an hour, I'm not joking about that.

I have awful news for you: as others have said above you need good mastery of other languages before even attempting to write your own, which will involve massive amounts of coding anyway.

Link to comment
Share on other sites

4 hours ago, Green Baron said:

No formal language is actually difficult to learn. Grammar, syntax, it's all done in a few hours to days. Compared to German or Spanish, Chinese, Japanese ...

 

To write a well defined and behaved program is something different, though ... :-)

I'd recommend C for the beginning. Good for everything, simple, fast and just about to regain place 1 among the programming languages (tiobe). Here is an open source interpreter written in C (lua), often used in games etc. for scripting.

The C++ spec is 1605 pages long.  While being able to program in the "pigeon english" equivalent of C++ might take little more than C, being able to parse code using all the features may be as hard as doing the same with a human language.  It certainly is an outlier, and its popularity has turned it into the proverbial kitchen sink.

I'd recommend Python.  Or if you want to get "down to the metal", C (which is probably best for small arduino code).  As the introduction to K&R said, "C is not a big language, and it is not well served by a big book".

https://www.iso.org/standard/68564.html

Link to comment
Share on other sites

My code currently only has 3 pages of operations and I can code about 1/2 of what I need for my Rocket excluding connecting to a physical device. The biggest problem with me making my own code is making it communicate with the rockets hardware.

Like I said I designed it specifically for aerospace and rockets so having 1 command that says turn 15* is possible. It's very simple why write 1000 pages of code to do the same thing.

Of course assign the values is important too 

Link to comment
Share on other sites

Here is my "guidance program" I did not include the stability program because it's long.

<

UnconditionallyTrigger %lockprog10seconds%

File(Fin1)+File(Fin3) %activate2seconds%

%lockprogramperp%

>

That is it here is the translation

%lockprog10seconds% locks this program for 10 seconds

File Fin1 and File Fin3 simpily specify a turn Rate for the fins for example 5* per second that means the rocket fins rotates 10* in two seconds.

%lockprogperp% mean lock the program perpetually. 

< and > is the beginning and end of the program respectively

-------------

So when you launch this rocket from a software perspective it goes up for 10 seconds and then pitches 10* over the course of two seconds then it proceeds to fly.

I'm just curious if someone wanted to do this in C or python how would that look post the full code that would achieve the same outcome

I'm just curious if it would be simpiler or harder. 

P.S. My program reads left to right just like english

Link to comment
Share on other sites

5 hours ago, Cheif Operations Director said:

Im not sure I mentioned it but I'm making my "model rocket" as a large liquid rocket so it's not like I'm in a rush. I want to make my own code because I really hate learning code. I mean I would rather stare at a brick wall for 1 hour than learn code for an hour, I'm not joking about that. But if I invent it I can make it for specially what I need and reduce file size hence how expensive my flight computer needs to be. I'm going to have a guidance system, an RCS, system and a stability program.  

The problem is that the easiest way to write a new language is write it in another language. You may want to consider how you could learn to enjoy learning programming, or consider collaborating on your project with someone who does enjoy it. The fastest way to get burned out on a hobby project is to hate doing parts of it.

5 hours ago, Shpaget said:

[...]

Let me be honest. You're at the peak of the Dunning Kruger graph.

[...]

I think this is a bit unfair, they've never said that they know everything about programming. In fact they're said that they don't know very much, and are asking for help with, admittedly, something that is harder than the original project.

42 minutes ago, Cheif Operations Director said:

Here is my "guidance program" I did not include the stability program because it's long.

<

UnconditionallyTrigger %lockprog10seconds%

File(Fin1)+File(Fin3) %activate2seconds%

%lockprogramperp%

>

That is it here is the translation

%lockprog10seconds% locks this program for 10 seconds

File Fin1 and File Fin3 simpily specify a turn Rate for the fins for example 5* per second that means the rocket fins rotates 10* in two seconds.

%lockprogperp% mean lock the program perpetually. 

< and > is the beginning and end of the program respectively

-------------

So when you launch this rocket from a software perspective it goes up for 10 seconds and then pitches 10* over the course of two seconds then it proceeds to fly.

I'm just curious if someone wanted to do this in C or python how would that look post the full code that would achieve the same outcome

I'm just curious if it would be simpiler or harder. 

P.S. My program reads left to right just like english

It really depends on how you interface the software with the hardware, but in python it might look like (pardon extremely rusty python skills):

degreesPerSecond = 0

time.sleep(10)

rotateFin(["Fin1", "Fin2"], 10, 2)

sys.exit

def rotateFin(fins, degrees, seconds):
  for i in fins:
    degreesPerSecond = degrees/seconds
    #however you interface the code to your hardware, passing degreesPerSecond and seconds to the servo defined by the fin name
  return
    

From my point of view, the hard part is the interface of hardware and software, and writing a custom language would only be pushing that problem to a lower level.

EDIT: Just realized defining degreesPerSecond every loop is dumb, but you can't edit code, so ¯\_(ツ)_/¯

Edited by Mad Rocket Scientist
Link to comment
Share on other sites

It almost sounds like what the OP is really wanting is some kind of pseudocode. Pseudocode is kind of like making an outline before you write a story. You can just use plain language and high level concepts like:

========

For 10 -> 0

count down

end loop

========

Then you can pick some other language to actually write your program in, following the logic that you wrote down in the pseudocode.

Link to comment
Share on other sites

5 hours ago, Shpaget said:

http://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-42735-8-bit-AVR-Microcontroller-ATmega328-328P_Datasheet.pdf

Page 438

Or if you don't feel like opening it, that microconroller (ATmega328, the one that is used in quite a few Arduinos) is 4 x 4 x 0,9 mm. If that is small enough for you, Arduino is the way to go.

How do you expect to make your own programing language if you don't learn other stuff about programing languages? I mean, knowledge required to make a brand new programing language capable of interfacing with any hardware is certainly greater than just learning an existing language and using vast amount of other peoples work that does the hard part in the background without needing to understand that as well.

Believe it or not, but staring at the wall will not help you in making your own language, while an hour tinkering with Arduino will certainly get you a good deal towards the program you are describing. I am still confused why you think that making a new language and then writing the code in it is less work than just writing the code in an existing language.

What are you going to do about interfacing with your components? You talk about guidance, that would suggest inertial navigation, barometric altitude sensor and possibly GPS. Do you plan on building those systems from scratch as well or will you use off the shelf components/modules? I would guess off the shelf components since, let's be honest, there is absolutely zero chance of you developing your own GPS module. Do you know how those modules communicate with other devices? Have you even heard of I2C and SPI? Do you plan on writing your own libraries for that as well? I'm not saying that's impossible, far from it, but that part alone is more work than entire software you'd need for your rocket.

Let me be honest. You're at the peak of the Dunning Kruger graph.

Pick up a C or a C++ book or an online tutorial and order yourself a few Arduino Unos from ebay (perhaps a starter kit with a bunch of other electronic components included) and just play with that for a few days. It will open your eyes.

 

I do not want to learn other programming languages, I already told you I would rather stare at a brick wall for an hour I will gladly learn about computers and programming but no specific language unless I must. I know I may seem insane but If this code can be completed before my rocket I can have a very simple flight computer and have a ton of capabilities essentiall up too orbital flight a second version could support orbital flight. What bugs me is that with standard code is meant for a ton of applications I as I said only need it for aerospace hence why I'm basing it around a simple operations based code. What my example was is what it will be the two challenges I face are

1. Getting the code to actually work

2. Connecting to hardware such as motors

Link to comment
Share on other sites

5 hours ago, Gaarst said:

How much experience do you have in model rocketry (or engineering)?

It's good to have ambition but if you try too much too quickly you will become discouraged at how hard everything turns out to be, it's better to take baby steps at first and temper your ambitions.
This goes for writing a new programming language from scratch and for building a complex liquid fueled rocket. Meet up with your closest rocketry club, have fun with solid fueled rockets, mess around with Arduino/RPi guidance to get the grips of it, and make your way up slowly.

I have awful news for you: as others have said above you need good mastery of other languages before even attempting to write your own, which will involve massive amounts of coding anyway.

I've done your standard model rocket kits. I've customized quite a few to have custom boosters and custom second stages. I'm working on one that has boosters that seperate via the ejection charge. How I'm going to keep the rocket from catching on fire is a problem but I'm working on it. 

5 hours ago, HebaruSan said:

This is like saying, "I want to build my own motorcycle from scratch because I really hate learning about motorcycles." If you're serious, then the best advice is to drop the project now, because you're going to spend much more than 1 hour to accomplish what you've proposed.

You're very unlikely to "reduce file size" below what you'll get by compiling a well designed C program. Especially if you don't want to spend hours learning to code.

As I stated my coding is based around operations you only need 3 lines of code for a standard guidance program. Not self stabalizing but just the actual guidance program.

Also your example is semi-wrong what would be more accurate is saying I want to build my own ford truck out of spare parts but I hate BMW spare parts.

Link to comment
Share on other sites

22 minutes ago, Cheif Operations Director said:

Also I've never looked in to coding because I hate it so much. I just started looking into it less than a week ago.

Well, if you've only been at it a week, how do you know you hate it? What language(s) have you been trying to learn, and what resources have you been trying to use to teach yourself? You could easily have picked a badly or confusingly designed language, or simply been using a bad resource for learning, without realizing it.

There is something else to this general problem, though - to design your own programming language, you're going to have to teach yourself a good amount of theory of computing, in order to not design a language that is either impossible to parse or insufficiently expressive to do what you want to do. And if you think learning a programming language is boring, just wait till you get to finite state automata, context-free grammars, and Turing completeness. Writing your own programming language could easily become at least a master's thesis if you make it interesting enough.

Link to comment
Share on other sites

6 minutes ago, IncongruousGoat said:

Well, if you've only been at it a week, how do you know you hate it? What language(s) have you been trying to learn, and what resources have you been trying to use to teach yourself? You could easily have picked a badly or confusingly designed language, or simply been using a bad resource for learning, without realizing it.

There is something else to this general problem, though - to design your own programming language, you're going to have to teach yourself a good amount of theory of computing, in order to not design a language that is either impossible to parse or insufficiently expressive to do what you want to do. And if you think learning a programming language is boring, just wait till you get to finite state automata, context-free grammars, and Turing completeness. Writing your own programming language could easily become at least a master's thesis if you make it interesting enough.

I've been at making my own code for a week I've tried to learn other code before and it drove me crazy  

Link to comment
Share on other sites

27 minutes ago, Cheif Operations Director said:

As I stated my coding is based around operations you only need 3 lines of code for a standard guidance program. Not self stabalizing but just the actual guidance program.

Unfortunately that has nothing to do with how difficult it will be for you to write a compiler or interpreter for that language.

27 minutes ago, Cheif Operations Director said:

Also your example is semi-wrong what would be more accurate is saying I want to build my own ford truck out of spare parts but I hate BMW spare parts.

It sounds like you're thinking of the vehicle as the rocket guidance program. That's not the analogy I was making; the vehicle is the new programming language, since that's what you're building first. Making your own programming language is a difficult, deep dive into the programming that you say you hate.

Link to comment
Share on other sites

2 hours ago, HebaruSan said:

Unfortunately that has nothing to do with how difficult it will be for you to write a compiler or interpreter for that language.

It sounds like you're thinking of the vehicle as the rocket guidance program. That's not the analogy I was making; the vehicle is the new programming language, since that's what you're building first. Making your own programming language is a difficult, deep dive into the programming that you say you hate.

Out of this thread I still do not know where to even begin writing a compiler or interpreter. Where do I find this? How does it work?

Link to comment
Share on other sites

5 minutes ago, Cheif Operations Director said:

Out of this thread I still do not know where to even begin writing a compiler or interpreter. Where do I find this? How does it work?

I linked a book on the first page of the thread that answers pretty much any question you could have on the topic. Reading it won't be easy, but neither is writing a compiler.

Link to comment
Share on other sites

4 hours ago, Mad Rocket Scientist said:

I think this is a bit unfair, they've never said that they know everything about programming. In fact they're said that they don't know very much, and are asking for help with, admittedly, something that is harder than the original project.

OP has not a lot of knowledge of the subject but has exhibited large amount of confidence in getting it to work. I don't thing that's unfair assessment. It was not meant as an insult. Everybody falls far the effect, nobody is immune. I've been tinkering with electronics and embedded systems for 15 years and still there are occasions where I think something will be trivial, only to hit a snag somewhere which forces me to go back to the books.

@Cheif Operations Director is English your first language? I believe we might have a problem in communication where you don't recognize some specific words used here as having very specific meanings and then gloss over them. 

Let me try to explain some of them.

This is a piece of code:

const byte engine1 = 5;
const byte engine2 = 6;
const byte engine3 = 7;

void setup() {
  pinMode (engine1, OUTPUT);
  pinMode (engine2, OUTPUT);
  pinMode (engine3, OUTPUT);

  digitalWrite (engine1, HIGH);
  delay (5000);
  digitalWrite (engine2, HIGH);
  delay (5000);
  digitalWrite (engine3, HIGH);
}

void loop() {

}

It is perfectly functional and complete. It is one click away from compiling and working. Programming language used here is heavily based on C++. However, this specific one was written for Arduino. All that this code does is to turn three physical pins on a microcontroller from logical LOW to logical HIGH (from 0 volts to 5 volts, in this case) in sequence, with 5 seconds of delay between each.

If you hooked a microcontroller with this code to adequate electronics, you could turn on three lights, three electric motors, or three rocket motors with this. For solid rocket motors you can find in hobbyist shops (Estes type), you could fire them by hooking physical pins 5, 6 and 7 to gate pins of three N channel MOSFETs that act as switch to turn on electric igniters.

The command (also called function) to turn on a microcontroller pin is digitalWrite, but for it to actually do something, there are quite a few things that have to happen in the background. If you use an existing programming language, you don't need to worry about that. However, if you want to make your own language you will need to not only write that part as well, but have a detailed knowledge and understanding of hardware and software part of the microcontoller you are using.

For example, this is the back end of the digitalWrite function, the stuff that you'd need to write too if you want to go the diy route:

void digitalWrite(uint8_t pin, uint8_t val)
{
        uint8_t timer = digitalPinToTimer(pin);
        uint8_t bit = digitalPinToBitMask(pin);
        uint8_t port = digitalPinToPort(pin);
        volatile uint8_t *out;

        if (port == NOT_A_PIN) return;

        // If the pin that support PWM output, we need to turn it off
        // before doing a digital write.
        if (timer != NOT_ON_TIMER) turnOffPWM(timer);

        out = portOutputRegister(port);

        uint8_t oldSREG = SREG;
        cli();

        if (val == LOW) {
                *out &= ~bit;
        } else {
                *out |= bit;
        }

        SREG = oldSREG;
}

You see? One easy to use and understand line of code suddenly expands into 15 lines that are not quite as easy to understand.

If you want to write this part yourself as well, you better start learning about hardware timers, interrupts, direct port manipulation, bitwise operations etc...

If you look at the code above, you'll notice there are five other functions in this one function. Each of them is another block of code you'll need to write. It can go all the way down until you get to bottom of the rabbit hole and machine code. How deep are you willing to go?

Link to comment
Share on other sites

59 minutes ago, Cheif Operations Director said:

Out of this thread I still do not know where to even begin writing a compiler or interpreter. Where do I find this? How does it work?

I don't really know enough enough about it to give you any good guidance, but some searching came up with this tutorial, which includes a complete portable lisp interpreter for python. It's only about 400 lines too:

http://norvig.com/lispy.html

Also this, which is a complete lexer, parser, and interpreter:

https://github.com/marciok/Mu#writing-your-own-programming-language

Also there's this, which is more of a meta-resource:

https://tomassetti.me/resources-create-programming-languages/

Basically, your first task will be to decide what language you want to write the program in, and then figure out what features you want it to have. Then just implement them as described above, although it looks to me like for a very small set of features, there will be zero benefit to making our own language over just making functions.

EDIT: Oh, and for ways to make learning programming easier, consider scratch. It's how I got started with programming before I graduated to python. It's a surprisingly powerful visual programming language that removes a bunch of the hardest to learn overhead for programming.

Edited by Mad Rocket Scientist
Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...