Jump to content

Recommended Posts

I have zero experience with Python.

I am not a programmer, but I have 8 years of experience working a job where my main task became to design and develop embedded systems for in-house use. I build various electronic and mechanical solutions for our company, including things that could be called robotics.

Edited by Shpaget
Link to comment
Share on other sites

1 hour ago, Cheif Operations Director said:

@Shpaget what is the best IDE for c++?

Ask 20 people and you'll get 25 answers.

Visual Studio, Atmel Studio, Eclipse, Sublime Text...

When I started playing with microcontrollers I picked up Arduino Uno, and got comfortable with Arduino IDE. Soon I made myself a nice stockpile of all sorts of both Arduino boards and individual microcontrollers, big and small and for 90% of my needs Arduino IDE is good enough.

Why? Because it does the job, not that I would mind some of those very nice features you find in big boy IDEs.

33 minutes ago, Cheif Operations Director said:

Can I order python to run a c++ file? I mean if I tell python to open a .exe c++ file it could run right? I think I may take a shot a c++ for the robotics end of things and then use python for the software part. Idk it is just an idea since python robotics seems to be lacking

I'd say that making two systems work together would be much more trouble than just deciding on one and do everything with it.

Sure, you can analyze the data with Python (once you offload it from your rocket), but the rocket itself should be perfectly capable running just C.

Link to comment
Share on other sites

17 hours ago, Shpaget said:

Ask 20 people and you'll get 25 answers.

Visual Studio, Atmel Studio, Eclipse, Sublime Text...

When I started playing with microcontrollers I picked up Arduino Uno, and got comfortable with Arduino IDE. Soon I made myself a nice stockpile of all sorts of both Arduino boards and individual microcontrollers, big and small and for 90% of my needs Arduino IDE is good enough.

Why? Because it does the job, not that I would mind some of those very nice features you find in big boy IDEs.

I'd say that making two systems work together would be much more trouble than just deciding on one and do everything with it.

Sure, you can analyze the data with Python (once you offload it from your rocket), but the rocket itself should be perfectly capable running just C.

Ok thanks

Link to comment
Share on other sites

On 8/10/2019 at 12:18 AM, Cheif Operations Director said:

Can I order python to run a c++ file? I mean if I tell python to open a .exe c++ file it could run right? I think I may take a shot a c++ for the robotics end of things and then use python for the software part. Idk it is just an idea since python robotics seems to be lacking

looks like the tried and true method is os.system("a.out") while the new hotness is subprocess.run("a.out", "-parameters").

If you are having trouble with python, I'd think twice before trying to tackle C++.  It seems that C++ started with C, then added every possible feature they could to the language.  Expect to need to know a lot more about the language to do relatively simple things than you ever needed to know about python.

