BB.NSK.Drive (bb_nsk v0.1.2)

Copy Markdown View Source

Where a pilot's intentions reach the balance controller.

A BB.NSK.Message.Drive on [:drive] — a throttle and a turn rate. That message's moduledoc explains why the throttle is not a velocity, which is the thing most worth knowing before using this.

Pubsub rather than BB.Command, because a command is a spawned process with a goal and a result, meant for things like arming. This is a stream at twenty hertz that is stale the moment the next one arrives.

Letting go stops it

Both axes settle rather than latch. The throttle returns to zero, the robot leans back to its balance point and rolls to a stop; the turn rate returns to zero and the heading loop holds wherever it got to.

And a command is only good for drive_timeout — see the balance controller — so a phone that walks out of wifi range stops the robot rather than leaving it driving on its last instruction.

Summary

Functions

Ask the robot to lean throttle and turn at turn radians a second.

The topic drive commands are published on.

Ask for nothing, which is how the robot is stopped.

Functions

command(robot, throttle, turn)

@spec command(module(), number(), number()) :: :ok

Ask the robot to lean throttle and turn at turn radians a second.

throttle runs -1 to 1 and is a fraction of the lean the controller will spend on driving, not a speed. Positive is forwards and to the robot's left.

path()

@spec path() :: [atom()]

The topic drive commands are published on.

stop(robot)

@spec stop(module()) :: :ok

Ask for nothing, which is how the robot is stopped.

Worth calling explicitly on the way out rather than relying on the timeout: the timeout is what catches a pilot who has vanished, not a courtesy for one who has simply stopped.