View Full Version : Programming in Python and Explaination of Programming
roboxking
31-12-2007, 02:16
Our team has decided to use Python for programming, instead of C. Does anyone know how to do that. I also need a general explanation of how programming works in general. This is our first year in FRC, and in FVC (now FTC) all we did was use EasyC, so how programming worked wasn't an issue. Thanks for the help anyone can give me.
The FRC controllers are written in straight ANSI C. It is not C++. We don't do objects.
Inside the controller is a ton of code that has the framework where you hang your custom code for autonomous and a routine that you modify to do your normal hands on control. A lot of the work is setup for you already in terms of conditioning I/O points and setting up interrupt handlers, etc.
Considering that IFI has done 90% of the code for you it is impractical and unnecessary to consider another language.
This competition reflects real life. Just like a real life project the language may have been chosen before you arrived for any of a million reasons.
Besides, professional programmers are adept at:
a - picking the right tool for the job
or
b - using the tools that have been chosen when not given the choice.
BTW - If you used a coprocessor like the gumstick you could eventually get to the point of building support for python but that project isn't for a newbie programmer. You only have 6 weeks to finish this whole robot project.
Good Luck !!
Robostang 548
31-12-2007, 11:59
My team will be programming our 2008 robot in python. We are trying to get an off board coprocessor working. Team 245 did a workshop on using a coprocessor at last years kickoff in Novi Mi. They did their coprocessor in python and for a time, they had their code on their website. I don't know if team 245 will be using a coprocessor this year or if they will be giving support to their code because their two main programmers who wrote the code graduated last year. In terms of getting python to work on the RC alone, I cant help you much there. But there is rumor that the new controller that will be available in the 09 season will have support for multiple languages.
-Don
tajmorton
31-12-2007, 13:02
I also need a general explanation of how programming works in general.
Check out the guide that Team 1540 (The Flaming Chickens) put together: http://www.team1540.org/programming.
It's a great overview of how the default code is setup, and how to modify it.
[Assuming that you are going to use C...otherwise please ignore :)]
As for learning C, if you already know some Python (or another language), I don't think the jump will be too huge. A lot of being a programmer is the way you think, not the syntax you write (for me, anyway). That said, you might want to dip your toes in the C-sea before you have to write embedded code on a deadline.
On Windows, I've used the Dev-C++ (http://www.bloodshed.net/devcpp.html) IDE (uses a GCC compiler). Despite its name, it can be used for both C and C++ programming. Look up some C tutorials on the web and try writing some simple programs (something that reads a file and prints it on the screen, something that computes the area of a circle from its radius, something that computes the hypotenuse of a right triangle, etc)--just some simple stuff to learn the syntax. I can't really recommend and C tutorials, but a quick google brought up this this one (http://www.physics.drexel.edu/courses/CompPhys/General/C_basics/c_tutorial.html) (and many others).
- Taj
slavik262
31-12-2007, 20:35
A lot of being a programmer is the way you think, not the syntax you write (for me, anyway). That said, you might want to dip your toes in the C-sea before you have to write embedded code on a deadline.
I would definately agree. Once you get the hang of programming itself, learning syntax really isn't as hard as you would think. I would give C a try.
Is EasyC going to be available for FRC again? If so, problem (partially) solved.
not meant as a reply, just some thoughts:
It interesting to see what real speed advantage the coprocessor would give. Python is generally 16x slower than native, so it would seem that (if true) the Python code would run more slowly on a 400 mhz computer than native c on the 40 mhz (i think) PIC mcu. But it might be worthwhile just using C on the coprocessor, which may or may not be against the purpose of a coprocessor. I think python would be worthwhile for extra control speed (using heavily optimized code, or more likely, native imported code), ease of development (the mcc18 C is not exactly ANSI C, so it would be generally easier to use a higher layer of abstraction instead of dodging all the pitfalls and differences; though it may take some work to setup), and portability of code (we could use a straight cvs/svn/bazaar rep to manage the code which is generally more modular and clean-cut than the C code). Other than that, its way easier to get new programmers in the team learn python than C (well, depends on how thoroughly they think of a problem; if they could live in abstraction, python is easy); it would generally take a day or two to pickup the python syntax (after the general compsci aspect is explained) vs a week for C (which would also require a thorough knowledge of the PIC18 mcu before any programming). Of course, this is after its all setup. And lastly, python is new and cool and stuff, along with linux(not so new, but still cool and stuff).
So those were our reason for trying the python/coprocessor technique.
I made an error on the previous post, calculating that python would be slower than the frc controller, forgetting that a 40mhz clock allows the FRC controller to run at 10mips (million instructions per second). So it will be faster with python, but not as fast as using C on the coprocessor (which would be an order of magnitude faster).
Another question: where can we find sample code in Python (adambots reps are down). Thanks.
bear24rw
02-01-2008, 00:10
Even if it is alot faster to do calculations on a co processor, how fast can you pipe it back and forth between the two.. 115200kbs at most
" The ACS communicates over serial using the
programming port on the IFI controller. During
normal operation, the IFI and the coprocessor
exchange data once every 26.2 ms, alternating
sending and receiving as the IFI receives new data.
" from Adambots kickoff presentation (http://www.chiefdelphi.com/media/papers/1900?)
well, that seems a bit slow (38 hertz), but i guess the program can be tweaked to go faster?
Guy Davidson
02-01-2008, 01:48
38hz comes from the limitation on the IFI RC. The IFI only recieves new data from the OI every 26.6ms as well as updates pwms, unless I'm mistaken, and those are the points where their code has the IFI RC send the data over.
I know its not the most reliable source, but according to IFI:
"Digital Input Frequency: 50 KHz (typical)"
and
"Serial Ports| TTL Serial (115Kb) and
RS232 Program (115Kb)"
(http://www.ifirobotics.com/rc.shtml)
so it looks like it could go at least some kilohertz there.
roboxking
02-01-2008, 02:29
Thanks for all the information (and quick response) But now, I'm asking if anyone who has a [working] python code for an FRC robot? We need to see how one works, and etc. Thanks
jtdowney
02-01-2008, 08:28
I have seen the code for AdamBots (245) co-processor solution (http://www.adambots.com/index.php?title=Co-Processor) which uses Python. However as hdanak pointed out their bazaar repositories are not responding. You might try contacting them and seeing if they'd be willing to share the code with you.
Does anyone have a cached version of the code (all or in part)? Thanks in advance.
jtdowney
03-01-2008, 05:12
I have a copy of their code on my home machine. I am still at my parents on vacation right now but I'll be back at Purdue for kickoff and can get it to anyone who wants it.
jtdowney
04-01-2008, 13:05
Since their repository is down I've attached what I had on my computer. Please note I didn't write this and all credit goes to AdamBots. However since it is under the GPL, I am within my rights to redistribute the code.
Thanks a lot for the code.
roboxking
04-01-2008, 22:39
Yes, we at Team 2584 thank you!
techwizrd
07-01-2008, 00:05
Our team has decided to use Python for programming, instead of C. Does anyone know how to do that. I also need a general explanation of how programming works in general. This is our first year in FRC, and in FVC (now FTC) all we did was use EasyC, so how programming worked wasn't an issue. Thanks for the help anyone can give me.
Sadly, our team wants to use C too. I personally suggest, being an experienced Python programmer (whatever that's worth :P ), using CPython to write the code. You can import the header files and write the code with Python syntax. If I am correct, you'll get nice compiled code at the end, that theoretically should work. I personally am not very experienced with CPython, as I do not normally need to write C-like code with toolkits like PyGTK out.
jtdowney
07-01-2008, 08:14
Sadly, our team wants to use C too. I personally suggest, being an experienced Python programmer (whatever that's worth :P ), using CPython to write the code. You can import the header files and write the code with Python syntax. If I am correct, you'll get nice compiled code at the end, that theoretically should work. I personally am not very experienced with CPython, as I do not normally need to write C-like code with toolkits like PyGTK out.
CPython is just the name of the standard Python interpreter (Just as JPython is the interpreter written in Java). It does not mean you can produce C code from your Python code.
Sadly, our team wants to use C too. I personally suggest, being an experienced Python programmer (whatever that's worth :P ), using CPython to write the code. You can import the header files and write the code with Python syntax. If I am correct, you'll get nice compiled code at the end, that theoretically should work. I personally am not very experienced with CPython, as I do not normally need to write C-like code with toolkits like PyGTK out.
I think that you are referring to Pyrex or Psyco. But remember, when your talking about compiled code, you mean compiled for a PC. Writing C on the PICmicro is not the same C in comparison to that used on a pc (different compiler, different libraries). Something written for a PC won't just run on a PIC.
However, I did find this Python to PIC assembly translator : http://pyastra.sourceforge.net/
It should run closer to native speed than an interpreter, but its not all that efficient, even if it doesn't use an interpreter.
By the way, we have decided on using microchip C for our robot, mostly because this year's competition is basically an RC race (even in Autonomous --hybrid-- mode), and partly because we weren't sure enough to allocate sufficient funds (including time) for buying/testing a coprocessor.
EDIT: heres a useful link: http://www.piclist.com/techref/microchip/languages.htm
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.