I was trying to do exactly that: take an existing C++ library and get it to run in Python.  Of course to do this I had to finagle the wrapper functions to deal with the data the way python expects, so it took just a little C++.  One of the gotchas was that none of the "learn C++ books" I found at the local library mentioned that the method I was using to create objects (simply typed from "Learn C++ in FIXNUM days") was putting the object (but not the pointer) on the stack (where it would quickly be destroyed), but I needed to put it on the heap instead (I should have known this from simple C programming, but my C was pretty rusty by then).  Even this little thing took about a week of debugging (since I really didn't understand the issue).

Link to comment
Share on other sites

5 minutes ago, wumpus said:

looks like the tried and true method is os.system("a.out") while the new hotness is subprocess.run("a.out", "-parameters").

If you are having trouble with python, I'd think twice before trying to tackle C++.  It seems that C++ started with C, then added every possible feature they could to the language.  Expect to need to know a lot more about the language to do relatively simple things than you ever needed to know about python.

I was trying to do exactly that: take an existing C++ library and get it to run in Python.  Of course to do this I had to finagle the wrapper functions to deal with the data the way python expects, so it took just a little C++.  One of the gotchas was that none of the "learn C++ books" I found at the local library mentioned that the method I was using to create objects (simply typed from "Learn C++ in FIXNUM days") was putting the object (but not the pointer) on the stack (where it would quickly be destroyed), but I needed to put it on the heap instead (I should have known this from simple C programming, but my C was pretty rusty by then).  Even this little thing took about a week of debugging (since I really didn't understand the issue).

I only thought about it because I found nothing online about getting python to work for robotics/my rocket.

I know it will not work, but I think I may be able to get some success with my current code I just need to replace my print’s to interface with a pin in a computer to turn a servo etc etc, 

My thought was hook up the code for servos and hardware and run the c++ file with that code hike the actual guidance system is in python

10 minutes ago, wumpus said:

It seems that C++ started with C, then added every possible feature they could to the language.

I mean it is called ++. Not just + but ++ waiting for C+++ ;) 

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

  • 3 weeks later...

Basically I want a function called pinoutputs():
It will then take a bunch of true statements that are set when each loop of the code runs, fire the appropriate pins and then clear the vars back to false to allow the code to resume. Now the problem here is that I need to access these variables which are all local vars outside of the function. I can use global vars, but I have about 40 pins planned (sort of) either way for each function that access's these pins I need to list all global vars, that means for EVERY FUNCTION that uses these pins which is +8 RIGHT NOW I need a block of 40 lines of code to access the corresponding pins, and that is just for the pins. This is completely outrages in terms of code that needs to be run, there has to be a better way than this. Is there?

what if I just put all the vars at the beginning? on the 0 indent would this still count as a local variable? 

 

Also how hard is it to change the syntax of python via a library? I know this is preposterous but humor me, if I wanted to add a new syntax function (like if or while etc) 

and it was "ksptwoshouldbegood" that is the syntax I want for whatever reason, how do I make this a reality?

Link to comment
Share on other sites

10 hours ago, Cheif Operations Director said:

Basically I want a function called pinoutputs(): (...) This is completely outrages in terms of code that needs to be run, there has to be a better way than this. Is there?

Basically the problem you describe is why we have objects, to prevent any of the issues you describe. Search for “objects” and “classes” and firm up your knowledge of that subject.

In addition, whatever solution you came up with, I can state with mathematical certainty that if it requires lots of global variables, it is not a good solution. Get more experience with a few projects, follow along with some books, and see how it’s done.

A few generic statements:

  • Python integrates very well with C, at least the standard (CPython) version. Some of Python’s most relevant libraries are written in C. You could also consider switching to another version of Python called Cython which allows seamless integration. However, if eventually you want to run your code from an Arduino I’d stay away from Cython and look up how it’s done for Micro Python; From what I understand it’s the same kind of mechanism as with regular Python.
  • It really, really, really helps to focus on learning to program in Python first and do some simple projects (scraping the web, automate file-oriented tasks, etc) to gain some general experience in programming, and in learning what are good and bad practices are. After that, get an Adafruit CircuitPython board or a BBC microbit board, for less than $20 you’ll have great fun interfacing with hardware and getting hands on experience.
  • As pointed out, C++ is C with added bells and whistles. While the basics are very similar, the advanced stuff is not (mainly because the main charm of C is its rock-solid simplicity; there is no “advanced stuff” in the language, which doesn’t mean you can’t do advanced stuff with it—an important distinction). Whatever you do to interface with the hardware, do it in C and not C++
Link to comment
Share on other sites

4 minutes ago, Kerbart said:

Basically the problem you describe is why we have objects, to prevent any of the issues you describe. Search for “objects” and “classes” and firm up your knowledge of that subject.

In addition, whatever solution you came up with, I can state with mathematical certainty that if it requires lots of global variables, it is not a good solution. Get more experience with a few projects, follow along with some books, and see how it’s done.

A few generic statements:

  • Python integrates very well with C, at least the standard (CPython) version. Some of Python’s most relevant libraries are written in C. You could also consider switching to another version of Python called Cython which allows seamless integration. However, if eventually you want to run your code from an Arduino I’d stay away from Cython and look up how it’s done for Micro Python; From what I understand it’s the same kind of mechanism as with regular Python.
  • It really, really, really helps to focus on learning to program in Python first and do some simple projects (scraping the web, automate file-oriented tasks, etc) to gain some general experience in programming, and in learning what are good and bad practices are. After that, get an Adafruit CircuitPython board or a BBC microbit board, for less than $20 you’ll have great fun interfacing with hardware and getting hands on experience.
  • As pointed out, C++ is C with added bells and whistles. While the basics are very similar, the advanced stuff is not (mainly because the main charm of C is its rock-solid simplicity; there is no “advanced stuff” in the language, which doesn’t mean you can’t do advanced stuff with it—an important distinction). Whatever you do to interface with the hardware, do it in C and not C++

Ok noted, I was looking very hard at the adafruit stuff, Now how do I make my own python library? Including with my own syntax like what I posted for my last post? I read what Shpraget said and I did not think it was related. Did I miss read it?

Link to comment
Share on other sites

On ‎8‎/‎30‎/‎2019 at 1:39 PM, Kerbart said:

Python integrates very well with C, at least the standard (CPython) version. Some of Python’s most relevant libraries are written in C. You could also consider switching to another version of Python called Cython which allows seamless integration. However, if eventually you want to run your code from an Arduino I’d stay away from Cython and look up how it’s done for Micro Python; From what I understand it’s the same kind of mechanism as with regular Python.

Ok, I am using the Anaconda-> spyder IDE. I am trying to find the library for Circuit python, this is it correct?

https://github.com/adafruit/circuitpython

This is the Micro Python Library Correct?
https://github.com/micropython/micropython

How do I add the library to the spyder IDE? I saw most things being pip anaconda library name, but before I start messing around with admin access and command prompts I want to make sure this is correct. I have both of those repositories in .zip form. Is there a folder I should unzip them too to add them? That would be exponentially less risky I presume so it would be preferable. 

Also my first question still stands on changing syntax highlighting and generally syntax. I have no intention of editing it at least not for awhile. I just wanted to know how that part works. 

If it is the pip anaconda library name thing. How do I actually go about opening that command prompt. It would be my first time doing that

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

Steer clear of pip, you are always better off installing stuff via package manager. Unless you run windows – there you can let pip put stuff into your profile (no admin privileges) and call it a poor man's package management I guess.

You add a library to python project via

  1. installing it into site-packages (Don't mess with site-packages unless you know how to do that properly, which you obviously don't)
  2. put it anywhere and add it to $PYTHONPATH. (Afaik this is what most IDE's do.)
  3. just put it into your project. If your library does not pull  other dependencies, this is the most simple way to do it.

Micropython (upython) is not a library, it's a custom interpreter with trimmed down standard library. Forget about it now, it will only interrest you once you start toying with actual hardware.

As for changing syntax, you don't do that. That essentialy equals to creating a new language, and that is way out of your league. You don't need it anyway, you just need to learn how namespaces work, how to cut logic into functions or encapsulate it in classes. In short, learn the freakin language, which is what several people already pointed you to. 

4 hours ago, Cheif Operations Director said:

If it is the pip anaconda library name thing. How do I actually go about opening that command prompt. It would be my first time doing that

Man, you have a LOT of learning ahead of you. 

Link to comment
Share on other sites

7 hours ago, radonek said:

Steer clear of pip, you are always better off installing stuff via package manager. Unless you run windows – there you can let pip put stuff into your profile (no admin privileges) and call it a poor man's package management I guess.

I am running windows, so I guess pip will work, this assumes pip has all of the files I want. 

 

7 hours ago, radonek said:

You add a library to python project via

  1. installing it into site-packages (Don't mess with site-packages unless you know how to do that properly, which you obviously don't)
  2. put it anywhere and add it to $PYTHONPATH. (Afaik this is what most IDE's do.)
  3. just put it into your project. If your library does not pull  other dependencies, this is the most simple way to do it.

Where are site-packages? If I wanted to create my own library with my own functions (for the sake of argument) how do I do that?

 

7 hours ago, radonek said:

Micropython (upython) is not a library, it's a custom interpreter with trimmed down standard library. Forget about it now, it will only interest you once you start toying with actual hardware.

If I have a program written for python and I want to test it for micropython, how do I go about doing that? My code right now is still "software" but I want to start testing it with either Circuit or Micro python. (Which ever one will support the cheapest but worth while electronics) 

 

7 hours ago, radonek said:

As for changing syntax, you don't do that. That essentialy equals to creating a new language, and that is way out of your league. You don't need it anyway, you just need to learn how namespaces work, how to cut logic into functions or encapsulate it in classes.

I understand this, I have no intention of actually doing it right now. I just want to know the files I would need to edit, AND how to change the syntax highlighting to be something else ( I am not referring to the tools drop down bar) For example if I have the function time.time(), I may want this to be considered highlighted syntax. (For reasons just an example) so how do I do that, that is my question. 

 

7 hours ago, radonek said:

In short, learn the freakin language, which is what several people already pointed you to

I am doing that, I just am trying to figure out how to do more stuff with python's libraries and other peoples libraries. 

 

7 hours ago, radonek said:

Man, you have a LOT of learning ahead of you.

I have used the IPython console, I was referring to the windows command prompt, if that is what you are referring to

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