Closed akru closed 8 years ago
I really like the way connect
looks, but I'm not yet sure about the TopicArrow
part. The example looks a lot like the Applicative interface. Do you have in mind some examples where the Arrow interface really wins?
It's not the same as Applicative because TopicArrow
:
>>>
combinator is left-to-right vs function composition, it's like to graphical scheme of processFor example
refModel :: TopicArrow IO Double Double
{- |The DC motor with reductor model
- u - control voltage
- y - current position
-
- u +---+ +-------+ +----------+ y
- ------>| K |-->| Motor |--->| Reductor |---->
- +---+ +-------+ +----------+
-}
refModel k = gain k >>> dcmotor >>> reductor
reductor :: Arrow a => a Double Double
reductor = gear 15 >>> gear 5 >>> gear 24
dcmotor :: TopicArrow IO Double Double
dcmotor = stateSpace ss_dcm
where -- State-space dc motor model
ss_dcm = c2d dt $ SS tA tB tC tX
tX = fromLists [[0],[0],[0]]
tA = fromLists [[0,1,0],[0,-b/j, k/j],[0,-k/l,-r/l]]
tB = fromLists [[0],[0],[1/l]]
tC = fromLists [[1,0,0]]
-- DC motor physics constants
b = 0.1 -- motor viscous friction constant
j = 0.01 -- moment of inertia of the rotor
k = 0.01 -- motor torque constant
l = 0.5 -- electric inductance
r = 1 -- electric resistance
Alright, I'm sold. Thank you for both the effort on the coding and the patience with the PR!
Arrows
The arrow(https://www.haskell.org/arrows) on topic is an alternative to monadic
Ros.Topic
interface.Arrows says in terms of message changing, e.g.
TopicArrow
has type:A lot of standart topic operations can be written in arrow terms, e.g.
Subscribe, Advertise and Connect type classes
The
Subscribe
type class is an abstraction of subscribed types, and have definition:The
Advertise
type class is an abstraction of advertised types, and have definition:The
Connect
type class is a combination ofSubscribe
andAdvertise
actions with given arrow between messages of subscribed and advertised types.This PR contains Subscribe/Advertise instances for
Topic IO
andTopicArrow IO ()
types, and Connect instances for(->)
andTopicArrow IO
.Example: