Coroutines make robot code easy
91–100 of 127 posts
Re: Coroutines make robot code easy
#92"Deep coroutines:" where you can yield from a function called from the coroutine. Lua supports this, but python doesn't (as far as I can tell). Is there a term for this? To the author: you could make the code even cleaner by moving the yield to within the action functions. Though maybe this won't work as well for parallel actions...
I suppose we could make more utilities for running coroutines "in parallel", but I haven't really felt the need. At that point we usually have to worry about exit conditions and it feels natural to just write a loop.
Re: Coroutines make robot code easy
#93"Deep coroutines:" where you can yield from a function called from the coroutine. Lua supports this, but python doesn't (as far as I can tell). Is there a term for this? To the author: you could make the code even cleaner by moving the yield to within the action functions. Though maybe this won't work as well for parallel actions...
def first():
yield 1
yield from second()
yield 4
def second():
yield 2
yield 3
print(list(first())) # collects all the results and prints them
# Output: [1, 2, 3, 4]
But yeah, it doesn't work on a direct function call you have to know it's going to return a generator (or an iterable, like if it returns a list): def something():
yield from something_else()
def something_else():
return [1,2,3,4]Re: Coroutines make robot code easy
#94Earlier quoted context omitted.
The only officially supported languages for the competition are C++, Java, and LabVIEW. When those are your educational options...you stick with Java. (We've now switched to Lua, integrated with the official C++, but it's a lot more work behind the scenes.)
What's the hardware/OS stack you have for the autonomous part? Can you go wild and use unsupported software as long as it fits in the official hardware?
Re: Coroutines make robot code easy
#95People always say that coroutines make code easier to understand, but I've always found normal asynchronous code with callbacks much easier to understand. They're equivalent except that asynchronous callbacks is what actually happens and you have clear control and visibility on how control flow moves.
Re: Coroutines make robot code easy
#96Earlier quoted context omitted.
We learned borland pascal and borland c in high school. Java is perfectly fine.
I went to a university where Java was the main language for most of the basic programming courses I've been making a living coding in Java for 10+ years I'm a strong believer in types etc etc I still don't think Java is a great language to teach programming lol too much pointless boilerplate and abstraction to achieve the simplest things lots of footguns and objectively bad standard practices built into the language…
Re: Coroutines make robot code easy
#97Oddly, the kids I mentored in FIRST loved the command/subsystem framework. I kept trying to convince them to do some procedural code to make things simpler (they had little experience coding, even for high school robotics kids), but command/subsystem was their comfort zone and they didn't want to leave it.
... but not everybody is ready for that step.
Re: Coroutines make robot code easy
#98Earlier quoted context omitted.
The only officially supported languages for the competition are C++, Java, and LabVIEW. When those are your educational options...you stick with Java. (We've now switched to Lua, integrated with the official C++, but it's a lot more work behind the scenes.)
What's the hardware/OS stack you have for the autonomous part? Can you go wild and use unsupported software as long as it fits in the official hardware?
If you're using Java (or C++ or LabVIEW, to a lesser extent), you at least have a hope of posting to a forum and going "Hey, we think our robot should be doing X and it's doing Y, here's our code, any insights?"
If you use and your own custom bindings, you're on your own.
Re: Coroutines make robot code easy
#99If you want to make it easy for high schoolers, just don't use java in the first place...
We learned borland pascal and borland c in high school. Java is perfectly fine.
Java is "fine" in the sense that NBASIC was "fine." There's definite room for improvement in matching the abstraction to the problem domain.
Re: Coroutines make robot code easy
#100Earlier quoted context omitted.
We learned borland pascal and borland c in high school. Java is perfectly fine.
I went to a university where Java was the main language for most of the basic programming courses I've been making a living coding in Java for 10+ years I'm a strong believer in types etc etc I still don't think Java is a great language to teach programming lol too much pointless boilerplate and abstraction to achieve the simplest things lots of footguns and objectively bad standard practices built into the language…
You can write code in it, but in industry almost everything I see is basically a DSL built out of annotations that tries as hard as it can to not involve writing actual Java.
When more of your application is annotations than lines of Java code, the language is probably a bad fit for the problem domain.