ICreateMoveToLoc.spec
Require Import robots.icreate.
Require Import canonical_names.
Require Import Vector.
Require Import CPS.
Require Import CPSUtils.
Require Import MathClasses.interfaces.canonical_names.
Require Import MCInstances.
Require Import CartCR.
Set Implicit Arguments.
Instance ProjectionFst_instance_sig
(A : Type) (P: A → Prop):
ProjectionFst (sig P) A := (@proj1_sig A P) .
Instance ProjectionFst_instance_sigT
(A : Type) (P: A → Type):
ProjectionFst (sigT P) A := (@projT1 A P) .
Require Import canonical_names.
Require Import Vector.
Require Import CPS.
Require Import CPSUtils.
Require Import MathClasses.interfaces.canonical_names.
Require Import MCInstances.
Require Import CartCR.
Set Implicit Arguments.
Instance ProjectionFst_instance_sig
(A : Type) (P: A → Prop):
ProjectionFst (sig P) A := (@proj1_sig A P) .
Instance ProjectionFst_instance_sigT
(A : Type) (P: A → Type):
ProjectionFst (sigT P) A := (@projT1 A P) .
Overview
To move to the target position, the robot first turns towards it and then
moves forward. Because a robot may not be able to physical achieve
any arbitrary angular linear speed, we let the user specify the desired
speeds. By adjusting the duration of rotation and linear motion, we can
make the robot go anywhere.
The two variable respectively denote the user specified rotational(angular) and linear speed.
The meaning of the 2 parameters below will be explained while explaining
the program.
Context { delEps : Qpos}.
Context { delay : Qpos}.
Definition R2QPrec : Qpos := simpleApproximateErr delRes delEps.
Close Scope Q_scope.
Here is the program. For a detailed explanation, please
refer to Section 4.2 of the
ROSCoq paper
Definition robotPureProgam (target : Cart2D Q) : list (Q × Polar2D Q) :=
let polarTarget : Polar2D CR := Cart2Polar target in
let rotDuration : CR := ((| θ polarTarget |) * '(/ rotspeed)%Q) in
let translDuration : CR := (rad polarTarget) * '(/ linspeed)%Q in
[ (0,{|rad:= 0 ; θ := (polarθSign target) * rotspeed |})
; (tapprox rotDuration delRes delEps , {|rad:= 0 ; θ := 0 |})
; ('delay , {|rad:= 'linspeed ; θ := 0 |})
; (tapprox translDuration delRes delEps , {|rad:= 0 ; θ := 0 |}) ].
Specifying the whole cyber-physical system system.
Topics
TopicClass the type to have decidable equality
The TopicClass also needs the payload type for eqch topic.
Definition topic2Type (t : Topic) : Type :=
match t with
| VELOCITY ⇒ Polar2D Q
| TARGETPOS ⇒ Cart2D Q
end.
Global Instance rtopic : @TopicClass Topic _.
constructor. exact topic2Type.
Defined.
The type Topic will serve as an implicit parameter of the type Message.
A message is just a dependent pair of a topic and its payload type.
Here is an example usage.
Collection of Agents.
To be able to holistically reason about a CpS, we have to specify the collection of agents and the physical model of the cyber-physical system. One has to then specify the behavior of each agent in a mutually independent way. All of this is achieved by specifying an instance of CPS. We will see how to build one for our example. First, we need a type to denote the collection of agents. Each member of the type below denotes an agent (vertical downward arrow) in the message sequence diagram near the top of this page. Also, below they appear in the same order as they appear in the figure above.
Decidable equality is a requirement of the CPS typeclass
Scheme Equality for RosLoc.
Global Instance ldeq : DecEq RosLoc.
constructor. exact RosLoc_eq_dec.
Defined.
Global Instance ldeq : DecEq RosLoc.
constructor. exact RosLoc_eq_dec.
Defined.
Definition locTopics (rl : RosLoc) : TopicInfo :=
match rl with
| MOVABLEBASE ⇒ ((VELOCITY::nil), nil)
| SWNODE ⇒ ((TARGETPOS::nil), (VELOCITY::nil))
| EXTERNALCMD ⇒ (nil, (TARGETPOS::nil))
end.
match rl with
| MOVABLEBASE ⇒ ((VELOCITY::nil), nil)
| SWNODE ⇒ ((TARGETPOS::nil), (VELOCITY::nil))
| EXTERNALCMD ⇒ (nil, (TARGETPOS::nil))
end.
Physical Model
Now that we have defined the the collection of agents, we have to specify the behvior of each agent in a mutually independent way. However, the behavior of hardware devices such as sensors and actuators cannot be specified without modeling the evolution of the relevant physical quantities (e.g. the ones they measure or influence). The first argument of CPS, which is implicit, a a type denoting the physical model of the cyber-physical system. As described in Sec. 2 of the ROSCoq paper, A physical model is a type that specifies how each relevant physical quantities evolved over time, and the physical laws governing that evolution. In this example, there is only one robot (iRobot Create), and the physical quantities are the physical quantities relevant to that robot where specified in the type iCreate. So that type will serve as our physical model. If there were, say 2 robots, the physical model could be the type iCreate * iCreateSemantics of Agents
Hardware Agent
It is more sensible to change the type to QNonNeg
as the value certainly does not represent time.
However, the coercion QT2Q does not work then
Context {motorPrec : Polar2D Q → Polar2D QTime}.
Hypothesis motorPrec0 : motorPrec {| rad :=0 ; θ :=0 |} ≡ {| rad :=0 ; θ :=0 |}.
Definition HwAgent : Device PhysicalModel := HwAgent VELOCITY eq_refl reacTime motorPrec.
Hypothesis motorPrec0 : motorPrec {| rad :=0 ; θ :=0 |} ≡ {| rad :=0 ; θ :=0 |}.
Definition HwAgent : Device PhysicalModel := HwAgent VELOCITY eq_refl reacTime motorPrec.
Definition PureSwProgram: PureProcWDelay TARGETPOS VELOCITY:=
robotPureProgam.
Definition SwProcess : Process Message (list Message):=
mkPureProcess (delayedLift2Mesg (PureSwProgram)).
Context {procTime : QTime}.
Context {sendTimeAcc : Qpos}.
Require Export CoRN.model.metric2.Qmetric.
Definition ControllerNode : RosSwNode :=
Build_RosSwNode (SwProcess) (procTime, sendTimeAcc).
robotPureProgam.
Definition SwProcess : Process Message (list Message):=
mkPureProcess (delayedLift2Mesg (PureSwProgram)).
Context {procTime : QTime}.
Context {sendTimeAcc : Qpos}.
Require Export CoRN.model.metric2.Qmetric.
Definition ControllerNode : RosSwNode :=
Build_RosSwNode (SwProcess) (procTime, sendTimeAcc).
Context {target : Cart2D Q}.
Definition externalCmdSemantics
: @NodeSemantics PhysicalModel Topic _ _:=
λ Event edeq etype _ evs,
isSendEvtOp (evs 0)
∧ (getSentPayloadOp TARGETPOS (evs 0) ≡ Some target)
∧ ∀ n : nat, (evs (S n)) ≡ None.
Definition externalCmdSemantics
: @NodeSemantics PhysicalModel Topic _ _:=
λ Event edeq etype _ evs,
isSendEvtOp (evs 0)
∧ (getSentPayloadOp TARGETPOS (evs 0) ≡ Some target)
∧ ∀ n : nat, (evs (S n)) ≡ None.
The network model.
To specify a CPS, we need to specify its network model In this example, we assume that the network reliably delivers messages.Context {expectedDelivDelay : Qpos}.
Context {delivDelayVar : Qpos}.
Instance lcon : @Connectivity Topic RosLoc.
constructor.
- exact locTopics.
- exact (λ _ _ t , ball delivDelayVar t (QposAsQ expectedDelivDelay)).
Defined.
Definition networkModel : NetworkModel RosLoc :=
fun Event _ _ _ ⇒ @EOReliableDelivery Topic Event RosLoc _ _ _ _ _ _.
Definition locNode (rl : RosLoc) : NodeSemantics :=
match rl with
| MOVABLEBASE ⇒ DeviceSemantics (λ ts, ts) HwAgent
| SWNODE ⇒ SwSemantics ControllerNode
| EXTERNALCMD ⇒ externalCmdSemantics
end.
Global Instance icreateMoveToLoc : @CPS PhysicalModel Topic _ _ RosLoc ldeq _ :=
Build_CPS _ _ _ locNode networkModel.
End RobotProgam.