
Show HN: Program “Greppy”, a 2-wheeled robot, using a new robotics language - tlb
https://yoga.dev/timeshared-robots/
======
pplonski86
Off-topic. I'm thinking about building a game where players are controlling
real robots. The players compete for resources which are randomly distributed
in the land. In the first version of the game it will be on the Earth. This
game can be later used to help colonize Moon and Mars.

Do you know any robots which can be used in such game?

~~~
milgrim
You probably heard of Isotopium: Chernobyl. Interesting concept and a solid
implementation of a similar idea.

[https://youtu.be/TET-xQIgZQE](https://youtu.be/TET-xQIgZQE)

~~~
danvoell
Nope never heard of it. That is amazing.

------
thdrdt
Looks like this is what Bret Victor is promoting for years: a real-time
feedback loop with your code and the outcome.

This would also be very nice for game development as Bret Victor demonstrated
multiple times.

great!

~~~
tlb
I'm greatly inspired by his work. It seems magical for game design.

Game engines like Unity also let you tweak a lot of things interactively, but
more by making those things be assets rather than code. But I never really
liked that style. (For that matter, I don't like CSS being separate from the
page content either.)

So I want Dynamicland for robots.

------
memexy
This is a really great idea

> The compiler extracts anything marked as a parameter into a separate data
> structure, with a link to the location in the source code they came from.
> When the IDE renders the Yoga code, it shows the parameters as sliders.

Turning code into data that can be represented in another way. I guess the
idea is from projectional editors, where the code is projected onto different
representations depending on the context and what the user wants to
accomplish.

Does anyone know of other work along similar lines? Programming the robot is
also cool and I'm curious if this idea can be applied to other types of
programming where a simplified projection of the program can make code more
accessible to non-programmers.

------
sangfroid_bio
How does the differentiable programming implementation work?

~~~
tlb
Yoga is purely functional, so it's possible to use backpropagation to compute
it efficiently.

It actually compiles 2 versions of each function: call them foo and foo.grad.
foo.grad takes the same arguments as foo, and also a gradient for each output
argument. It then computes gradients for each input argument.

The algorithm is simple: traverse the expression tree in the usual order you'd
use for emitting code, and remember the order. Then traverse in reverse order,
propagating gradients as you go.

The tedious bit is writing the gradients for every built-in op. For an
operation like + it's simple: each argument gets the same gradient as the
result:

    
    
      void ExprAdd::backprop(YogaContext const &ctx, GradientExprSet &grads, ExprNode *g)
      {
        grads.addGradient(ctx, args[0], g);
        grads.addGradient(ctx, args[1], g);
      }
    

For something like divide it's a bit grosser:

    
    
      void ExprDiv::backprop(YogaContext const &ctx, GradientExprSet &grads, ExprNode *g)
      {
        // https://en.wikipedia.org/wiki/Quotient_rule
        grads.addGradient(ctx, args[0], ctx.mkExpr<ExprDiv>(g, args[1]));
        grads.addGradient(ctx, args[1], ctx.mkExpr<ExprNeg>(
          ctx.mkExpr<ExprMul>(g,
            ctx.mkExpr<ExprDiv>(
              args[0],
              ctx.mkExpr<ExprPow>(
                args[1],
                ctx.mkExpr<ExprConstDouble>(2.0))))));
      }
    

More at
[https://gitlab.com/umbrellaresearch/yoga2/-/blob/master/jit/...](https://gitlab.com/umbrellaresearch/yoga2/-/blob/master/jit/expr_backprop.cc)
if you're curious.

~~~
sangfroid_bio
Have you considered using an off the shelf differentiable programming
implementation? Or are the requirements for real-time applications too
demanding for existing software?

~~~
tlb
I looked at a few systems but didn't think any of them would work.

The real-time requirement is fairly hard. The robots I work on use a 1 kHz
feedback loop, so it has 1 mS in which to recalculate everything.

Caffe is pretty efficient if you can supply batches of values, but the
overhead is high when running real-time.

~~~
EquallyJust
have you tried torchscript w/ the C++ interface?

~~~
tlb
No. It looks promising. I should try it.

~~~
sangfroid_bio
I think Tensorflow with Swift or Rust bindings may also work.

------
moorage
Okay I'm 100% biased, but this is something I've enjoyed working with as well.
It's made developing a self-balancing greppy super easy :)

------
CodeWriter23
The robot’s name seems to imply it can find specific items in a cluttered
closet. Is that the case?

~~~
moorage
That's what the googley eyes are for! Ideally, this isn't the only "greppy"
design (:

------
ilovefood
This is amazing. I love the concept of remote programmable robotics and the
real-time feedback of the controls is a great idea. I think this is the way
forward, I wasted countless hours trying to fiddle with code only to see the
robot failing on the edge of breaking apart. Any indications on how to build
my own Greppy and the whole infrastructure behind it? :)

~~~
moorage
Curious about your use case! Do you want to setup your own warehouse for you
and your own friends? Or use the existing Yoga warehouse and get your own
personal Greppy on it that only a subset of people can share? Or something
else?

~~~
ilovefood
I would love to understand how the whole thing works actually and how it can
be configured/updated. Surely this approach can be adapted to smaller robots?
It's more of a curiosity question since I love to tinker with robots and am
looking for a good way to make them better. Apart from didactic purposes I
don't have a really specific use case yet. :)

~~~
moorage
Yoga is a language as well as an environment, so if the robot has an open
controller where a compiled program can be installed, it will work!

What robot did you want to tinker with

------
gumby
By the way Trevor is a founder of YC

------
zubairq
I love this creepy robot!

