Commit 996d975b authored by Claudio Gomes's avatar Claudio Gomes
Browse files

Overture controller model

parent 7c0af5d0
/materials/driver_controller/Driver/generated
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Driver</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.overture.ide.core.builder.VdmBuilder</name>
<arguments>
<dictionary>
<key>LANGUAGE_VERSION</key>
<value>vdm10</value>
</dictionary>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.overture.ide.vdmrt.core.nature</nature>
</natures>
</projectDescription>
class Controller
instance variables
positionSensor : PositionSensor;
steeringActuator : SteeringActuator;
kpPort : RealPort;
operations
public Controller : RealPort * PositionSensor * SteeringActuator ==> Controller
Controller(k, s,a)==
(
kpPort := k;
positionSensor := s;
steeringActuator := a;
);
private loop : () ==>()
loop()==
cycles(2)
(-- retrieve the first value from Co-SIM
let kp : real = kpPort.getValue() in
let x : real = positionSensor.getX() in
let y : real = positionSensor.getY() in
let beta : real = positionSensor.getBeta()
in
(
steeringActuator.setSteering(-kp*y);
);
)
thread
periodic(10E6,0,0,0)(loop);
end Controller
--## EXPORT d4e2dd66f36c59f4134c76e1fce69803be3fe08e Driver.fmu 2020-18-07 15:19:21 tool-wrapper {"name":"fmu-import-export","version":"0.2.20"}
--## EXPORT d8742605b27a11e2393abad17012e5a5a49ba528 Driver.fmu 2020-18-07 14:53:10 tool-wrapper {"name":"fmu-import-export","version":"0.2.20"}
class HardwareInterface
values
-- @ interface: type = parameter, name="kp";
public kp : RealPort = new RealPort(1.0);
instance variables
-- @ interface: type = input, name="x";
public x : RealPort := new RealPort(0.0);
-- @ interface: type = input, name="y";
public y : RealPort := new RealPort(0.0);
-- @ interface: type = input, name="beta";
public beta : RealPort := new RealPort(0.0);
-- @ interface: type = output, name="steering";
public steering : RealPort := new RealPort(0.0);
end HardwareInterface
class PositionSensor
instance variables
portX : RealPort;
portY : RealPort;
portBeta : RealPort;
operations
public PositionSensor: RealPort * RealPort * RealPort ==> PositionSensor
PositionSensor(pX, pY, pB) == (
portX := pX;
portY := pY;
portBeta := pB;
);
public getX: () ==> real
getX()== return portX.getValue();
public getY: () ==> real
getY()== return portY.getValue();
public getBeta: () ==> real
getBeta()== return portBeta.getValue();
end PositionSensor
\ No newline at end of file
class SteeringActuator
instance variables
steering : RealPort;
operations
public SteeringActuator: Port ==> SteeringActuator
SteeringActuator(p) == steering := p;
public setSteering: real ==> ()
setSteering(value)== steering.setValue(value);
end SteeringActuator
\ No newline at end of file
system System
instance variables
-- Hardware interface variable required by FMU Import/Export
public static hwi: HardwareInterface := new HardwareInterface();
instance variables
public positionSensor : PositionSensor;
public steeringActuator : SteeringActuator;
public static controller : [Controller] := nil;
cpu1 : CPU := new CPU(<FP>, 20);
operations
public System : () ==> System
System () ==
(
positionSensor := new PositionSensor(hwi.x, hwi.y, hwi.beta);
steeringActuator := new SteeringActuator(hwi.steering);
controller := new Controller(hwi.kp, positionSensor, steeringActuator);
cpu1.deploy(controller,"Controller");
);
end System
class World
operations
public run : () ==> ()
run() ==
(start(System`controller);
block();
);
private block : () ==>()
block() ==
skip;
sync
per block => false;
end World
\ No newline at end of file
/******************************************************************************************************************************
* FMI 2.0 interface for VDM
*
* The Port class is the base class for all ports. The following ports exists:
* - IntPort
* - BoolPort
* - RealPort
* - StringPort
* These concreate ports must be used in the HardwareInterface class. All of them must contain a private 'value' field
* this field is accessed directly by the build-in FMI support in the simulator. The ports can be given as arguments to
* other model elements. All access to the internal value must be done through set/getValue since this call insured that the
* simulator knows that the value have been read or written to and requires a co-simulation step for synchronization.
*
* A port can be instantiated with a value or with no values to use the library default value.
*
******************************************************************************************************************************/
class Port
types
public String = seq of char;
public FmiPortType = bool | real | int | String;
operations
public setValue : FmiPortType ==> ()
setValue(v) == is subclass responsibility;
public getValue : () ==> FmiPortType
getValue() == is subclass responsibility;
end Port
class IntPort is subclass of Port
instance variables
value: int:=0;
operations
public IntPort: int ==> IntPort
IntPort(v)==setValue(v);
public setValue : int ==> ()
setValue(v) ==value :=v;
public getValue : () ==> int
getValue() == return value;
end IntPort
class BoolPort is subclass of Port
instance variables
value: bool:=false;
operations
public BoolPort: bool ==> BoolPort
BoolPort(v)==setValue(v);
public setValue : bool ==> ()
setValue(v) ==value :=v;
public getValue : () ==> bool
getValue() == return value;
end BoolPort
class RealPort is subclass of Port
instance variables
value: real:=0.0;
operations
public RealPort: real ==> RealPort
RealPort(v)==setValue(v);
public setValue : real ==> ()
setValue(v) ==value :=v;
public getValue : () ==> real
getValue() == return value;
end RealPort
class StringPort is subclass of Port
instance variables
value: String:="";
operations
public StringPort: String ==> StringPort
StringPort(v)==setValue(v);
public setValue : String ==> ()
setValue(v) ==value :=v;
public getValue : () ==> String
getValue() == return value;
end StringPort
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment