Jump to content

Recommended Posts

#Constant Variables

T1 = 2

a = 0

#---------------Import Section
import time
import timeit
#---------------Class Section
class Calculator:
    def addition (x,y):
        add = x+y
        print(add)
    def subtraction (x,y):
        sub = x-y
        print(sub)
    def multiplication (x,y):
        mult = x*y
        print(mult)
    def division (x,y):
        div = x/y
        print(div)

#--------------Functions
#---Math
def add1(x,y):
    Calculator.addition(x,y)

def sub1(x,y):
    Calculator.subtraction(x,y)

def mutl(x,y):
    Calculator.multiplication(x,y)

def div(x,y):
    Calculator.division(x,y)
    
def repeatingchecks(b):
     while time.clock()<b:
        voltage4(0)
        voltage3(0)
        voltage2(0)
        voltage1(0)
        
    
#---Engine Control
    
def RME(A1):
    Temp

#---------------Flight Code Section Secondary

a = 0
def voltage1(b1):
    global c1
    c1 = b1 + 0
    if c1 > a:
        print("Activate Response 1") 
        print("The Value of Voltage +", c1)
        #Open RCS Valve Code
    elif c1==0:
        print("No Excessive Aerodynamic Forces sensor1")
        pass

#---Sensor 2

a = 0
def voltage2(b2):
    global c2
    c2 = b2 + 0
    if c2 > a:
        print("Activate Response 2") 
        print("The Value of Voltage +", c2)
        #Open RCS Valve Code
    elif c2==0:
        print("No Excessive Aerodynamic Forces sensor2")
        pass


#---Sensor 3

a = 0
def voltage3(b3):
    global c3
    c3 = b3 + 0
    if c3 > a:
        print("Activate Response 3") 
        print("The Value of Voltage +", c3)
        #Open RCS Valve Code
    elif c3==0:
        print("No Excessive Aerodynamic Forces sensor3")
        pass


#---Sensor 4

a = 0
def voltage4(b4):
    global c4
    c4 = b4 + 0
    if c4 > a:
        print("Activate Response 4") 
        print("The Value of Voltage +", c4)
        #Open RCS Valve Code
    elif c4==0:
        print("No Excessive Aerodynamic Forces sensor4")
        pass

#---------------Primary Code Section


repeatingchecks(2)
TT = 1
time.sleep (TT)
print("Hello World")

7 minutes ago, HebaruSan said:

But if you really think something that simple could work, then you don't need a computer. You could just connect the wire from the sensor directly to the motor. The point of writing software is to do something complicated.

I have more things that will be programs then that.

The latest version this works as intended is Python 3.2.8. 

Does anyone have an alternative to time.clock()   ?

 

Link to comment
Share on other sites

19 minutes ago, Cheif Operations Director said:

     while time.clock()<b:

The latest version this works as intended is Python 3.2.8. 

Does anyone have an alternative to time.clock()   ?

You could try (oops hit shift-enter and it posted) threads, but they're notoriously difficult to work with without causing lots of bugs:

https://www.geeksforgeeks.org/timer-objects-python/

Edited by HebaruSan
Link to comment
Share on other sites

https://www.ebay.com/itm/Freenove-Ultrasonic-Starter-Kit-for-Arduino-Beginner-Uno-R3-Detailed-Tutorial/301995038239?hash=item46504e961f:g:uOMAAOSwvg9Xb8Lf&amp;enc=AQADAAAB4KX%2FKt4E1xf3SDqEdBclaYYDETDqRiEb7BnZqYQ3hAMWauisZpf%2B8hpFnX74UkIA9GH41KdLcqPI4pB6Z0QPoJ2EWekg6tO1355yXyp%2BBDqPqkz0WfNKZuPcQ6aGO00i4F9PjY5vvIumWosEGgED0%2BwT8uJ778b6G0ZarY9n8RlZaXIq2M0%2BHdp%2BWj%2F87nTrMraAHmL64LKA%2BDdvZb%2F7Ju1Toaj7RUAQVABpmPSg5WNh8G2Sv4vHMYmakV5idxXSPOrOiYx4fUD4T2EhDiYnt%2BIwiYqDBt4ducQ4UA7MrbGwOG0qIUJlPEbrwKk%2FLlkEKr3SYaN7lSCxbkGkdA2uh1EPRrkkUPntcRc5rocCVMr7iUlVoXHwgBNd5%2F6x868yg0sDahyQZJrBcejlUO45Urz86ZXQJjtDjVnvsm70RiAByCyXMeMM15k55J1VzrvMxYDLaAfkKm32ErBH1KlG4DEvfqIr2en5A6fpwRtQxAx101vFinzojd%2FhyWtDMWl83kTh2X22O1C%2BzyLxlMuXBMT9zp5UPKtwBd%2BRUpF%2BgeEhlVJeg0xGmL08LpxlTbHJpz6mbObFEpEX3MQjuc8%2FfkK8K6gsAkSBXnTUFgDp2%2BNxTLvWdJhk%2FLvIwYEvqmbDKQ%3D%3D&amp;checksum=301995038239966eb911d59a4e7683dd4560eb571f0d

Get yourself something like this.

In that set you'll have plenty of bits and pieces to keep you occupied and learning for months. The project you are proposing is beyond your level and while I would never try to dissuade you from taking on a project, for you and your skill level it's just not time yet. Start small. Launching a rocket with half baked software will become very time consuming, frustrating and expensive. Learn how to read a potentiometer value, learn how to move a servo motor,  then learn how to move the servo based on the value of the potentiometer.

You are trying to integrate too much stuff too quickly. Learn in steps, and gradually build your project.

Just how big do you expect your final rocket to be? You are talking about cold gas thrusters. That implies large, high pressure tanks and some beefy solenoid valves. Do you have any experience with those?

I still don't understand why you insist on Python. That choice will necessarily lead to a significantly bigger and much more power hungry CPU than needed, leading to more powerful and heavier control mechanisms, which require bigger batteries etc... Soon your rocket will be a one ton missile.

 

Link to comment
Share on other sites

19 minutes ago, Shpaget said:

I still don't understand why you insist on Python.

Let's be frank, the number of clues had by our friend the Cheif [sic] is an integer between -1 and 1, exclusive. There's a 0% chance that the code he's writing right now will end up on any kind of moving object other than possibly a laptop. He needs to learn programming first, and doing that in Python, driven by an end goal that he cares about, is far from the worst learning environment he could ask for.

Link to comment
Share on other sites

30 minutes ago, Shpaget said:

I still don't understand why you insist on Python. That choice will necessarily lead to a significantly bigger and much more power hungry CPU than needed, leading to more powerful and heavier control mechanisms, which require bigger batteries etc... Soon your rocket will be a one ton missile.

I didn’t realize how cutting edge the model rocket world is. A circuit board of 3g and 36x18mm is considered “huge” and will lead to a one ton missile? Assuming an Ardino is only 1g, that 2g difference matters that much?!

Link to comment
Share on other sites

59 minutes ago, Shpaget said:

https://www.ebay.com/itm/Freenove-Ultrasonic-Starter-Kit-for-Arduino-Beginner-Uno-R3-Detailed-Tutorial/301995038239?hash=item46504e961f:g:uOMAAOSwvg9Xb8Lf&amp;enc=AQADAAAB4KX%2FKt4E1xf3SDqEdBclaYYDETDqRiEb7BnZqYQ3hAMWauisZpf%2B8hpFnX74UkIA9GH41KdLcqPI4pB6Z0QPoJ2EWekg6tO1355yXyp%2BBDqPqkz0WfNKZuPcQ6aGO00i4F9PjY5vvIumWosEGgED0%2BwT8uJ778b6G0ZarY9n8RlZaXIq2M0%2BHdp%2BWj%2F87nTrMraAHmL64LKA%2BDdvZb%2F7Ju1Toaj7RUAQVABpmPSg5WNh8G2Sv4vHMYmakV5idxXSPOrOiYx4fUD4T2EhDiYnt%2BIwiYqDBt4ducQ4UA7MrbGwOG0qIUJlPEbrwKk%2FLlkEKr3SYaN7lSCxbkGkdA2uh1EPRrkkUPntcRc5rocCVMr7iUlVoXHwgBNd5%2F6x868yg0sDahyQZJrBcejlUO45Urz86ZXQJjtDjVnvsm70RiAByCyXMeMM15k55J1VzrvMxYDLaAfkKm32ErBH1KlG4DEvfqIr2en5A6fpwRtQxAx101vFinzojd%2FhyWtDMWl83kTh2X22O1C%2BzyLxlMuXBMT9zp5UPKtwBd%2BRUpF%2BgeEhlVJeg0xGmL08LpxlTbHJpz6mbObFEpEX3MQjuc8%2FfkK8K6gsAkSBXnTUFgDp2%2BNxTLvWdJhk%2FLvIwYEvqmbDKQ%3D%3D&amp;checksum=301995038239966eb911d59a4e7683dd4560eb571f0d

Get yourself something like this.

In that set you'll have plenty of bits and pieces to keep you occupied and learning for months. The project you are proposing is beyond your level and while I would never try to dissuade you from taking on a project, for you and your skill level it's just not time yet. Start small. Launching a rocket with half baked software will become very time consuming, frustrating and expensive. Learn how to read a potentiometer value, learn how to move a servo motor,  then learn how to move the servo based on the value of the potentiometer.

You are trying to integrate too much stuff too quickly. Learn in steps, and gradually build your project.

Just how big do you expect your final rocket to be? You are talking about cold gas thrusters. That implies large, high pressure tanks and some beefy solenoid valves. Do you have any experience with those?

I still don't understand why you insist on Python. That choice will necessarily lead to a significantly bigger and much more power hungry CPU than needed, leading to more powerful and heavier control mechanisms, which require bigger batteries etc... Soon your rocket will be a one ton missile. 

 

A one ton guided missile :) lol. In all seriousness I will try to use some of those compressed air canisters you use for dusting computers. Obviously not those specifically but something like that. Something in Principle similar to this:

 

 

 

To begin with the flight of my rocket will first look something like the one below but just have a gravity turn and be bigger.

 

 

 

 

 

And to answer your question the reason im not learning C yet is because many people have told me that Python is easier to learn. Furthermore I do not know anybody in person who can code in C but I do know people who can code in Python.

 

46 minutes ago, HebaruSan said:

Let's be frank, the number of clues had by our friend the Cheif [sic] is an integer between -1 and 1, exclusive. There's a 0% chance that the code he's writing right now will end up on any kind of moving object other than possibly a laptop. He needs to learn programming first, and doing that in Python, driven by an end goal that he cares about, is far from the worst learning environment he could ask for.

Part of the reason 

Quick note: Im thinking and doing research on it now on weather using 3D printed parts may be cheaper, stronger, and easier to use. Im still looking into it.

Link to comment
Share on other sites

8 hours ago, Kerbart said:

I didn’t realize how cutting edge the model rocket world is. A circuit board of 3g and 36x18mm is considered “huge” and will lead to a one ton missile? Assuming an Ardino is only 1g, that 2g difference matters that much?!

I'll admit I had something like RPi in mind mind when writing this, since it was mentioned earlier in the thread.

However, while my 1 ton remark is perhaps a bit exaggerated for effect, I do believe it in the correct order of magnitude, if one would try to design something as described here using standard model rocketry engines. Keep in mind that those things have abysmal ISP compared to real things.

Link to comment
Share on other sites

10 hours ago, Cheif Operations Director said:

And to answer your question the reason im not learning C yet is because many people have told me that Python is easier to learn. Furthermore I do not know anybody in person who can code in C but I do know people who can code in Python.

I think people get too hung up on choosing a language and neglect just learning programming sometimes. I learned C as my first language, without knowing anyone in person who could even program. I'm quite glad I did as it's made it easy to pickup many other languages since. I don't think python is that much easier to learn, you just have a different set of pitfalls compared to C.

Link to comment
Share on other sites

10 hours ago, Flibble said:

I think people get too hung up on choosing a language and neglect just learning programming sometimes. I learned C as my first language, without knowing anyone in person who could even program. I'm quite glad I did as it's made it easy to pickup many other languages since. I don't think python is that much easier to learn, you just have a different set of pitfalls compared to C.

Yes and no. As a first language Python is great because there aren’t many pitfalls for starters; the most common ones are basically of the “don’t do it the way you’re used to in C/Java/other curly braces language” but if that knowledge is not there there’s nothing to avoid.

Python’s avoidance of system related issues (memory allocation, pointer arithmetic) is of course not beneficial if the goal is to learn about computers and how they’re programmed. And C is hard to beat for its bear-metal performance, albeit with the risk if focus on code efficiency instead of efficient algorithms,

For someone with no affinity to programming I think it’s easier to start with Python, and once the concepts of “variables” and “functions” have grown roots it will be a lot easier to learn C

40 minutes ago, Cheif Operations Director said:

Ok heres what going to happen. Im going to learn python to an intermediate level. If it does not do what I want to which seems likely I will learn C. Which IDE is best for learning C

No contest.Visual Studio Code, these days. Free, powerful, and you’re able to use it on any machine, with practically any language.

Link to comment
Share on other sites

Having briefly followed this thread, here's some advice I'd like to give:

1) Focus on learning the language first. I think you're doing that.

2) Write some aeronatics-related code. For instance, write a script that simulates a rocket launch in .05s intervals (or any duration really). You can use data from KSP, and see how your model stacks up against "reality" - and implementing KSP's atmo model will be a good exercise

3) Get the kRPC mod and write software to control a KSP rocket through a Python script

That will keep you busy for a while, learning lots of skills that are applicable for what you want to achieve.

 

You can go to coder.com to use an online version of VSCode to get started.

Link to comment
Share on other sites

1 minute ago, Kerbart said:

Having briefly followed this thread, here's some advice I'd like to give:

1) Focus on learning the language first. I think you're doing that.

2) Write some aeronatics-related code. For instance, write a script that simulates a rocket launch in .05s intervals (or any duration really). You can use data from KSP, and see how your model stacks up against "reality" - and implementing KSP's atmo model will be a good exercise

3) Get the kRPC mod and write software to control a KSP rocket through a Python script

That will keep you busy for a while, learning lots of skills that are applicable for what you want to achieve.

 

You can go to coder.com to use an online version of VSCode to get started.

Ok cool. Out of curiosity do you know if this is a way to do 

 "time.clock()<b" after python 3.2? That this did in python 2 was have a clock counting infinitely until it was greater than the b value then it stopped. This way I had a de facto timer.

Link to comment
Share on other sites

2 minutes ago, Cheif Operations Director said:

Ok cool. Out of curiosity do you know if this is a way to do 

 "time.clock()<b" after python 3.2? That this did in python 2 was have a clock counting infinitely until it was greater than the b value then it stopped. This way I had a de facto timer.

It depends on what you want to achieve.

I think this is what you're looking for, in this case in a loop that roughly runs 10x per second:
 

import time

while True:
    # do things
    time.sleep(0.10)

The advantage is that your code will "go to sleep" for the amount of time specified, instead of running a loop thousands of time checking the time (and eating up processor capacity). You'll need some kind of break statement to escape the loop, at one point. Or change the while clause.

Link to comment
Share on other sites

1 minute ago, Kerbart said:

It depends on what you want to achieve.

I think this is what you're looking for, in this case in a loop that roughly runs 10x per second:
 


import time

while True:
    # do things
    time.sleep(0.10)

The advantage is that your code will "go to sleep" for the amount of time specified, instead of running a loop thousands of time checking the time (and eating up processor capacity). You'll need some kind of break statement to escape the loop, at one point. Or change the while clause.

I should be more specific

 

def function1(b)

while time.clock()<b:

    print("Hello World")

 

function1(2)

 

#this means that this will print hello world until time is in excess of 2 seconds. In python two I had a bug where I could call the function again after the first call but it would not do anything I suspect (on a conjecture)  it was because of some sort of memory problem.  

 

 

Link to comment
Share on other sites

4 minutes ago, Kerbart said:

It depends on what you want to achieve.

I think this is what you're looking for, in this case in a loop that roughly runs 10x per second:
 


import time

while True:
    # do things
    time.sleep(0.10)

The advantage is that your code will "go to sleep" for the amount of time specified, instead of running a loop thousands of time checking the time (and eating up processor capacity). You'll need some kind of break statement to escape the loop, at one point. Or change the while clause.

I've done that before not a problem I could always do

while time.clock()<b:

    print("Hello World")

    time.sleep(0.10)

Just now, HebaruSan said:

Or if the goal is to limit how many times the loop runs, you can use a for loop:


import time

for step in range(100):
    # do things
    time.sleep(0.10)

Let me run it

Link to comment
Share on other sites

Why would you want to block your code? If you don't need to do anything, just don't do it yet, but don't tell the program to grind to a halt.

Sure, if you need to do one thing in regular intervals, it will do, but if you want more than one thing happening in different intervals the code will become entirely unwieldy.

It's bad practice.

Link to comment
Share on other sites

Just now, Shpaget said:

Why would you want to block your code? If you don't need to do anything, just don't do it yet, but don't tell the program to grind to a halt.

Sure, if you need to do one thing in regular intervals, it will do, but if you want more than one thing happening in different intervals the code will become entirely unwieldy.

It's bad practice.

Because I may only need the code to check its sensors for 2 seconds

Link to comment
Share on other sites

3 minutes ago, HebaruSan said:

Or if the goal is to limit how many times the loop runs, you can use a for loop:


import time

for step in range(100):
    # do things
    time.sleep(0.10)

First I can not call this again I need a variable in the range does something x times and not for x seconds

1 minute ago, HebaruSan said:

For that matter, variable names like "b1" and "c2" are also bad practice. Programming languages allow long variable names so you can use them to express what each variable is for.

Simplification plus it was a repeat of the code for the same sensor I may change it to input1 input 2 etc

6 minutes ago, HebaruSan said:

Or if the goal is to limit how many times the loop runs, you can use a for loop:


import time

for step in range(100):
    # do things
    time.sleep(0.10)

Let me try making it a function with a variable

Link to comment
Share on other sites

import time

def generic_check(check_function, duration=2.0, interval=0.5)
    start_time = time.time()
    while time.time() < start_time + duration:
        check_function()
        time.sleep(interval)

def check_my_sensors_yo():
    ...

# check sensors for 3 seconds
generic_check(check_my_sensors_yo, 3.0, .1)


 

Link to comment
Share on other sites

1 minute ago, Kerbart said:

import time

def generic_check(check_function, duration=2.0, interval=0.5)
    start_time = time.time()
    while time.time() < start_time + duration:
        check_function()
        time.sleep(interval)

def check_my_sensors_yo():
    ...

# check sensors for 3 seconds
generic_check(check_my_sensors_yo, 3.0, .1)


 

Let me try it

3 minutes ago, Kerbart said:

import time

def generic_check(check_function, duration=2.0, interval=0.5)
    start_time = time.time()
    while time.time() < start_time + duration:
        check_function()
        time.sleep(interval)

def check_my_sensors_yo():
    ...

# check sensors for 3 seconds
generic_check(check_my_sensors_yo, 3.0, .1)


 

Invalid Syntax

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...