diff options
author | manasdas17 | 2019-08-26 09:14:01 +0530 |
---|---|---|
committer | manasdas17 | 2019-08-26 09:14:01 +0530 |
commit | a606e57a77628d2ac2301ee7e194bd46f7a5813b (patch) | |
tree | f17cd36483b9e173d2a1d906a0a8363431002b09 | |
download | OpenModelica_Arduino_With_MDD-a606e57a77628d2ac2301ee7e194bd46f7a5813b.tar.gz OpenModelica_Arduino_With_MDD-a606e57a77628d2ac2301ee7e194bd46f7a5813b.tar.bz2 OpenModelica_Arduino_With_MDD-a606e57a77628d2ac2301ee7e194bd46f7a5813b.zip |
first commit
220 files changed, 16212 insertions, 0 deletions
diff --git a/Final.pdf b/Final.pdf Binary files differnew file mode 100644 index 0000000..56a7d3b --- /dev/null +++ b/Final.pdf diff --git a/FosseeInternReport.doc b/FosseeInternReport.doc Binary files differnew file mode 100644 index 0000000..114cd93 --- /dev/null +++ b/FosseeInternReport.doc diff --git a/FosseeInternReport.pdf b/FosseeInternReport.pdf Binary files differnew file mode 100644 index 0000000..1739666 --- /dev/null +++ b/FosseeInternReport.pdf diff --git a/OpenModelica_Arduino_With_MDD/Arduino.mo b/OpenModelica_Arduino_With_MDD/Arduino.mo new file mode 100644 index 0000000..649b694 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/Arduino.mo @@ -0,0 +1,1801 @@ +package Arduino + extends Arduino.SerialCommunication.Icons.GenericICPackage; + + package SerialCommunication "Serial Communication Package for Arduino" + extends Arduino.SerialCommunication.Icons.FunctionLayerIcon; + import ModelicaReference.Operators; + + package Functions + extends Modelica.Icons.Package; + import Modelica; + + function open_serial "Command to initialize the serial port which is connected to Arduino" + extends Modelica.Icons.Function; + input Integer handle, port, baudrate; + output Integer OK; + + external OK = open_serial(handle, port, baudrate) annotation( + Library = "SerialComm"); + annotation( + Documentation(info = "<html> +<h4>Syntax</h4> +<blockquote><pre> +Arduino.SerialCommunication.Functions.<b>open_serial</b>(handle,port,baudrate); +</pre></blockquote> +<h4>Description</h4> +<p> +Establishes a serial communication using port number \"port\".To connect to the Arduino board, check the port number from the device manager or check it from the Arduino software. +</p> +</html>")); + end open_serial; + + function read_serial "read characters from serial port" + extends Modelica.Icons.Function; + input Integer handle; + input Integer size; + output Integer r_OK; + protected + Integer buf[size + 1]; + //String buf; + + external r_OK = read_serial(handle, buf, size) annotation( + Library = "SerialComm"); + annotation( + Documentation(info = "<html> +<h4>Syntax</h4> +<blockquote><pre> +Arduino.SerialCommunication.Functions.<b>read_serial</b>(handle,size); +</pre></blockquote> +<h4>Description</h4> +<p>The translation setting of openserial can come in the way, affecting the number of characters effectively read. If that is the case, omitting the parameter n might be a bad idea, as scilab can hang. This would happen if the input stream contains CR or LF characters which are filtered out: in such cases serialstatus counts them, but readserial does not see them and keeps wating (if the blocking mode of openserial was true) until the total number is received. +</p> +</html>")); + end read_serial; + + //algorithm + //Modelica.Utilities.Streams.print(String(buf)); + + function write_serial "write to the serial port" + extends Modelica.Icons.Function; + input Integer handle; + input String str; + input Integer size; + output Integer w_OK; + + external w_OK = write_serial(handle, str, size) annotation( + Library = "SerialComm"); + annotation( + Documentation(info = "<html> +<h4>Syntax</h4> +<blockquote><pre> +Arduino.SerialCommunication.Functions.<b>write_serial</b>(handle,str,size); +</pre></blockquote> +<h4>Description</h4> +<p>No end of line character is appended to the string; the user might have to add it if the device being talked to requires it. The Tcl command puts -nonewline is used. In addition, the translation mode of openserial can come into way. +</p> +</html>")); + end write_serial; + + function close_serial "Command to close the serial port which is connected to Arduino" + extends Modelica.Icons.Function; + input Integer handle; + output Integer c_OK; + + external c_OK = close_serial(handle) annotation( + Library = "SerialComm"); + annotation( + Documentation(info = "<html> +<h4>Syntax</h4> +<blockquote><pre> +Arduino.SerialCommunication.Functions.<b>close_serial</b>(handle); +</pre></blockquote> +<h4>Description</h4> +<p>Closes the port for serial communication specified by \"handle\".It is important to close the serial port after use, else the port would be busy and restart of Scilab might required to connect to it again. +</p> +</html>")); + end close_serial; + + function status_serial "get status of the serial port" + extends Modelica.Icons.Function; + input Integer handle; + output Integer stat_OK; + protected + Integer bytes[2]; + + external stat_OK = status_serial(handle, bytes) annotation( + Library = "SerialComm"); + annotation( + Documentation(info = "<html> +<h4>Syntax</h4> +<blockquote><pre> +Arduino.SerialCommunication.Functions.<b>status_serial</b>(handle); +</pre></blockquote> +<h4>Description</h4> +<p>Provides status of serial communication channel specified by \"handle\".Get some information about the number of characters present in the input and output buffers of the serial port, and about the status lines (DTS, CTS, etc.).The translation setting of openserial can come in the way. If the input stream contains CR or LF characters which are filtered out, openserial counts them but readserial does not see them. +</p> +</html>")); + end status_serial; + + function cmd_digital_out "Command to sent out digital signal to a connected Arduino board" + extends Modelica.Icons.Function; + input Integer h, pin_no, val; + output Integer digital_w_OK; + + external digital_w_OK = cmd_digital_out(h, pin_no, val) annotation( + Library = "Digital"); + annotation( + Documentation(info = "<html> +<h4>Syntax</h4> +<blockquote><pre> +Arduino.SerialCommunication.Functions.<b>cmd_digital_out</b>(handle,pin_no,value); +</pre></blockquote> +<h4>Description</h4> +<p>The Arduino board has a set of logical ports (digital) that are used for writing or reading data from a component. +To map a UNO, ports 2-13 are available (0 and 1 are used for serial transmission). For MEGA board, ports 2-53 are available. The port takes the low logic level (0) or logic high (1) which corresponds to the reference voltage. +</p> +</html>")); + end cmd_digital_out; + + function cmd_digital_in "Command to read in digital signal from a connected Arduino board" + extends Modelica.Icons.Function; + input Integer h, pin_no; + output Integer digital_in; + + external digital_in = cmd_digital_in(h, pin_no) annotation( + Library = "Digital"); + annotation( + Documentation(info = "<html> +<h4>Syntax</h4> +<blockquote><pre> +Arduino.SerialCommunication.Functions.<b>cmd_digital_in</b>(handle,pin_no); +</pre></blockquote> +<h4>Description</h4> +<p>The Arduino board has a set of logical ports (digital) that are used for writing or reading data from a component. +To map a UNO, ports 2-13 are available (0 and 1 are used for serial transmission). For MEGA board, ports 2-53 are available. The port takes the low logic level (0) or logic high (1) which corresponds to the reference voltage. +</p> +</html>")); + end cmd_digital_in; + + function delay "Provides delay.Suspends Openmodelica." + extends Modelica.Icons.Function; + input Integer t; + + external delay(t) annotation( + Library = "delay"); + annotation( + Documentation(info = "<html> + <h4>Syntax</h4> + <blockquote><pre> + Arduino.SerialCommunication.Functions.<b>delay</b>(milliseconds); + </pre></blockquote> + <h4>Description</h4> + <p>Delay process for specified number of miliseconds specified by the argument. The actual suspension time may be longer because of other activities in the system, or because of the time spent in processing the call. + </p> + </html>")); + end delay; + + function cmd_analog_in "Command to read in analog signal from a connected Arduino board" + extends Modelica.Icons.Function; + input Integer h, pin_no; + output Integer val; + + external val = cmd_analog_in(h, pin_no) annotation( + Library = "Analog"); + annotation( + Documentation(info = "<html> +<h4>Syntax</h4> +<blockquote><pre> +Arduino.SerialCommunication.Functions.<b>cmd_analog_in</b>(handle,pin_no); +</pre></blockquote> +<h4>Description</h4> +<p>Arduino UNO board has 6 analog input ports (A0 to A5), the Arduino Mega board has 16 analog input ports (A0 to A15). The 10 bits channels convert the analog input from 0 to 5 volts, to a digital value between 0 and 1023. +</p> +</html>")); + end cmd_analog_in; + + function cmd_analog_out "Command to sent out analog signal to a connected Arduino board" + extends Modelica.Icons.Function; + input Integer h, pin_no; + input Real val; + output Integer analog_w_OK; + + external analog_w_OK = cmd_analog_out(h, pin_no, val) annotation( + Library = "Analog"); + annotation( + Documentation(info = "<html> +<h4>Syntax</h4> +<blockquote><pre> +Arduino.SerialCommunication.Functions.<b>cmd_analog_out</b>(handle,pin_no,val); +</pre></blockquote> +<h4>Description</h4> +<p>The analog outputs of the Arduino Uno is available at the pins 3,5,6,9,10 and 11, while on the Mega board, the outputs are on pins 1-13 and 44-46. It is a bit misleading to use the term 'analog output', because in order to generate this output while minimizing energy losses, the Arduino uses PWM (Pulse Width Modulation) available on these ports. By varying the duty cycle of the PWM is altered the average voltage across the component connected to this port, which has the effect of having a analog output voltage. +The input port accepts the value from 0 to 255 which is correspoding to the duty cycle of 0 to 100%. In other words, sending 0 to the block will generate 0 V output at the port, 127 generates 2.5V and 255 generates 5V. (the port is 8 bits, so the resolutions of output would be 2^8 =256). +</p> +</html>")); + end cmd_analog_out; + + function cmd_analog_in_volt "Command to read in analog signal from a connected Arduino board" + extends Modelica.Icons.Function; + input Integer h, pin_no; + output Integer val; + + external val = cmd_analog_in_volt(h, pin_no) annotation( + Library = "Analogv"); + annotation( + Documentation(info = "<html> + <h4>Syntax</h4> + <blockquote><pre> + Arduino.SerialCommunication.Functions.<b>cmd_analog_in_volt</b>(handle,pin_no); + </pre></blockquote> + <h4>Description</h4> + <p>Arduino UNO board has 6 analog input ports (A0 to A5), the Arduino Mega board has 16 analog input ports (A0 to A15). The 10 bits channels convert the analog input from 0 to 5 volts, to a digital value between 0 and 1023. This function scale the reading to 0-5 so the user could get the measured voltage directly. + </p> + </html>")); + end cmd_analog_in_volt; + + function cmd_analog_out_volt "Command to sent out analog signal to a connected Arduino board" + extends Modelica.Icons.Function; + input Integer h, pin_no; + input Real val; + output Integer analog_v_wOK; + + external analog_v_wOK = cmd_analog_out_volt(h, pin_no, val) annotation( + Library = "Analogv"); + annotation( + Documentation(info = "<html> + <h4>Syntax</h4> + <blockquote><pre> + Arduino.SerialCommunication.Functions.<b>cmd_analog_out_volt</b>(handle,pin_no,val); + </pre></blockquote> + <h4>Description</h4> + <p>The analog outputs of the Arduino Uno is available at the pins 3,5,6,9,10 and 11, while on the Mega board, the outputs are on pins 1-13 and 44-46. It is a bit misleading to use the term 'analog output', because in order to generate this output while minimizing energy losses, the Arduino uses PWM (Pulse Width Modulation) available on these ports. By varying the duty cycle of the PWM is altered the average voltage across the component connected to this port, which has the effect of having a analog output voltage. + </p> + </html>")); + end cmd_analog_out_volt; + + function cmd_dcmotor_setup "Command to setup pins to control DC motor" + extends Modelica.Icons.Function; + input Integer handle, driver_type, motor_no, pin1, pin2; + + external cmd_dcmotor_setup(handle, driver_type, motor_no, pin1, pin2) annotation( + Library = "DCMotor"); + annotation( + Documentation(info = "<html> + <h4>Syntax</h4> + <blockquote><pre> + Arduino.SerialCommunication.Functions.<b>cmd_dcmotor_setup</b>(handle,driver_type,motor_no,pin_no1,pin_no2); + </pre></blockquote> + <h4>Description</h4> + <p>Arduino board does not deliver enough power, so it is necessary to use a H-bridge circuit/IC to control the motor. There are several types of H-bridge IC that do not all operate on the same principle. For example, the L298 requires the use of a PWM signal with current sense. The L293 uses two PWM to set the speed and direction. Ready-to-use Shields are also available. + Remember that the PWM is 8-bit (0 to 255). The input of the block could accept any value, but it would saturate at +- 255. + </p> + </html>")); + end cmd_dcmotor_setup; + + function cmd_dcmotor_run "Command to run DC motor after setting up" + extends Modelica.Icons.Function; + input Integer handle, motor_no, val; + + external cmd_dcmotor_run(handle, motor_no, val) annotation( + Library = "DCMotor"); + annotation( + Documentation(info = "<html> + <h4>Syntax</h4> + <blockquote><pre> + Arduino.SerialCommunication.Functions.<b>cmd_dcmotor_run</b>(handle,motor_no,value); + </pre></blockquote> + <h4>Description</h4> + <p>Arduino board does not deliver enough power, so it is necessary to use a H-bridge circuit/IC to control the motor. There are several types of H-bridge IC that do not all operate on the same principle. For example, the L298 requires the use of a PWM signal with current sense. The L293 uses two PWM to set the speed and direction. Ready-to-use Shields are also available. + Remember that the PWM is 8-bit (0 to 255). The input of the block could accept any value, but it would saturate at +- 255. + </p> + </html>")); + end cmd_dcmotor_run; + + function cmd_dcmotor_release "Command to release pins which have setup for DC motor" + extends Modelica.Icons.Function; + input Integer handle, motor_no; + + external cmd_dcmotor_release(handle, motor_no) annotation( + Library = "DCMotor"); + annotation( + Documentation(info = "<html> + <h4>Syntax</h4> + <blockquote><pre> + Arduino.SerialCommunication.Functions.<b>cmd_dcmotor_release</b>(handle,motor_no); + </pre></blockquote> + <h4>Description</h4> + <p>Arduino board does not deliver enough power, so it is necessary to use a H-bridge circuit/IC to control the motor. There are several types of H-bridge IC that do not all operate on the same principle. For example, the L298 requires the use of a PWM signal with current sense. The L293 uses two PWM to set the speed and direction. Ready-to-use Shields are also available. + Remember that the PWM is 8-bit (0 to 255). The input of the block could accept any value, but it would saturate at +- 255. + </p> + </html>")); + end cmd_dcmotor_release; + + function cmd_servo_attach "Command to attach servo motor to Arduino" + extends Modelica.Icons.Function; + input Integer handle, servo_no; + + external cmd_servo_attach(handle, servo_no) annotation( + Library = "ServoMotor"); + annotation( + Documentation(info = "<html> + <h4>Syntax</h4> + <blockquote><pre> + Arduino.SerialCommunication.Functions.<b>cmd_servo_attach</b>(handle,servo_no); + </pre></blockquote> + <h4>Description</h4> + <p>A servomotor is an rotary actuator consist of an electric motor, gears, a potentiometer and an analogue or digital electronics for control. The servomotor usualy used for a position control application (or speed for continuous rotation servos). + The user must give the command of the position setpoint or desired speed. This command is sent to the actuator in pulses spaced by 10 to 20 ms. The coding of these pulses is made such that a pulse of 1.5 ms corresponding to the centered position (rest), a pulse of 1 ms corresponds to an angle of 90° in the anticlockwise direction, and a pulse 2 ms corresponds to an angle of 90° clockwise. All other pulse widths give intermediate values. + A servomotor for continuous rotation, the pulse width control the rotational speed and the direction. It is recommended to use a voltage regulator to power the servomotor instead of using the Arduino board power. For simplicity, the function takes an input commnad in degrees from 0 to 180. Two actuators can be controlled with this toolbox. (modified version of 3 motors available) + </p> + </html>")); + end cmd_servo_attach; + + function cmd_servo_move "Command to run servo motor which has been setup" + extends Modelica.Icons.Function; + input Integer handle, servo_no, val; + + external cmd_servo_move(handle, servo_no, val) annotation( + Library = "ServoMotor"); + annotation( + Documentation(info = "<html> + <h4>Syntax</h4> + <blockquote><pre> + Arduino.SerialCommunication.Functions.<b>cmd_servo_move</b>(handle,servo_no,value); + </pre></blockquote> + <h4>Description</h4> + <p>A servomotor is an rotary actuator consist of an electric motor, gears, a potentiometer and an analogue or digital electronics for control. The servomotor usualy used for a position control application (or speed for continuous rotation servos). + The user must give the command of the position setpoint or desired speed. This command is sent to the actuator in pulses spaced by 10 to 20 ms. The coding of these pulses is made such that a pulse of 1.5 ms corresponding to the centered position (rest), a pulse of 1 ms corresponds to an angle of 90° in the anticlockwise direction, and a pulse 2 ms corresponds to an angle of 90° clockwise. All other pulse widths give intermediate values. + A servomotor for continuous rotation, the pulse width control the rotational speed and the direction. It is recommended to use a voltage regulator to power the servomotor instead of using the Arduino board power. For simplicity, the function takes an input commnad in degrees from 0 to 180. Two actuators can be controlled with this toolbox. (modified version of 3 motors available) + </p> + </html>")); + end cmd_servo_move; + + function cmd_servo_detach "Command to release the pin which has been setup for servo motor" + extends Modelica.Icons.Function; + input Integer handle, servo_no; + + external cmd_servo_attach(handle, servo_no) annotation( + Library = "ServoMotor"); + annotation( + Documentation(info = "<html> + <h4>Syntax</h4> + <blockquote><pre> + Arduino.SerialCommunication.Functions.<b>cmd_servo_detach</b>(handle,servo_no); + </pre></blockquote> + <h4>Description</h4> + <p>A servomotor is an rotary actuator consist of an electric motor, gears, a potentiometer and an analogue or digital electronics for control. The servomotor usualy used for a position control application (or speed for continuous rotation servos). + The user must give the command of the position setpoint or desired speed. This command is sent to the actuator in pulses spaced by 10 to 20 ms. The coding of these pulses is made such that a pulse of 1.5 ms corresponding to the centered position (rest), a pulse of 1 ms corresponds to an angle of 90° in the anticlockwise direction, and a pulse 2 ms corresponds to an angle of 90° clockwise. All other pulse widths give intermediate values. + A servomotor for continuous rotation, the pulse width control the rotational speed and the direction. It is recommended to use a voltage regulator to power the servomotor instead of using the Arduino board power. For simplicity, the function takes an input commnad in degrees from 0 to 180. Two actuators can be controlled with this toolbox. (modified version of 3 motors available) + </p> + </html>")); + end cmd_servo_detach; + + function ieeesingle2num "ieee-745 floating point converter" + extends Modelica.Icons.Function; + input String hexa; + output Real y; + + external y = ieeesingle2num(hexa) annotation( + Library = "ieeesingle2num"); + annotation( + Documentation(info = "<html> +<h4>Syntax</h4> +<blockquote><pre> +Arduino.SerialCommunication.Functions.<b>ieeesingle2num</b>(hexa); +</pre></blockquote> +<h4>Description</h4> +<p>Converts an hexadecimal integer to ieee single precision format + </p> +</html>")); + end ieeesingle2num; + + function math_floor "Floor function" + extends Modelica.Icons.Function; + input Real x; + output Integer y; + + external y = mfloor(x) annotation( + Library = "floor"); + annotation( + Documentation(info = "<html> + <h4>Syntax</h4> + <blockquote><pre> + Arduino.SerialCommunication.Functions.<b>math_floor</b>(x); + </pre></blockquote> + <h4>Description</h4> + <p>Returns the greatest integer less than or equal to x + </p> + </html>")); + end math_floor; + + function getArduinoVersion "Returns the Arduino version used" + extends Modelica.Icons.Function; + output String arduinoVersion(fixed = true); + algorithm + arduinoVersion := "1.1"; + annotation( + Documentation(info = "<html> + <h4>Syntax</h4> + <blockquote><pre> + Arduino.SerialCommunication.<b>getArduinoVersion</b>(); + </pre></blockquote> + <h4>Description</h4> + <p>Gives the version of the arduino used. + </p> + </html>")); + end getArduinoVersion; + + function cmd_encoder_init "Initiates the encoder" + extends Modelica.Icons.Function; + input Integer h, encoder_mode, pin_no1, pin_no2; + + external cmd_encoder_init(h, encoder_mode, pin_no1, pin_no2) annotation( + Library = "Encoder"); + annotation( + Documentation(info = "<html> + <h4>Syntax</h4> + <blockquote><pre> + Arduino.SerialCommunication.<b>cmd_encoder_init</b>(handle,encoder_mode,pin_no1,pin_no2); + </pre></blockquote> + <h4>Description</h4> + <p>Used to read encoder signal from one or more channels + </p> + </html>")); + end cmd_encoder_init; + + //Incomplete + + package MDD_Servo + extends Modelica.Icons.Package; + + class Init + extends ExternalObject; + + function constructor "Return device handle" + extends .Modelica.Icons.Function; + import Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions; + import Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types; + import sComm = Arduino.SerialCommunication.Functions; + import Arduino.SerialCommunication.Functions.MDD_Servo; + input sComm.Types.Servo_no servo_no; + output sComm.Functions.MDD_Servo.Init servo; + + external "C" servo = MDD_avr_servo_initialize(servo_no) annotation( + Include = "#include \"/home/manas/OpenModelica/Resources/Include/MDDAVRServo.h\""); + end constructor; + + function destructor "Destructor" + extends .Modelica.Icons.Function; + import Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types; + import sComm = Arduino.SerialCommunication.Functions; + import Arduino.SerialCommunication.Functions.MDD_Servo; + input sComm.Types.Servo_no servo_no "Device handle"; + + external "C" MDD_avr_servo_finalize(servo_no) annotation( + Include = "#include \"/home/manas/OpenModelica/Resources/Include/MDDAVRServo.h\""); + end destructor; + end Init; + + function Move + extends Modelica.Icons.Function; + import sComm = Arduino.SerialCommunication.Functions; + input sComm.Functions.MDD_Servo.Init servo; + input Integer value; + + external "C" MDD_avr_servo_move(servo, value) annotation( + Include = "#include \"/home/manas/OpenModelica/Resources/Include/MDDAVRServo.h\""); + end Move; + end MDD_Servo; + end Functions; + + package Examples + extends Modelica.Icons.ExamplesPackage; + + package led + extends Modelica.Icons.ExamplesPackage; + + model led_blue "Turn on Blue LED" + extends Modelica.Icons.Example; + import sComm = Arduino.SerialCommunication.Functions; + import strm = Modelica.Utilities.Streams; + Integer ok(fixed = false); + Integer digital_out(fixed = false); + Integer c_ok(fixed = false); + algorithm + when initial() then + ok := sComm.open_serial(1, 0, 115200) "At port 0 with baudrate of 115200"; + sComm.delay(2000); + if ok <> 0 then + strm.print("Check the serial port and try again"); + else + digital_out := sComm.cmd_digital_out(1, 27, 1) "This will turn ON the blue LED"; + end if; + strm.print(String(time)); + c_ok := sComm.close_serial(1) "To close the connection safely"; + end when; + annotation( + experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-6, Interval = 10)); + end led_blue; + + + model led_blue_delay "Turn on Blue LED for a period of 2 seconds" + extends Modelica.Icons.Example; + import sComm = Arduino.SerialCommunication.Functions; + import strm = Modelica.Utilities.Streams; + Integer ok(fixed = false); + Integer digital_out(fixed = false); + Integer c_ok(fixed = false); + algorithm + when initial() then + ok := sComm.open_serial(1, 0, 115200) "At port 0 with baudrate of 115200"; + sComm.delay(2000); + if ok <> 0 then + strm.print("Check the serial port and try again"); + else + digital_out := sComm.cmd_digital_out(1, 9, 1) "This will turn the blue LED"; + sComm.delay(2000) "let the blue LED be on for two seconds"; + digital_out := sComm.cmd_digital_out(1, 9, 0) "turn off blue LED"; + sComm.delay(2000) "let the blue LED be off for two seconds"; + end if; + strm.print(String(time)); + c_ok := sComm.close_serial(1) "To close the connection safely"; + end when; + annotation( + experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-6, Interval = 10)); + end led_blue_delay; + + model led_blue_red "Turn on Red & Blue LED" + extends Modelica.Icons.Example; + import sComm = Arduino.SerialCommunication.Functions; + import strm = Modelica.Utilities.Streams; + Integer ok(fixed = false); + Integer digital_out(fixed = false); + Integer c_ok(fixed = false); + algorithm + when initial() then + ok := sComm.open_serial(1, 0, 115200) "At port 0 with baudrate of 115200"; + if ok <> 0 then + strm.print("Check the serial port and try again"); + else + sComm.delay(2000); + digital_out := sComm.cmd_digital_out(1, 9, 1) "This will turn the blue LED"; + digital_out := sComm.cmd_digital_out(1, 11, 1) "This will turn the red LED"; + sComm.delay(5000) "Delay for 5 seconds"; + digital_out := sComm.cmd_digital_out(1, 9, 0) "This turns off the blue Led"; + sComm.delay(3000) "Delay for 3 seconds"; + digital_out := sComm.cmd_digital_out(1, 11, 0) "This turns off the red Led"; + end if; + strm.print(String(time)); + c_ok := sComm.close_serial(1) "To close the connection safely"; + end when; + annotation( + experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-6, Interval = 10)); + end led_blue_red; + + model led_blink "This will turn on and turn off the user LED for every second for 10 times" + extends Modelica.Icons.Example; + import sComm = Arduino.SerialCommunication.Functions; + import strm = Modelica.Utilities.Streams; + Integer ok(fixed = false); + Integer digital_out(fixed = false); + Integer c_ok(fixed = false); + algorithm + when initial() then + ok := sComm.open_serial(1, 0, 57600) "At port 0 with baudrate of 115200"; + sComm.delay(2000); + if ok <> 0 then + strm.print("Check the serial port and try again"); + else + for i in 1:10 loop + digital_out := sComm.cmd_digital_out(1, 30, 0) "This will turn off the LED"; + sComm.delay(500) "Delay for 0.5 seconds"; + digital_out := sComm.cmd_digital_out(1, 30, 1) "This turns the Led"; + sComm.delay(500) "Delay for 0.5 seconds"; + end for; + end if; + c_ok := sComm.close_serial(1) "To close the connection safely"; + end when; + annotation( + experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-6, Interval = 10)); + end led_blink; + + model led_green_blink "This will turn on and turn off the green LED for every second for 5 times" + extends Modelica.Icons.Example; + import sComm = Arduino.SerialCommunication.Functions; + import strm = Modelica.Utilities.Streams; + Integer ok(fixed = false); + Integer digital_out(fixed = false); + Integer c_ok(fixed = false); + algorithm + when initial() then + ok := sComm.open_serial(1, 0, 115200) "At port 0 with baudrate of 115200"; + sComm.delay(1000); + if ok <> 0 then + strm.print("Check the serial port and try again"); + else + for i in 1:10 loop + digital_out := sComm.cmd_digital_out(1, 10, 0) "This will turn off the green LED"; + sComm.delay(1000) "Delay for 1 second"; + digital_out := sComm.cmd_digital_out(1, 10, 1) "This turns the green Led"; + sComm.delay(1000) "Delay for 1 second"; + end for; + end if; + strm.print(String(time)); + c_ok := sComm.close_serial(1) "To close the connection safely"; + end when; + annotation( + experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-6, Interval = 10)); + end led_green_blink; + end led; + + package push + extends Modelica.Icons.ExamplesPackage; + + model led_push_button "Conrolling LED with PushButton" + extends Modelica.Icons.Example; + import sComm = Arduino.SerialCommunication.Functions; + import strm = Modelica.Utilities.Streams; + Integer ok(fixed = false); + Integer digital_in(fixed = false); + Integer digital_out(fixed = false); + Integer c_ok(fixed = false); + algorithm + when initial() then + ok := sComm.open_serial(1, 0, 115200) "At port 0 with baudrate of 115200"; + end when; + if ok <> 0 then + strm.print("Unable to open serial port, please check"); + else + digital_in := sComm.cmd_digital_in(1, 12) "Read from digital pin 12"; + if digital_in == 0 then + digital_out := sComm.cmd_digital_out(1, 9, 0) "This will turn OFF the blue LED"; + sComm.delay(200); + else + digital_out := sComm.cmd_digital_out(1, 9, 1) "This will turn ON the blue LED"; + sComm.delay(200); + end if; + end if; +//for i in 1:1000 loop +//end for; +//strm.print(String(time)); + when terminal() then + c_ok := sComm.close_serial(1) "To close the connection safely"; + end when; + annotation( + experiment(StartTime = 0, StopTime = 1, Tolerance = 1e-6, Interval = 0.01)); + end led_push_button; + + model push_button_status "Checking Status of PushButton" + extends Modelica.Icons.Example; + import sComm = Arduino.SerialCommunication.Functions; + import strm = Modelica.Utilities.Streams; + Integer ok(fixed = false); + Integer digital_in(fixed = false); + Integer digital_out(start = 0, fixed = false); + Integer c_ok(fixed = false); + algorithm + when initial() then + ok := sComm.open_serial(1, 1, 115200) "At port 0 with baudrate of 115200"; + end when; + if ok <> 0 then + strm.print("Unable to open serial port, please check"); + else + digital_in := sComm.cmd_digital_in(1, 12); + if digital_in == 0 then + digital_out := sComm.cmd_digital_out(1, 9, 0) "This will turn OFF the blue LED"; + strm.print("LOW"); + sComm.delay(200); + else + digital_out := sComm.cmd_digital_out(1, 9, 1) "This will turn ON the blue LED"; + strm.print("HIGH"); + sComm.delay(200); + end if; + end if; +//for i in 1:1000 loop +//end for; + when terminal() then + c_ok := sComm.close_serial(1) "To close the connection safely"; + end when; +//sComm.cmd_arduino_meter(digital_in); + annotation( + experiment(StartTime = 0, StopTime = 1, Tolerance = 1e-6, Interval = 0.01)); + end push_button_status; + end push; + + package ldr + extends Modelica.Icons.ExamplesPackage; + + model ldr_led "LED indicating light sensor readings" + extends Modelica.Icons.Example; + import sComm = Arduino.SerialCommunication.Functions; + import strm = Modelica.Utilities.Streams; + Integer ok(fixed = false); + Integer analog_in(fixed = false); + Integer digital_out(fixed = false); + Integer c_ok(fixed = false); + algorithm + when initial() then + ok := sComm.open_serial(1, 2, 115200) "At port 0 with baudrate of 115200"; + sComm.delay(2000); + end when; + if ok <> 0 then + strm.print("Unable to open serial port, please check"); + else + analog_in := sComm.cmd_analog_in(1, 5) "read analog pin 5 (ldr)"; + strm.print(String(analog_in)); + if analog_in < 300 then + digital_out := sComm.cmd_digital_out(1, 9, 1) "Turn ON LED"; + else + digital_out := sComm.cmd_digital_out(1, 9, 0) "Turn OFF LED"; + end if; + sComm.delay(200); + end if; +//for i in 1:500 loop +//end for; +//strm.print(String(time)); + when terminal() then + c_ok := sComm.close_serial(1) "To close the connection safely"; + end when; +//Run for 500 iterations +//Setting Threshold value of 300 + annotation( + experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-6, Interval = 0.02)); + end ldr_led; + + model ldr_read "Reading light intensity using ldr" + extends Modelica.Icons.Example; + import sComm = Arduino.SerialCommunication.Functions; + import strm = Modelica.Utilities.Streams; + Integer ok(fixed = false); + Integer analog_in(fixed = false); + Integer c_ok(fixed = false); + algorithm + when initial() then + ok := sComm.open_serial(1, 2, 115200) "At port 0 with baudrate of 115200"; + sComm.delay(2000); + end when; + if ok <> 0 then + strm.print("Unable to open serial port, please check"); + else + analog_in := sComm.cmd_analog_in(1, 5) "read analog pin 5 (ldr)"; + strm.print("LDR Readings at time " + String(time) + " : " + String(analog_in)); + sComm.delay(500); + end if; +//for i in 1:10 loop +//end for; + when terminal() then + c_ok := sComm.close_serial(1) "To close the connection safely"; + end when; +//Run for 10 iterations + annotation( + experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-6, Interval = 1)); + end ldr_read; + end ldr; + + package pot + extends Modelica.Icons.ExamplesPackage; + + model pot_threshold + extends Modelica.Icons.Example; + import sComm = Arduino.SerialCommunication.Functions; + import strm = Modelica.Utilities.Streams; + Integer ok(fixed = false); + Integer analog_in(fixed = false); + Integer digital_out(fixed = false); + Integer c_ok(fixed = false); + algorithm + when initial() then + ok := sComm.open_serial(1, 0, 115200) "At port 0 with baudrate of 115200"; + sComm.delay(1000); + end when; + if ok <> 0 then + strm.print("Unable to open serial port, please check"); + else + analog_in := sComm.cmd_analog_in(1, 2) "read analog pin 2"; + strm.print("Potentiometer Readings:" + String(analog_in)); + if analog_in >= 0 and analog_in < 320 then + digital_out := sComm.cmd_digital_out(1, 11, 1) "Turn ON LED"; + sComm.delay(1000); + digital_out := sComm.cmd_digital_out(1, 11, 0) "Turn OFF LED"; + elseif analog_in >= 320 and analog_in <= 900 then + digital_out := sComm.cmd_digital_out(1, 10, 1) "Turn ON LED"; + sComm.delay(1000); + digital_out := sComm.cmd_digital_out(1, 10, 0) "Turn OFF LED"; + elseif analog_in > 900 and analog_in <= 1023 then + digital_out := sComm.cmd_digital_out(1, 9, 1) "Turn ON LED"; + sComm.delay(1000); + digital_out := sComm.cmd_digital_out(1, 9, 0) "Turn OFF LED"; + end if; + end if; +//for i in 1:10 loop +//end for; + when terminal() then + c_ok := sComm.close_serial(1) "To close the connection safely"; + end when; +//Run for 10 iterations +//Threshold 1 +//Threshold 2 + annotation( + experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-6, Interval = 0.01)); + end pot_threshold; + end pot; + + package thermistor + extends Modelica.Icons.ExamplesPackage; + + model therm_buzzer "Sound buzzer depending on thermistor readings" + extends Modelica.Icons.Example; + import sComm = Arduino.SerialCommunication.Functions; + import strm = Modelica.Utilities.Streams; + Integer ok(fixed = false); + Integer analog_in(fixed = false); + Integer digital_out(fixed = false); + Integer c_ok(fixed = false); + algorithm + when initial() then + ok := sComm.open_serial(1, 0, 115200) "At port 0 with baudrate of 115200"; + sComm.delay(2000); + end when; + if ok <> 0 then + strm.print("Unable to open serial port, please check"); + else + analog_in := sComm.cmd_analog_in(1, 4) "read analog pin 4"; + if analog_in > 500 then + digital_out := sComm.cmd_digital_out(1, 3, 1) "Turn ON Buzzer"; + else + digital_out := sComm.cmd_digital_out(1, 3, 0) "Turn OFF Buzzer"; + end if; + sComm.delay(200); + end if; +//for i in 1:500 loop +//end for; +//Run for 500 iterations +//Setting Threshold value of 500 + when terminal() then + c_ok := sComm.close_serial(1) "To close the connection safely"; + end when; + annotation( + experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-6, Interval = 0.02)); + end therm_buzzer; + + model therm_read "Thermistor Readings" + extends Modelica.Icons.Example; + import sComm = Arduino.SerialCommunication.Functions; + import strm = Modelica.Utilities.Streams; + Integer ok(fixed = false); + Integer analog_in(fixed = false); + Integer c_ok(fixed = false); + algorithm + when initial() then + ok := sComm.open_serial(1, 0, 115200) "At port 0 with baudrate of 115200"; + sComm.delay(2000); + end when; + if ok <> 0 then + strm.print("Unable to open serial port, please check"); + else + analog_in := sComm.cmd_analog_in(1, 4) "read analog pin 5 (ldr)"; + strm.print("Thermistor Readings " + " : " + String(analog_in)); + sComm.delay(500); + end if; +//for i in 1:20 loop +//end for; + when terminal() then + c_ok := sComm.close_serial(1) "To close the connection safely"; + end when; +//Run for 20 iterations + annotation( + experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-6, Interval = 0.5)); + end therm_read; + end thermistor; + + package dcmotor + extends Modelica.Icons.ExamplesPackage; + + model dcmotor_clock "Rotate DC Motor clockwise" + extends Modelica.Icons.Example; + import sComm = Arduino.SerialCommunication.Functions; + import strm = Modelica.Utilities.Streams; + Integer ok(fixed = false); + Integer c_ok(fixed = false); + algorithm + when initial() then + ok := sComm.open_serial(1, 0, 115200) "COM port is 0 and baud rate is 115200"; + if ok <> 0 then + strm.print("Unable to open serial port, please check"); + else + sComm.delay(2000); + sComm.cmd_dcmotor_setup(1, 3, 1, 9, 10) "Setup DC motor of type 3 (L293D), motor 1, pin 9 and 10"; + sComm.cmd_dcmotor_run(1, 1, 100) "Motor 1 runs at PWM 100"; + sComm.delay(3000) "This is allowed to continue for 3 seconds"; + sComm.cmd_dcmotor_release(1, 1) "Motor 1 is released"; + end if; + c_ok := sComm.close_serial(1) "To close the connection safely"; + end when; + annotation( + experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-6, Interval = 10)); + end dcmotor_clock; + + model dcmotor_both "Rotate DC Motor in both directions" + extends Modelica.Icons.Example; + import sComm = Arduino.SerialCommunication.Functions; + import strm = Modelica.Utilities.Streams; + Integer ok(fixed = false); + Integer c_ok(fixed = false); + algorithm + when initial() then + ok := sComm.open_serial(1, 0, 115200) "COM port is 0 and baud rate is 115200"; + if ok <> 0 then + strm.print("Unable to open serial port, please check"); + else + sComm.delay(2000); + sComm.cmd_dcmotor_setup(1, 3, 1, 9, 10) "Setup DC motor of type 3 (L293D), motor 1, pin 9 and 10"; + sComm.cmd_dcmotor_run(1, 1, 255) "Motor 1 runs at PWM 100"; + sComm.delay(3000) "for 3 seconds"; + sComm.cmd_dcmotor_run(1, 1, -255) "Motor 1 runs at PWM -100 in reverse direction"; + sComm.delay(2000) "for 2 seconds"; + sComm.cmd_dcmotor_release(1, 1) "Motor 1 is released"; + end if; + c_ok := sComm.close_serial(1) "To close the connection safely"; + end when; + annotation( + experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-6, Interval = 10)); + end dcmotor_both; + + model dcmotor_loop "Rotate DC Motor in both directions in a loop" + extends Modelica.Icons.Example; + import sComm = Arduino.SerialCommunication.Functions; + import strm = Modelica.Utilities.Streams; + Integer ok(fixed = false); + Integer c_ok(fixed = false); + algorithm + when initial() then + ok := sComm.open_serial(1, 0, 115200) "COM port is 0 and baud rate is 115200"; + if ok <> 0 then + strm.print("Unable to open serial port, please check"); + else + for i in 1:4 loop + sComm.cmd_dcmotor_setup(1, 3, 1, 9, 10) "Setup DC motor of type 3 (L293D), motor 1, pins 9 and 10"; + sComm.cmd_dcmotor_run(1, 1, 100) "Motor 1 runs at PWM 100"; + sComm.delay(2000) "for 3 seconds"; + sComm.cmd_dcmotor_run(1, 1, 0) "Halt the motor"; + sComm.delay(2000) "for 2 seconds"; + sComm.cmd_dcmotor_run(1, 1, -100) "Run it at PWM 100 in reverse direction"; + sComm.delay(2000) "for 2 seconds"; + sComm.cmd_dcmotor_release(1, 1) "Motor 1 is released"; + end for; + end if; + c_ok := sComm.close_serial(1) "To close the connection safely"; + end when; + annotation( + experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-6, Interval = 10)); + end dcmotor_loop; + end dcmotor; + + package servo + extends Modelica.Icons.ExamplesPackage; + + model servo_init "Rotate Servo Motor by 30 degrees.After the roataion reset it by 0" + extends Modelica.Icons.Example; + import sComm = Arduino.SerialCommunication.Functions; + import strm = Modelica.Utilities.Streams; + Integer ok(fixed = false); + Integer c_ok(fixed = false); + algorithm + when initial() then + ok := sComm.open_serial(1, 0, 115200) "COM port is 0 and baud rate is 115200"; + if ok <> 0 then + strm.print("Check the serial port and try again"); + else + sComm.delay(2000); + sComm.cmd_servo_attach(1, 1) "To attach the motor to pin 9 of servo1"; + sComm.cmd_servo_move(1, 1, 0) "tell servo to rotate by 30 degrees"; + sComm.delay(3000); + end if; + c_ok := sComm.close_serial(1) "To close the connection safely"; + end when; + annotation( + experiment(StartTime = 0, StopTime = 5, Tolerance = 1e-6, Interval = 5)); + end servo_init; + + model servo_loop "Rotate servo motor by 20 degrees 10 times" + extends Modelica.Icons.Example; + import sComm = Arduino.SerialCommunication.Functions; + import strm = Modelica.Utilities.Streams; + Integer ok(fixed = false); + Integer c_ok(fixed = false); + Integer angle(fixed = true); + algorithm + when initial() then + ok := sComm.open_serial(1, 0, 115200) "COM port is 0 and baud rate is 115200"; + if ok <> 0 then + strm.print("Check the serial port and try again"); + else + sComm.delay(2000); + sComm.cmd_servo_attach(1, 1) "Attach motor to pin 9. 1 means pin 9."; + sComm.delay(2000); + angle := 20 "Angle by which it has to move"; + for i in 1:10 loop + sComm.cmd_servo_move(1, 1, angle * i) "tell servo to rotate by 20 degrees"; + sComm.delay(1000) "waits for a sec"; + end for; + end if; + c_ok := sComm.close_serial(1) "To close the connection safely"; + end when; +//sComm.cmd_servo_detach(1, 1) "Detach the motor"; + annotation( + experiment(StartTime = 0, StopTime = 5, Tolerance = 1e-6, Interval = 5)); + end servo_loop; + + model servo_reverse + extends Modelica.Icons.Example; + import sComm = Arduino.SerialCommunication.Functions; + import strm = Modelica.Utilities.Streams; + Integer ok(fixed = false); + Integer c_ok(fixed = false); + algorithm + when initial() then + ok := sComm.open_serial(1, 0, 115200) "COM port is 0 and baud rate is 115200"; + if ok <> 0 then + strm.print("Check the serial port and try again"); + else + sComm.delay(2000); + sComm.cmd_servo_attach(1, 1) "Attach the motor to pin 9. 1 means 9"; + sComm.cmd_servo_move(1, 1, 90) "Move the servo to 90 degree"; + sComm.delay(1000) "be there for one second"; + sComm.cmd_servo_move(1, 1, 45) "Move the servo to 45 degree"; + sComm.delay(1000) "be there for one second"; + sComm.delay(1000); + end if; + c_ok := sComm.close_serial(1) "To close the connection safely"; + end when; +//sComm.cmd_servo_detach(1, 1) "Detach the motor"; + annotation( + experiment(StartTime = 0, StopTime = 5, Tolerance = 1e-6, Interval = 5)); + end servo_reverse; + + model servo_pot "Control Servo Motor using Potentiometer" + extends Modelica.Icons.Example; + import sComm = Arduino.SerialCommunication.Functions; + import strm = Modelica.Utilities.Streams; + Integer ok(fixed = false); + Integer c_ok(fixed = false); + Integer analog_in(fixed = false); + algorithm + when initial() then + ok := sComm.open_serial(1, 0, 115200) "COM port is 0 and baud rate is 115200"; + if ok <> 0 then + strm.print("Check the serial port and try again"); + else + sComm.delay(2000); + sComm.cmd_servo_attach(1, 1) "Attach the motor to pin 9"; + sComm.delay(2000); + for i in 1:5000 loop + analog_in := sComm.cmd_analog_in(1, 2) "Read potentiometer value"; + analog_in := sComm.math_floor(analog_in * (180 / 1023)) "Scale Potentiometer value to 0-180"; + sComm.cmd_servo_move(1, 1, analog_in) "Command the servo motor"; + sComm.delay(1000) "sleep for 500 milliseconds"; + strm.print("Potentiometer Reading at time" + String(time) + " : " + String(analog_in)); + end for; + end if; + sComm.cmd_servo_detach(1, 1) "Detach the motor"; + sComm.delay(5000); + c_ok := sComm.close_serial(1) "To close the connection safely"; + end when; +//5,000 itterations + annotation( + experiment(StartTime = 0, StopTime = 5, Tolerance = 1e-6, Interval = 5)); + end servo_pot; + end servo; + + package modbus + extends Modelica.Icons.ExamplesPackage; + + function read_voltage + extends Modelica.Icons.Function; + + external read_voltage() annotation( + Library = "Modbus"); + annotation( + Documentation(info = "<html> + <h4>Syntax</h4> + <blockquote><pre> + Arduino.SerialCommunication.Examples.modbus.<b>read_voltage</b>(); + </pre></blockquote> + <h4>Description</h4> + <p> + </p> + </html>")); + end read_voltage; + + function read_current + extends Modelica.Icons.Function; + + external read_voltage() annotation( + Library = "Modbus"); + annotation( + Documentation(info = "<html> + <h4>Syntax</h4> + <blockquote><pre> + Arduino.SerialCommunication.Examples.modbus.<b>read_current</b>(); + </pre></blockquote> + <h4>Description</h4> + <p> + </p> + </html>")); + end read_current; + + function read_val + extends Modelica.Icons.Function; + input Integer addr_byte; + output Real p; + + external p = read_val(addr_byte) annotation( + Library = "Modbus"); + annotation( + Documentation(info = "<html> + <h4>Syntax</h4> + <blockquote><pre> + Arduino.SerialCommunication.Examples.modbus.<b>read_val</b>(address_byte); + </pre></blockquote> + <h4>Description</h4> + <p> + </p> + </html>")); + end read_val; + + function read_active_power + extends Modelica.Icons.Function; + + external read_active_power() annotation( + Library = "Modbus"); + annotation( + Documentation(info = "<html> + <h4>Syntax</h4> + <blockquote><pre> + Arduino.SerialCommunication.Examples.modbus.<b>read_active_power</b>(); + </pre></blockquote> + <h4>Description</h4> + <p> + </p> + </html>")); + end read_active_power; + + model modbus_test + extends Modelica.Icons.Example; + import sComm = Arduino.SerialCommunication.Functions; + import modbus = Arduino.SerialCommunication.Examples.modbus; + Integer ok(fixed = false); + Integer c_ok(fixed = false); + algorithm + when initial() then + ok := sComm.open_serial(1, 0, 9600); + modbus.read_voltage(); + modbus.read_current(); + modbus.read_active_power(); + c_ok := sComm.close_serial(1); + end when; + end modbus_test; + end modbus; + end Examples; + + package MDD_Examples "Interfacing arduino with OpenModelica using Modelica Device Drivers" + extends Modelica.Icons.ExamplesPackage; + + package MDD_led + extends Modelica.Icons.ExamplesPackage; + + model MDD_led_blue "" + extends Modelica.Icons.Example; + inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation( + Placement(visible = true, transformation(origin = {-44, 66}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation( + Placement(visible = true, transformation(origin = {39, 41}, extent = {{-17, -17}, {17, 17}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.DigitalWriteBoolean digitalWriteBoolean1(pin = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Pin.'1', port = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Port.B) annotation( + Placement(visible = true, transformation(origin = {39, -21}, extent = {{-19, -19}, {19, 19}}, rotation = 0))); + Modelica.Blocks.Sources.BooleanExpression booleanExpression1(y = true) annotation( + Placement(visible = true, transformation(origin = {-41, -21}, extent = {{-15, -17}, {15, 17}}, rotation = 0))); + equation + connect(booleanExpression1.y, digitalWriteBoolean1.u) annotation( + Line(points = {{-24, -20}, {14, -20}, {14, -20}, {16, -20}}, color = {255, 0, 255})); + annotation( + Documentation(info = "<html> + <h4>Syntax</h4> + <blockquote><pre> + Arduino.SerialCommunication.MDD_Examples.MDD_led.<b>MDD-led_blue</b>(); + </pre></blockquote> + <h4>Description</h4> + <p> + </p> + </html>")); + end MDD_led_blue; + + model MDD_led_blue_delay + extends Modelica.Icons.Example; + inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation( + Placement(visible = true, transformation(origin = {-40, 40}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation( + Placement(visible = true, transformation(origin = {31, 41}, extent = {{-19, -19}, {19, 19}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.DigitalWriteBoolean digitalWriteBoolean1(pin = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Pin.'1', port = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Port.B) annotation( + Placement(visible = true, transformation(origin = {41, -17}, extent = {{-17, -17}, {17, 17}}, rotation = 0))); + Modelica.Blocks.Sources.BooleanExpression booleanExpression1(y = if time < 5 then true else false) annotation( + Placement(visible = true, transformation(origin = {-27, -16}, extent = {{-21, -16}, {21, 16}}, rotation = 0))); + equation + connect(booleanExpression1.y, digitalWriteBoolean1.u) annotation( + Line(points = {{-4, -16}, {20, -16}}, color = {255, 0, 255})); + end MDD_led_blue_delay; + + model MDD_led_blink + extends Modelica.Icons.Example; + inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation( + Placement(visible = true, transformation(origin = {-45, 71}, extent = {{-23, -23}, {23, 23}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.DigitalWriteBoolean digitalWriteBoolean1(pin = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Pin.'5', port = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Port.B) annotation( + Placement(visible = true, transformation(origin = {42, -22}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation( + Placement(visible = true, transformation(origin = {23, 71}, extent = {{-19, -19}, {19, 19}}, rotation = 0))); + Modelica.Blocks.Sources.BooleanExpression booleanExpression1(y = mod(time, 2) >= 1) annotation( + Placement(visible = true, transformation(origin = {-24, -21}, extent = {{-16, -15}, {16, 15}}, rotation = 0))); + equation + connect(booleanExpression1.y, digitalWriteBoolean1.u) annotation( + Line(points = {{-6, -21}, {16, -21}, {16, -22}, {18, -22}}, color = {255, 0, 255})); + end MDD_led_blink; + + model MDD_led_blue_red + extends Modelica.Icons.Example; + inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation( + Placement(visible = true, transformation(origin = {-47, 47}, extent = {{-21, -21}, {21, 21}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.DigitalWriteBoolean digitalWriteBoolean1(pin = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Pin.'1', port = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Port.B) annotation( + Placement(visible = true, transformation(origin = {38, -16}, extent = {{-16, -16}, {16, 16}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation( + Placement(visible = true, transformation(origin = {40, 44}, extent = {{-18, -18}, {18, 18}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.DigitalWriteBoolean digitalWriteBoolean2(pin = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Pin.'3', port = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Port.B) annotation( + Placement(visible = true, transformation(origin = {38, -62}, extent = {{-16, -16}, {16, 16}}, rotation = 0))); + Modelica.Blocks.Sources.BooleanExpression booleanExpression1(y = if time < 5 then true else false) annotation( + Placement(visible = true, transformation(origin = {-32, -16}, extent = {{-18, -14}, {18, 14}}, rotation = 0))); + Modelica.Blocks.Sources.BooleanExpression booleanExpression2(y = if time < 8 then true else false) annotation( + Placement(visible = true, transformation(origin = {-32, -62}, extent = {{-18, -16}, {18, 16}}, rotation = 0))); + equation + connect(digitalWriteBoolean2.u, booleanExpression2.y) annotation( + Line(points = {{18, -62}, {-12, -62}, {-12, -62}, {-12, -62}}, color = {255, 0, 255})); + connect(booleanExpression2.y, digitalWriteBoolean2.u) annotation( + Line(points = {{-12, -62}, {18, -62}, {18, -62}, {18, -62}}, color = {255, 0, 255})); + connect(booleanExpression1.y, digitalWriteBoolean1.u) annotation( + Line(points = {{-12, -16}, {18, -16}, {18, -16}, {18, -16}}, color = {255, 0, 255})); + end MDD_led_blue_red; + + model MDD_led_green_blink + extends Modelica.Icons.Example; + inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation( + Placement(visible = true, transformation(origin = {-40, 40}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.DigitalWriteBoolean digitalWriteBoolean1(pin = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Pin.'2', port = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Port.B) annotation( + Placement(visible = true, transformation(origin = {46, -30}, extent = {{-18, -18}, {18, 18}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation( + Placement(visible = true, transformation(origin = {39, 39}, extent = {{-19, -19}, {19, 19}}, rotation = 0))); + Modelica.Blocks.Sources.BooleanExpression booleanExpression1(y = mod(time, 2) >= 1) annotation( + Placement(visible = true, transformation(origin = {-17, -30}, extent = {{-15, -14}, {15, 14}}, rotation = 0))); + equation + connect(booleanExpression1.y, digitalWriteBoolean1.u) annotation( + Line(points = {{0, -30}, {24, -30}, {24, -30}, {24, -30}}, color = {255, 0, 255})); + end MDD_led_green_blink; + + model MDD_traffic_light "" + extends Modelica.Icons.Example; + inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega16) annotation( + Placement(visible = true, transformation(origin = {-44, 42}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer1) annotation( + Placement(visible = true, transformation(origin = {39, 41}, extent = {{-17, -17}, {17, 17}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.DigitalWriteBoolean digitalWriteBoolean1(pin = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Pin.'4', port = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Port.A) annotation( + Placement(visible = true, transformation(origin = {39, -21}, extent = {{-19, -19}, {19, 19}}, rotation = 0))); + Modelica.Blocks.Sources.BooleanExpression booleanExpression1(y = true) annotation( + Placement(visible = true, transformation(origin = {-41, -21}, extent = {{-15, -17}, {15, 17}}, rotation = 0))); + equation + connect(booleanExpression1.y, digitalWriteBoolean1.u) annotation( + Line(points = {{-24, -20}, {14, -20}, {14, -20}, {16, -20}}, color = {255, 0, 255})); + annotation( + Documentation(info = "<html> + <h4>Syntax</h4> + <blockquote><pre> + Arduino.SerialCommunication.MDD_Examples.MDD_led.<b>MDD-led_blue</b>(); + </pre></blockquote> + <h4>Description</h4> + <p> + </p> + </html>")); + end MDD_traffic_light; + end MDD_led; + + package MDD_push + extends Modelica.Icons.ExamplesPackage; + + model MDD_led_push_button + extends Modelica.Icons.Example; + inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation( + Placement(visible = true, transformation(origin = {-46, 62}, extent = {{-18, -18}, {18, 18}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation( + Placement(visible = true, transformation(origin = {39, 41}, extent = {{-17, -17}, {17, 17}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.DigitalReadBoolean digitalReadBoolean1(pin = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Pin.'4', port = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Port.B) annotation( + Placement(visible = true, transformation(origin = {-44, -28}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.DigitalWriteBoolean digitalWriteBoolean1(pin = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Pin.'1', port = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Port.B) annotation( + Placement(visible = true, transformation(origin = {62, -28}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Logical.LogicalSwitch logicalSwitch1 annotation( + Placement(visible = true, transformation(origin = {8, -28}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Sources.BooleanExpression booleanExpression1(y = true) annotation( + Placement(visible = true, transformation(origin = {-32, 18}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Sources.BooleanExpression booleanExpression2(y = false) annotation( + Placement(visible = true, transformation(origin = {-32, -70}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + equation + connect(booleanExpression2.y, logicalSwitch1.u3) annotation( + Line(points = {{-20, -70}, {-16, -70}, {-16, -36}, {-4, -36}, {-4, -36}}, color = {255, 0, 255})); + connect(booleanExpression1.y, logicalSwitch1.u1) annotation( + Line(points = {{-20, 18}, {-14, 18}, {-14, -20}, {-4, -20}, {-4, -20}}, color = {255, 0, 255})); + connect(logicalSwitch1.y, digitalWriteBoolean1.u) annotation( + Line(points = {{20, -28}, {50, -28}, {50, -28}, {50, -28}}, color = {255, 0, 255})); + connect(digitalReadBoolean1.y, logicalSwitch1.u2) annotation( + Line(points = {{-32, -28}, {-4, -28}}, color = {255, 0, 255})); + end MDD_led_push_button; + + model MDD_push_button_status + extends Modelica.Icons.Example; + inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation( + Placement(visible = true, transformation(origin = {-43, 43}, extent = {{-19, -19}, {19, 19}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation( + Placement(visible = true, transformation(origin = {20, 42}, extent = {{-18, -18}, {18, 18}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.DigitalReadBoolean digitalReadBoolean1(pin = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Pin.'4', port = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Port.B) annotation( + Placement(visible = true, transformation(origin = {-39, -19}, extent = {{-19, -19}, {19, 19}}, rotation = 0))); + Modelica.Blocks.Interaction.Show.BooleanValue booleanValue1(use_activePort = true) annotation( + Placement(visible = true, transformation(origin = {31, -19}, extent = {{-15, -17}, {15, 17}}, rotation = 0))); + equation + connect(digitalReadBoolean1.y, booleanValue1.activePort) annotation( + Line(points = {{-18, -18}, {14, -18}, {14, -18}, {14, -18}}, color = {255, 0, 255})); + end MDD_push_button_status; + + model pushTest1 + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.DigitalReadBoolean digitalReadBoolean1(pin = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Pin.'4', port = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Port.B) annotation( + Placement(visible = true, transformation(origin = {-60, -2}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.DigitalWriteBoolean digitalWriteBoolean1(pin = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Pin.'1', port = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Port.B) annotation( + Placement(visible = true, transformation(origin = {60, -2}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Logical.LogicalSwitch logicalSwitch1 annotation( + Placement(visible = true, transformation(origin = {-2, -2}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Sources.BooleanExpression booleanExpression1 annotation( + Placement(visible = true, transformation(origin = {-44, 62}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Sources.BooleanExpression booleanExpression2(y = true) annotation( + Placement(visible = true, transformation(origin = {-46, -58}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + equation + connect(logicalSwitch1.y, digitalWriteBoolean1.u) annotation( + Line(points = {{10, -2}, {48, -2}, {48, -2}, {48, -2}}, color = {255, 0, 255})); + connect(digitalReadBoolean1.y, logicalSwitch1.u2) annotation( + Line(points = {{-48, -2}, {-14, -2}, {-14, -2}, {-14, -2}}, color = {255, 0, 255})); + connect(booleanExpression2.y, logicalSwitch1.u3) annotation( + Line(points = {{-34, -58}, {-24, -58}, {-24, -10}, {-14, -10}, {-14, -10}}, color = {255, 0, 255})); + connect(booleanExpression1.y, logicalSwitch1.u1) annotation( + Line(points = {{-32, 62}, {-28, 62}, {-28, 6}, {-14, 6}, {-14, 6}}, color = {255, 0, 255})); + annotation( + uses(Modelica_DeviceDrivers(version = "1.5.0"), Modelica(version = "3.2.2"))); + end pushTest1; + end MDD_push; + + package MDD_ldr + extends Modelica.Icons.ExamplesPackage; + + model MDD_ldr_led + extends Modelica.Icons.Example; + inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation( + Placement(visible = true, transformation(origin = {-45, 65}, extent = {{-21, -21}, {21, 21}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation( + Placement(visible = true, transformation(origin = {38, 60}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.DigitalWriteBoolean digitalWriteBoolean1(pin = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Pin.'1', port = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Port.B) annotation( + Placement(visible = true, transformation(origin = {79, -23}, extent = {{-17, -17}, {17, 17}}, rotation = 0))); + Modelica.Blocks.Sources.BooleanExpression booleanExpression1(y = true) annotation( + Placement(visible = true, transformation(origin = {-60, 12}, extent = {{-14, -16}, {14, 16}}, rotation = 0))); + Modelica.Blocks.Sources.BooleanExpression booleanExpression2 annotation( + Placement(visible = true, transformation(origin = {-59, -79}, extent = {{-13, -17}, {13, 17}}, rotation = 0))); + Modelica.Blocks.Logical.LogicalSwitch logicalSwitch1 annotation( + Placement(visible = true, transformation(origin = {28, -22}, extent = {{-16, -16}, {16, 16}}, rotation = 0))); + Modelica.Blocks.Logical.GreaterThreshold greaterThreshold1(threshold = 600) annotation( + Placement(visible = true, transformation(origin = {-21, -23}, extent = {{-11, -11}, {11, 11}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.ADC adc(analogPort = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.AnalogPort.A5, prescaler = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.AnalogPrescaler.'1/128', voltageReference = 1024, voltageReferenceSelect = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.VRefSelect.Internal) annotation( + Placement(visible = true, transformation(origin = {-72, -22}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + equation + connect(adc.y, greaterThreshold1.u) annotation( + Line(points = {{-50, -22}, {-34, -22}}, color = {0, 0, 127})); + connect(greaterThreshold1.y, logicalSwitch1.u2) annotation( + Line(points = {{-8, -22}, {8, -22}, {8, -22}, {8, -22}}, color = {255, 0, 255})); + connect(logicalSwitch1.y, digitalWriteBoolean1.u) annotation( + Line(points = {{46, -22}, {58, -22}, {58, -22}, {58, -22}}, color = {255, 0, 255})); + connect(booleanExpression1.y, logicalSwitch1.u1) annotation( + Line(points = {{-44, 12}, {8, 12}, {8, -10}, {8, -10}}, color = {255, 0, 255})); + connect(booleanExpression2.y, logicalSwitch1.u3) annotation( + Line(points = {{-44, -78}, {6, -78}, {6, -34}, {8, -34}}, color = {255, 0, 255})); + end MDD_ldr_led; + + model MDD_ldr_read + extends Modelica.Icons.Example; + inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation( + Placement(visible = true, transformation(origin = {-37, 39}, extent = {{-19, -19}, {19, 19}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation( + Placement(visible = true, transformation(origin = {50, 38}, extent = {{-22, -22}, {22, 22}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.ADC adc(analogPort = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.AnalogPort.A5, prescaler = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.AnalogPrescaler.'1/128', voltageReference = 1024, voltageReferenceSelect = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.VRefSelect.Internal) annotation( + Placement(visible = true, transformation(origin = {-39, -17}, extent = {{-17, -17}, {17, 17}}, rotation = 0))); + Modelica.Blocks.Interaction.Show.RealValue realValue1(use_numberPort = true) annotation( + Placement(visible = true, transformation(origin = {30, -17}, extent = {{-18, -17}, {18, 17}}, rotation = 0))); + equation + connect(adc.y, realValue1.numberPort) annotation( + Line(points = {{-20, -17}, {7, -17}}, color = {0, 0, 127})); + end MDD_ldr_read; + end MDD_ldr; + + package MDD_pot + extends Modelica.Icons.ExamplesPackage; + + model MDD_pot_threshold "" + extends Modelica.Icons.Example; + inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation( + Placement(visible = true, transformation(origin = {-79, 79}, extent = {{-19, -19}, {19, 19}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation( + Placement(visible = true, transformation(origin = {80, 80}, extent = {{-18, -18}, {18, 18}}, rotation = 0))); + Modelica.Blocks.Logical.Switch switch11 annotation( + Placement(visible = true, transformation(origin = {2, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Logical.Switch switch12 annotation( + Placement(visible = true, transformation(origin = {10, -64}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Logical.Greater greater1 annotation( + Placement(visible = true, transformation(origin = {42, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Logical.Greater greater2 annotation( + Placement(visible = true, transformation(origin = {36, 70}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.DigitalWriteBoolean digitalWriteBoolean1(pin = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Pin.'1', port = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Port.B) annotation( + Placement(visible = true, transformation(origin = {82, 40}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.DigitalWriteBoolean digitalWriteBoolean2(pin = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Pin.'2', port = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Port.B) annotation( + Placement(visible = true, transformation(origin = {82, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.DigitalWriteBoolean digitalWriteBoolean3(pin = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Pin.'3', port = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Port.B) annotation( + Placement(visible = true, transformation(origin = {82, -64}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Logical.GreaterEqualThreshold greaterEqualThreshold1(threshold = 0) annotation( + Placement(visible = true, transformation(origin = {-42, 44}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Logical.GreaterEqualThreshold greaterEqualThreshold2(threshold = 320) annotation( + Placement(visible = true, transformation(origin = {-42, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Logical.GreaterEqualThreshold greaterEqualThreshold3(threshold = 900) annotation( + Placement(visible = true, transformation(origin = {-40, -64}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Sources.RealExpression realExpression1(y = 0) annotation( + Placement(visible = true, transformation(origin = {-40, -92}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Sources.RealExpression realExpression2(y = 1) annotation( + Placement(visible = true, transformation(origin = {-44, 84}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Logical.Switch switch1 annotation( + Placement(visible = true, transformation(origin = {0, 70}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Math.RealToBoolean realToBoolean1(threshold = 0.5) annotation( + Placement(visible = true, transformation(origin = {44, -64}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.ADC adc(analogPort = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.AnalogPort.A2, prescaler = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.AnalogPrescaler.'1/128', voltageReference = 1024, voltageReferenceSelect = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.VRefSelect.Internal) annotation( + Placement(visible = true, transformation(origin = {-88, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Interaction.Show.RealValue realValue1(significantDigits = 5, use_numberPort = true) annotation( + Placement(visible = true, transformation(origin = {-74, -84}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + equation + connect(adc.y, realValue1.numberPort) annotation( + Line(points = {{-76, 0}, {-74, 0}, {-74, -70}, {-94, -70}, {-94, -84}, {-86, -84}, {-86, -84}}, color = {0, 0, 127})); + connect(adc.y, greaterEqualThreshold1.u) annotation( + Line(points = {{-76, 0}, {-70, 0}, {-70, 46}, {-54, 46}}, color = {0, 0, 127})); + connect(greaterEqualThreshold1.y, switch1.u2) annotation( + Line(points = {{-31, 46}, {-24, 46}, {-24, 70}, {-12, 70}}, color = {255, 0, 255})); + connect(adc.y, greaterEqualThreshold3.u) annotation( + Line(points = {{-76, 0}, {-70, 0}, {-70, -64}, {-52, -64}, {-52, -64}}, color = {0, 0, 127})); + connect(adc.y, greaterEqualThreshold2.u) annotation( + Line(points = {{-76, 0}, {-54, 0}, {-54, 0}, {-54, 0}}, color = {0, 0, 127})); + connect(realToBoolean1.y, digitalWriteBoolean3.u) annotation( + Line(points = {{56, -64}, {70, -64}, {70, -64}, {70, -64}}, color = {255, 0, 255})); + connect(switch12.y, realToBoolean1.u) annotation( + Line(points = {{22, -64}, {32, -64}, {32, -64}, {32, -64}}, color = {0, 0, 127})); + connect(realExpression1.y, switch1.u3) annotation( + Line(points = {{-28, -92}, {-16, -92}, {-16, 62}, {-12, 62}, {-12, 62}}, color = {0, 0, 127})); + connect(realExpression2.y, switch1.u1) annotation( + Line(points = {{-32, 84}, {-20, 84}, {-20, 78}, {-12, 78}, {-12, 78}}, color = {0, 0, 127})); + connect(switch1.y, greater2.u1) annotation( + Line(points = {{12, 70}, {22, 70}, {22, 70}, {24, 70}}, color = {0, 0, 127})); + connect(greater1.y, digitalWriteBoolean2.u) annotation( + Line(points = {{54, 0}, {70, 0}}, color = {255, 0, 255})); + connect(switch11.y, greater2.u2) annotation( + Line(points = {{14, 0}, {18, 0}, {18, 62}, {24, 62}, {24, 62}}, color = {0, 0, 127})); + connect(switch11.y, greater1.u1) annotation( + Line(points = {{14, 0}, {30, 0}}, color = {0, 0, 127})); + connect(switch12.y, greater1.u2) annotation( + Line(points = {{22, -64}, {22, -64}, {22, -8}, {30, -8}, {30, -8}}, color = {0, 0, 127})); + connect(greaterEqualThreshold2.y, switch11.u2) annotation( + Line(points = {{-30, 0}, {-10, 0}, {-10, 0}, {-10, 0}}, color = {255, 0, 255})); + connect(greater2.y, digitalWriteBoolean1.u) annotation( + Line(points = {{48, 70}, {56, 70}, {56, 40}, {70, 40}, {70, 40}}, color = {255, 0, 255})); + connect(realExpression2.y, switch12.u1) annotation( + Line(points = {{-32, 84}, {-20, 84}, {-20, -56}, {-2, -56}, {-2, -56}}, color = {0, 0, 127})); + connect(realExpression2.y, switch11.u1) annotation( + Line(points = {{-32, 84}, {-20, 84}, {-20, 8}, {-10, 8}, {-10, 8}}, color = {0, 0, 127})); + connect(realExpression1.y, switch11.u3) annotation( + Line(points = {{-28, -92}, {-16, -92}, {-16, -8}, {-10, -8}, {-10, -8}}, color = {0, 0, 127})); + connect(realExpression1.y, switch12.u3) annotation( + Line(points = {{-28, -92}, {-16, -92}, {-16, -72}, {-2, -72}, {-2, -72}}, color = {0, 0, 127})); + connect(greaterEqualThreshold3.y, switch12.u2) annotation( + Line(points = {{-28, -64}, {-2, -64}, {-2, -64}, {-2, -64}}, color = {255, 0, 255})); + annotation( + Documentation(info = "<html> + <h4>Syntax</h4> + <blockquote><pre> + Arduino.SerialCommunication.MDD_Examples.MDD_pot.<b>MDD_pot_threshold</b>(); + </pre></blockquote> + <h4>Description</h4> + <p>Voltage reference used to represent 10 bit precision(1024) of ADC along with prescaling by by 128.Internal voltage reference is applied to adc. + </p> + </html>")); + end MDD_pot_threshold; + end MDD_pot; + + package MDD_thermistor + extends Modelica.Icons.ExamplesPackage; + + model MDD_therm_read + extends Modelica.Icons.Example; + inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation( + Placement(visible = true, transformation(origin = {-40, 40}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation( + Placement(visible = true, transformation(origin = {40, 42}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.ADC adc(analogPort = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.AnalogPort.A4, prescaler = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.AnalogPrescaler.'1/128', voltageReference = 1024, voltageReferenceSelect = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.VRefSelect.Internal) annotation( + Placement(visible = true, transformation(origin = {-40, -20}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica.Blocks.Interaction.Show.RealValue realValue1(use_numberPort = true) annotation( + Placement(visible = true, transformation(origin = {39, -21}, extent = {{-15, -19}, {15, 19}}, rotation = 0))); + equation + connect(adc.y, realValue1.numberPort) annotation( + Line(points = {{-18, -20}, {20, -20}, {20, -20}, {22, -20}}, color = {0, 0, 127})); + end MDD_therm_read; + + model MDD_therm_buzzer + extends Modelica.Icons.Example; + inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation( + Placement(visible = true, transformation(origin = {-61, 61}, extent = {{-21, -21}, {21, 21}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.ADC adc(analogPort = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.AnalogPort.A4, prescaler = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.AnalogPrescaler.'1/128', voltageReference = 1024, voltageReferenceSelect = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.VRefSelect.Internal) annotation( + Placement(visible = true, transformation(origin = {-68, 1.77636e-15}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation( + Placement(visible = true, transformation(origin = {41, 61}, extent = {{-19, -19}, {19, 19}}, rotation = 0))); + Modelica.Blocks.Interaction.Show.RealValue realValue1(use_numberPort = true) annotation( + Placement(visible = true, transformation(origin = {12, -56}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.DigitalWriteBoolean digitalWriteBoolean1(pin = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Pin.'3', port = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Port.D) annotation( + Placement(visible = true, transformation(origin = {78, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Logical.LogicalSwitch logicalSwitch1 annotation( + Placement(visible = true, transformation(origin = {40, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Sources.BooleanExpression booleanExpression1(y = false) annotation( + Placement(visible = true, transformation(origin = {10, -32}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Sources.BooleanExpression booleanExpression2(y = true) annotation( + Placement(visible = true, transformation(origin = {10, 32}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Logical.GreaterEqualThreshold greaterEqualThreshold1(threshold = 550) annotation( + Placement(visible = true, transformation(origin = {-4, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + equation + connect(greaterEqualThreshold1.y, logicalSwitch1.u2) annotation( + Line(points = {{8, 0}, {28, 0}, {28, 0}, {28, 0}}, color = {255, 0, 255})); + connect(adc.y, greaterEqualThreshold1.u) annotation( + Line(points = {{-46, 0}, {-16, 0}, {-16, 0}, {-16, 0}}, color = {0, 0, 127})); + connect(adc.y, realValue1.numberPort) annotation( + Line(points = {{-46, 0}, {-32, 0}, {-32, -56}, {0, -56}}, color = {0, 0, 127})); + connect(logicalSwitch1.y, digitalWriteBoolean1.u) annotation( + Line(points = {{52, 0}, {66, 0}, {66, 0}, {66, 0}}, color = {255, 0, 255})); + connect(booleanExpression2.y, logicalSwitch1.u1) annotation( + Line(points = {{22, 32}, {24, 32}, {24, 8}, {28, 8}, {28, 8}}, color = {255, 0, 255})); + connect(booleanExpression1.y, logicalSwitch1.u3) annotation( + Line(points = {{22, -32}, {24, -32}, {24, -8}, {28, -8}, {28, -8}}, color = {255, 0, 255})); + end MDD_therm_buzzer; + end MDD_thermistor; + + package MDD_dcmotor + extends Modelica.Icons.ExamplesPackage; + + model MDD_dcmotor_clock + extends Modelica.Icons.Example; + inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation( + Placement(visible = true, transformation(origin = {-40, 40}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation( + Placement(visible = true, transformation(origin = {39, 41}, extent = {{-19, -19}, {19, 19}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.PWM pwm(fastPWM = true, initialValues = {0}, prescaler = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerPrescaler.'1/1024', timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer1, timerNumbers = {Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerNumber.B}) annotation( + Placement(visible = true, transformation(origin = {51, -3}, extent = {{-19, -19}, {19, 19}}, rotation = 0))); + Modelica.Blocks.Sources.IntegerExpression integerExpression1(y = if time < 5 then 255 else 0) annotation( + Placement(visible = true, transformation(origin = {-40, -3}, extent = {{-16, -13}, {16, 13}}, rotation = 0))); + equation + connect(pwm.u[1], integerExpression1.y) annotation( + Line(points = {{28, -3}, {-22, -3}}, color = {255, 127, 0}, thickness = 0.5)); + end MDD_dcmotor_clock; + + model MDD_dcmotor_both + extends Modelica.Icons.Example; + inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation( + Placement(visible = true, transformation(origin = {-40, 60}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation( + Placement(visible = true, transformation(origin = {56, 60}, extent = {{-18, -18}, {18, 18}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.PWM pwm(fastPWM = true, initialValues = {0}, prescaler = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerPrescaler.'1/1024', timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer1, timerNumbers = {Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerNumber.A}) annotation( + Placement(visible = true, transformation(origin = {54, 1.77636e-15}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica.Blocks.Sources.IntegerExpression integerExpression1(y = if mod(time, 5) >= 2.5 then 100 else 0) annotation( + Placement(visible = true, transformation(origin = {-41, 3.55271e-15}, extent = {{-23, -20}, {23, 20}}, rotation = 0))); + Modelica.Blocks.Sources.IntegerExpression integerExpression2(y = if mod(time, 5) < 2.5 then 100 else 0) annotation( + Placement(visible = true, transformation(origin = {-39, -48}, extent = {{-23, -20}, {23, 20}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.PWM pwm1(fastPWM = true, initialValues = {0}, prescaler = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerPrescaler.'1/1024', timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer1, timerNumbers = {Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerNumber.B}) annotation( + Placement(visible = true, transformation(origin = {54, -48}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + equation + connect(integerExpression2.y, pwm1.u[1]) annotation( + Line(points = {{-14, -48}, {28, -48}, {28, -48}, {30, -48}}, color = {255, 127, 0})); + connect(integerExpression1.y, pwm.u[1]) annotation( + Line(points = {{-16, 0}, {28, 0}, {28, 0}, {30, 0}}, color = {255, 127, 0})); + end MDD_dcmotor_both; + + model MDD_dcmotor_loop + extends Modelica.Icons.Example; + inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation( + Placement(visible = true, transformation(origin = {-40, 62}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation( + Placement(visible = true, transformation(origin = {40, 60}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.PWM pwm(fastPWM = true, initialValues = {0}, prescaler = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerPrescaler.'1/1024', timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer1, timerNumbers = {Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerNumber.A}) annotation( + Placement(visible = true, transformation(origin = {44, 16}, extent = {{-16, -16}, {16, 16}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.PWM pwm1(fastPWM = true, initialValues = {0}, prescaler = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerPrescaler.'1/1024', timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer1, timerNumbers = {Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerNumber.B}) annotation( + Placement(visible = true, transformation(origin = {44, -30}, extent = {{-16, -16}, {16, 16}}, rotation = 0))); + Modelica.Blocks.Sources.IntegerExpression integerExpression1(y = if mod(time, 6) < 3 then 255 else 0) annotation( + Placement(visible = true, transformation(origin = {-53, 16}, extent = {{-17, -16}, {17, 16}}, rotation = 0))); + Modelica.Blocks.Sources.IntegerExpression integerExpression2(y = if mod(time, 6) > 3 then 255 else 0) annotation( + Placement(visible = true, transformation(origin = {-52, -30}, extent = {{-16, -14}, {16, 14}}, rotation = 0))); + equation + connect(integerExpression2.y, pwm1.u[1]) annotation( + Line(points = {{-34, -30}, {24, -30}}, color = {255, 127, 0})); + connect(integerExpression1.y, pwm.u[1]) annotation( + Line(points = {{-34, 16}, {24, 16}}, color = {255, 127, 0})); + end MDD_dcmotor_loop; + end MDD_dcmotor; + + package MDD_servo + extends Modelica.Icons.ExamplesPackage; + + model MDD_servo_init + extends Modelica.Icons.Example; + inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation( + Placement(visible = true, transformation(origin = {-40, 58}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation( + Placement(visible = true, transformation(origin = {59, 59}, extent = {{-19, -19}, {19, 19}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.PWM pwm(fastPWM = true, initialValues = {0}, prescaler = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerPrescaler.'1/1024', timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer1, timerNumbers = {Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerNumber.A}) annotation( + Placement(visible = true, transformation(origin = {44, -6}, extent = {{-28, -28}, {28, 28}}, rotation = 0))); + Modelica.Blocks.Sources.IntegerExpression integerExpression1(y = 30) annotation( + Placement(visible = true, transformation(origin = {-57, -6}, extent = {{-23, -18}, {23, 18}}, rotation = 0))); + equation + connect(integerExpression1.y, pwm.u[1]) annotation( + Line(points = {{-32, -6}, {10, -6}}, color = {255, 127, 0})); + end MDD_servo_init; + + model MDD_servo_loop + extends Modelica.Icons.Example; + inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation( + Placement(visible = true, transformation(origin = {-41, 41}, extent = {{-19, -19}, {19, 19}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation( + Placement(visible = true, transformation(origin = {39, 41}, extent = {{-17, -17}, {17, 17}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.PWM pwm(fastPWM = true, initialValues = {0}, prescaler = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerPrescaler.'1/1024', timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer1, timerNumbers = {Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerNumber.A}) annotation( + Placement(visible = true, transformation(origin = {80, -8}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.MathInteger.TriggeredAdd triggeredAdd1(use_reset = false, use_set = false) annotation( + Placement(visible = true, transformation(origin = {10, -8}, extent = {{-6, -6}, {6, 6}}, rotation = 0))); + Modelica.Blocks.Sources.IntegerExpression integerExpression1(y = 10) annotation( + Placement(visible = true, transformation(origin = {-34, -8}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Sources.BooleanExpression booleanExpression1(y = if mod(time, 0.2) > 0.1 then true else false) annotation( + Placement(visible = true, transformation(origin = {-22, -32}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + equation + connect(booleanExpression1.y, triggeredAdd1.trigger) annotation( + Line(points = {{-10, -32}, {6, -32}, {6, -16}, {6, -16}}, color = {255, 0, 255})); + connect(integerExpression1.y, triggeredAdd1.u) annotation( + Line(points = {{-22, -8}, {2, -8}, {2, -8}, {2, -8}}, color = {255, 127, 0})); + connect(triggeredAdd1.y, pwm.u[1]) annotation( + Line(points = {{17, -8}, {68, -8}}, color = {255, 127, 0})); + end MDD_servo_loop; + + model MDD_servo_pot + extends Modelica.Icons.Example; + inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation( + Placement(visible = true, transformation(origin = {-40, 60}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation( + Placement(visible = true, transformation(origin = {39, 61}, extent = {{-19, -19}, {19, 19}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.ADC adc(analogPort = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.AnalogPort.A2, prescaler = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.AnalogPrescaler.'1/128', voltageReference = 180, voltageReferenceSelect = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.VRefSelect.Internal) annotation( + Placement(visible = true, transformation(origin = {-52, -10}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.PWM pwm(fastPWM = true, initialValues = {0}, prescaler = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerPrescaler.'1/1024', timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer1, timerNumbers = {Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerNumber.A}) annotation( + Placement(visible = true, transformation(origin = {48, -10}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Math.RealToInteger realToInteger1 annotation( + Placement(visible = true, transformation(origin = {-6, -10}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + equation + connect(adc.y, realToInteger1.u) annotation( + Line(points = {{-40, -10}, {-18, -10}, {-18, -10}, {-18, -10}, {-18, -10}}, color = {0, 0, 127})); + connect(realToInteger1.y, pwm.u[1]) annotation( + Line(points = {{6, -10}, {36, -10}, {36, -10}, {36, -10}}, color = {255, 127, 0})); + end MDD_servo_pot; + + model MDD_servo_reverse + extends Modelica.Icons.Example; + inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.01, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation( + Placement(visible = true, transformation(origin = {-59, 61}, extent = {{-19, -19}, {19, 19}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation( + Placement(visible = true, transformation(origin = {55, 61}, extent = {{-19, -19}, {19, 19}}, rotation = 0))); + Modelica.Blocks.Sources.IntegerExpression integerExpression1(y = if time < 0.2 then 22 else 15) annotation( + Placement(visible = true, transformation(origin = {-44, 0}, extent = {{-22, -22}, {22, 22}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.PWM pwm(fastPWM = true, initialValues = {0}, prescaler = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerPrescaler.'1/1024', timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer1, timerNumbers = {Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerNumber.A}) annotation( + Placement(visible = true, transformation(origin = {44, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + equation + connect(integerExpression1.y, pwm.u[1]) annotation( + Line(points = {{-20, 0}, {32, 0}}, color = {255, 127, 0})); + end MDD_servo_reverse; + end MDD_servo; + + package MDD_modbus + extends Modelica.Icons.ExamplesPackage; + + model MDD_read_val + extends Modelica.Icons.Example; + inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation( + Placement(visible = true, transformation(origin = {-45, 67}, extent = {{-15, -15}, {15, 15}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation( + Placement(visible = true, transformation(origin = {28, 68}, extent = {{-12, -12}, {12, 12}}, rotation = 0))); + Modelica.Blocks.MathInteger.MultiSwitch multiSwitch1(expr = {86, 88, 78}, nu = 3, use_pre_as_default = true, y_default = 0) annotation( + Placement(visible = true, transformation(origin = {-32.6577, -10}, extent = {{-10.0019, -22}, {30.0056, 22}}, rotation = 0))); + Modelica.Blocks.Interaction.Show.RealValue realValue1 annotation( + Placement(visible = true, transformation(origin = {60, -10}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Blocks.Read_Val read_Val1 annotation( + Placement(visible = true, transformation(origin = {26, -10}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + equation + connect(read_Val1.y, realValue1.numberPort) annotation( + Line(points = {{38, -10}, {48, -10}, {48, -10}, {48, -10}}, color = {0, 0, 127})); + connect(multiSwitch1.y, read_Val1.u) annotation( + Line(points = {{-2, -10}, {14, -10}, {14, -10}, {14, -10}}, color = {255, 127, 0})); + end MDD_read_val; + end MDD_modbus; + end MDD_Examples; + + package Blocks + extends Modelica.Icons.Package; + + model Read_Val + extends Modelica.Blocks.Interfaces.SISO; + import Modelica_DeviceDrivers.EmbeddedTargets.AVR; + import sComm = Arduino.SerialCommunication.Functions; + outer Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu; + annotation( + defaultComponentName = "Read_Val", + Icon(graphics = {Text(extent = {{-95, -95}, {95, 95}}, textString = "Read_Val", fontName = "Arial")})); + end Read_Val; + end Blocks; + + package Icons "Collection of icons used for library components" + extends Modelica.Icons.IconsPackage; + + partial package GenericICPackage "Icon with a generic IC" + annotation( + Icon(coordinateSystem(preserveAspectRatio = true, extent = {{-100, -100}, {100, 100}}), graphics = {Bitmap(extent = {{-95, -95}, {95, 95}}, fileName = "Resources/Images/Icons/tqfp32.png", rotation = 0)}), + Documentation(info = "<html> + <p> + This partial class is intended to design a <em>default icon for microcontrollers</em>. + </p> + </html>")); + end GenericICPackage; + + partial block GenericIC "Icon with a generic IC" + annotation( + Icon(coordinateSystem(preserveAspectRatio = true, extent = {{-100, -100}, {100, 100}}), graphics = {Bitmap(extent = {{-95, -95}, {95, 95}}, fileName = "Resources/Images/Icons/tqfp32.png", rotation = 0)}), + Documentation(info = "<html> + <p> + This partial class is intended to design a <em>default icon for microcontrollers</em>. + </p> + </html>")); + end GenericIC; + + partial package FunctionLayerIcon "Icon for packages that represent the function layer" + extends Modelica.Icons.Package; + annotation( + Icon(coordinateSystem(preserveAspectRatio = false, extent = {{-100, -100}, {100, 100}}), graphics = {Text(lineColor = {128, 128, 128}, extent = {{-90, -90}, {90, 90}}, textString = "f"), Ellipse(lineColor = {128, 128, 128}, extent = {{-80, -80}, {80, 80}})}), + Documentation(info = "<html> + <p>This icon indicates Modelica functions.</p> + </html>")); + end FunctionLayerIcon; + annotation( + preferredView = "info", + Documentation(info = "<html> + <p> + A collection of basic icons to be used for different elements of the library. + </p> + </html>")); + end Icons; + annotation( + Documentation(info = "<html> +<h4>Description</h4> +<p> +A serial communication package for hardware interfacing. +</p> +</html>")); + end SerialCommunication; + annotation( + uses(Modelica_DeviceDrivers(version = "1.5.0"), Modelica(version = "3.2.2"))); +end Arduino; diff --git a/OpenModelica_Arduino_With_MDD/Arduino.mo~ b/OpenModelica_Arduino_With_MDD/Arduino.mo~ new file mode 100644 index 0000000..d51347a --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/Arduino.mo~ @@ -0,0 +1,1775 @@ +package Arduino + extends Arduino.SerialCommunication.Icons.GenericICPackage; + + package SerialCommunication "Serial Communication Package for Arduino" + extends Arduino.SerialCommunication.Icons.FunctionLayerIcon; + import ModelicaReference.Operators; + + package Functions + extends Modelica.Icons.Package; + import Modelica; + + function open_serial "Command to initialize the serial port which is connected to Arduino" + extends Modelica.Icons.Function; + input Integer handle, port, baudrate; + output Integer OK; + + external OK = open_serial(handle, port, baudrate) annotation( + Library = "SerialComm"); + annotation( + Documentation(info = "<html> +<h4>Syntax</h4> +<blockquote><pre> +Arduino.SerialCommunication.Functions.<b>open_serial</b>(handle,port,baudrate); +</pre></blockquote> +<h4>Description</h4> +<p> +Establishes a serial communication using port number \"port\".To connect to the Arduino board, check the port number from the device manager or check it from the Arduino software. +</p> +</html>")); + end open_serial; + + function read_serial "read characters from serial port" + extends Modelica.Icons.Function; + input Integer handle; + input Integer size; + output Integer r_OK; + protected + Integer buf[size + 1]; + //String buf; + + external r_OK = read_serial(handle, buf, size) annotation( + Library = "SerialComm"); + annotation( + Documentation(info = "<html> +<h4>Syntax</h4> +<blockquote><pre> +Arduino.SerialCommunication.Functions.<b>read_serial</b>(handle,size); +</pre></blockquote> +<h4>Description</h4> +<p>The translation setting of openserial can come in the way, affecting the number of characters effectively read. If that is the case, omitting the parameter n might be a bad idea, as scilab can hang. This would happen if the input stream contains CR or LF characters which are filtered out: in such cases serialstatus counts them, but readserial does not see them and keeps wating (if the blocking mode of openserial was true) until the total number is received. +</p> +</html>")); + end read_serial; + + //algorithm + //Modelica.Utilities.Streams.print(String(buf)); + + function write_serial "write to the serial port" + extends Modelica.Icons.Function; + input Integer handle; + input String str; + input Integer size; + output Integer w_OK; + + external w_OK = write_serial(handle, str, size) annotation( + Library = "SerialComm"); + annotation( + Documentation(info = "<html> +<h4>Syntax</h4> +<blockquote><pre> +Arduino.SerialCommunication.Functions.<b>write_serial</b>(handle,str,size); +</pre></blockquote> +<h4>Description</h4> +<p>No end of line character is appended to the string; the user might have to add it if the device being talked to requires it. The Tcl command puts -nonewline is used. In addition, the translation mode of openserial can come into way. +</p> +</html>")); + end write_serial; + + function close_serial "Command to close the serial port which is connected to Arduino" + extends Modelica.Icons.Function; + input Integer handle; + output Integer c_OK; + + external c_OK = close_serial(handle) annotation( + Library = "SerialComm"); + annotation( + Documentation(info = "<html> +<h4>Syntax</h4> +<blockquote><pre> +Arduino.SerialCommunication.Functions.<b>close_serial</b>(handle); +</pre></blockquote> +<h4>Description</h4> +<p>Closes the port for serial communication specified by \"handle\".It is important to close the serial port after use, else the port would be busy and restart of Scilab might required to connect to it again. +</p> +</html>")); + end close_serial; + + function status_serial "get status of the serial port" + extends Modelica.Icons.Function; + input Integer handle; + output Integer stat_OK; + protected + Integer bytes[2]; + + external stat_OK = status_serial(handle, bytes) annotation( + Library = "SerialComm"); + annotation( + Documentation(info = "<html> +<h4>Syntax</h4> +<blockquote><pre> +Arduino.SerialCommunication.Functions.<b>status_serial</b>(handle); +</pre></blockquote> +<h4>Description</h4> +<p>Provides status of serial communication channel specified by \"handle\".Get some information about the number of characters present in the input and output buffers of the serial port, and about the status lines (DTS, CTS, etc.).The translation setting of openserial can come in the way. If the input stream contains CR or LF characters which are filtered out, openserial counts them but readserial does not see them. +</p> +</html>")); + end status_serial; + + function cmd_digital_out "Command to sent out digital signal to a connected Arduino board" + extends Modelica.Icons.Function; + input Integer h, pin_no, val; + output Integer digital_w_OK; + + external digital_w_OK = cmd_digital_out(h, pin_no, val) annotation( + Library = "Digital"); + annotation( + Documentation(info = "<html> +<h4>Syntax</h4> +<blockquote><pre> +Arduino.SerialCommunication.Functions.<b>cmd_digital_out</b>(handle,pin_no,value); +</pre></blockquote> +<h4>Description</h4> +<p>The Arduino board has a set of logical ports (digital) that are used for writing or reading data from a component. +To map a UNO, ports 2-13 are available (0 and 1 are used for serial transmission). For MEGA board, ports 2-53 are available. The port takes the low logic level (0) or logic high (1) which corresponds to the reference voltage. +</p> +</html>")); + end cmd_digital_out; + + function cmd_digital_in "Command to read in digital signal from a connected Arduino board" + extends Modelica.Icons.Function; + input Integer h, pin_no; + output Integer digital_in; + + external digital_in = cmd_digital_in(h, pin_no) annotation( + Library = "Digital"); + annotation( + Documentation(info = "<html> +<h4>Syntax</h4> +<blockquote><pre> +Arduino.SerialCommunication.Functions.<b>cmd_digital_in</b>(handle,pin_no); +</pre></blockquote> +<h4>Description</h4> +<p>The Arduino board has a set of logical ports (digital) that are used for writing or reading data from a component. +To map a UNO, ports 2-13 are available (0 and 1 are used for serial transmission). For MEGA board, ports 2-53 are available. The port takes the low logic level (0) or logic high (1) which corresponds to the reference voltage. +</p> +</html>")); + end cmd_digital_in; + + function delay "Provides delay.Suspends Openmodelica." + extends Modelica.Icons.Function; + input Integer t; + + external delay(t) annotation( + Library = "delay"); + annotation( + Documentation(info = "<html> + <h4>Syntax</h4> + <blockquote><pre> + Arduino.SerialCommunication.Functions.<b>delay</b>(milliseconds); + </pre></blockquote> + <h4>Description</h4> + <p>Delay process for specified number of miliseconds specified by the argument. The actual suspension time may be longer because of other activities in the system, or because of the time spent in processing the call. + </p> + </html>")); + end delay; + + function cmd_analog_in "Command to read in analog signal from a connected Arduino board" + extends Modelica.Icons.Function; + input Integer h, pin_no; + output Integer val; + + external val = cmd_analog_in(h, pin_no) annotation( + Library = "Analog"); + annotation( + Documentation(info = "<html> +<h4>Syntax</h4> +<blockquote><pre> +Arduino.SerialCommunication.Functions.<b>cmd_analog_in</b>(handle,pin_no); +</pre></blockquote> +<h4>Description</h4> +<p>Arduino UNO board has 6 analog input ports (A0 to A5), the Arduino Mega board has 16 analog input ports (A0 to A15). The 10 bits channels convert the analog input from 0 to 5 volts, to a digital value between 0 and 1023. +</p> +</html>")); + end cmd_analog_in; + + function cmd_analog_out "Command to sent out analog signal to a connected Arduino board" + extends Modelica.Icons.Function; + input Integer h, pin_no; + input Real val; + output Integer analog_w_OK; + + external analog_w_OK = cmd_analog_out(h, pin_no, val) annotation( + Library = "Analog"); + annotation( + Documentation(info = "<html> +<h4>Syntax</h4> +<blockquote><pre> +Arduino.SerialCommunication.Functions.<b>cmd_analog_out</b>(handle,pin_no,val); +</pre></blockquote> +<h4>Description</h4> +<p>The analog outputs of the Arduino Uno is available at the pins 3,5,6,9,10 and 11, while on the Mega board, the outputs are on pins 1-13 and 44-46. It is a bit misleading to use the term 'analog output', because in order to generate this output while minimizing energy losses, the Arduino uses PWM (Pulse Width Modulation) available on these ports. By varying the duty cycle of the PWM is altered the average voltage across the component connected to this port, which has the effect of having a analog output voltage. +The input port accepts the value from 0 to 255 which is correspoding to the duty cycle of 0 to 100%. In other words, sending 0 to the block will generate 0 V output at the port, 127 generates 2.5V and 255 generates 5V. (the port is 8 bits, so the resolutions of output would be 2^8 =256). +</p> +</html>")); + end cmd_analog_out; + + function cmd_analog_in_volt "Command to read in analog signal from a connected Arduino board" + extends Modelica.Icons.Function; + input Integer h, pin_no; + output Integer val; + + external val = cmd_analog_in_volt(h, pin_no) annotation( + Library = "Analogv"); + annotation( + Documentation(info = "<html> + <h4>Syntax</h4> + <blockquote><pre> + Arduino.SerialCommunication.Functions.<b>cmd_analog_in_volt</b>(handle,pin_no); + </pre></blockquote> + <h4>Description</h4> + <p>Arduino UNO board has 6 analog input ports (A0 to A5), the Arduino Mega board has 16 analog input ports (A0 to A15). The 10 bits channels convert the analog input from 0 to 5 volts, to a digital value between 0 and 1023. This function scale the reading to 0-5 so the user could get the measured voltage directly. + </p> + </html>")); + end cmd_analog_in_volt; + + function cmd_analog_out_volt "Command to sent out analog signal to a connected Arduino board" + extends Modelica.Icons.Function; + input Integer h, pin_no; + input Real val; + output Integer analog_v_wOK; + + external analog_v_wOK = cmd_analog_out_volt(h, pin_no, val) annotation( + Library = "Analogv"); + annotation( + Documentation(info = "<html> + <h4>Syntax</h4> + <blockquote><pre> + Arduino.SerialCommunication.Functions.<b>cmd_analog_out_volt</b>(handle,pin_no,val); + </pre></blockquote> + <h4>Description</h4> + <p>The analog outputs of the Arduino Uno is available at the pins 3,5,6,9,10 and 11, while on the Mega board, the outputs are on pins 1-13 and 44-46. It is a bit misleading to use the term 'analog output', because in order to generate this output while minimizing energy losses, the Arduino uses PWM (Pulse Width Modulation) available on these ports. By varying the duty cycle of the PWM is altered the average voltage across the component connected to this port, which has the effect of having a analog output voltage. + </p> + </html>")); + end cmd_analog_out_volt; + + function cmd_dcmotor_setup "Command to setup pins to control DC motor" + extends Modelica.Icons.Function; + input Integer handle, driver_type, motor_no, pin1, pin2; + + external cmd_dcmotor_setup(handle, driver_type, motor_no, pin1, pin2) annotation( + Library = "DCMotor"); + annotation( + Documentation(info = "<html> + <h4>Syntax</h4> + <blockquote><pre> + Arduino.SerialCommunication.Functions.<b>cmd_dcmotor_setup</b>(handle,driver_type,motor_no,pin_no1,pin_no2); + </pre></blockquote> + <h4>Description</h4> + <p>Arduino board does not deliver enough power, so it is necessary to use a H-bridge circuit/IC to control the motor. There are several types of H-bridge IC that do not all operate on the same principle. For example, the L298 requires the use of a PWM signal with current sense. The L293 uses two PWM to set the speed and direction. Ready-to-use Shields are also available. + Remember that the PWM is 8-bit (0 to 255). The input of the block could accept any value, but it would saturate at +- 255. + </p> + </html>")); + end cmd_dcmotor_setup; + + function cmd_dcmotor_run "Command to run DC motor after setting up" + extends Modelica.Icons.Function; + input Integer handle, motor_no, val; + + external cmd_dcmotor_run(handle, motor_no, val) annotation( + Library = "DCMotor"); + annotation( + Documentation(info = "<html> + <h4>Syntax</h4> + <blockquote><pre> + Arduino.SerialCommunication.Functions.<b>cmd_dcmotor_run</b>(handle,motor_no,value); + </pre></blockquote> + <h4>Description</h4> + <p>Arduino board does not deliver enough power, so it is necessary to use a H-bridge circuit/IC to control the motor. There are several types of H-bridge IC that do not all operate on the same principle. For example, the L298 requires the use of a PWM signal with current sense. The L293 uses two PWM to set the speed and direction. Ready-to-use Shields are also available. + Remember that the PWM is 8-bit (0 to 255). The input of the block could accept any value, but it would saturate at +- 255. + </p> + </html>")); + end cmd_dcmotor_run; + + function cmd_dcmotor_release "Command to release pins which have setup for DC motor" + extends Modelica.Icons.Function; + input Integer handle, motor_no; + + external cmd_dcmotor_release(handle, motor_no) annotation( + Library = "DCMotor"); + annotation( + Documentation(info = "<html> + <h4>Syntax</h4> + <blockquote><pre> + Arduino.SerialCommunication.Functions.<b>cmd_dcmotor_release</b>(handle,motor_no); + </pre></blockquote> + <h4>Description</h4> + <p>Arduino board does not deliver enough power, so it is necessary to use a H-bridge circuit/IC to control the motor. There are several types of H-bridge IC that do not all operate on the same principle. For example, the L298 requires the use of a PWM signal with current sense. The L293 uses two PWM to set the speed and direction. Ready-to-use Shields are also available. + Remember that the PWM is 8-bit (0 to 255). The input of the block could accept any value, but it would saturate at +- 255. + </p> + </html>")); + end cmd_dcmotor_release; + + function cmd_servo_attach "Command to attach servo motor to Arduino" + extends Modelica.Icons.Function; + input Integer handle, servo_no; + + external cmd_servo_attach(handle, servo_no) annotation( + Library = "ServoMotor"); + annotation( + Documentation(info = "<html> + <h4>Syntax</h4> + <blockquote><pre> + Arduino.SerialCommunication.Functions.<b>cmd_servo_attach</b>(handle,servo_no); + </pre></blockquote> + <h4>Description</h4> + <p>A servomotor is an rotary actuator consist of an electric motor, gears, a potentiometer and an analogue or digital electronics for control. The servomotor usualy used for a position control application (or speed for continuous rotation servos). + The user must give the command of the position setpoint or desired speed. This command is sent to the actuator in pulses spaced by 10 to 20 ms. The coding of these pulses is made such that a pulse of 1.5 ms corresponding to the centered position (rest), a pulse of 1 ms corresponds to an angle of 90° in the anticlockwise direction, and a pulse 2 ms corresponds to an angle of 90° clockwise. All other pulse widths give intermediate values. + A servomotor for continuous rotation, the pulse width control the rotational speed and the direction. It is recommended to use a voltage regulator to power the servomotor instead of using the Arduino board power. For simplicity, the function takes an input commnad in degrees from 0 to 180. Two actuators can be controlled with this toolbox. (modified version of 3 motors available) + </p> + </html>")); + end cmd_servo_attach; + + function cmd_servo_move "Command to run servo motor which has been setup" + extends Modelica.Icons.Function; + input Integer handle, servo_no, val; + + external cmd_servo_move(handle, servo_no, val) annotation( + Library = "ServoMotor"); + annotation( + Documentation(info = "<html> + <h4>Syntax</h4> + <blockquote><pre> + Arduino.SerialCommunication.Functions.<b>cmd_servo_move</b>(handle,servo_no,value); + </pre></blockquote> + <h4>Description</h4> + <p>A servomotor is an rotary actuator consist of an electric motor, gears, a potentiometer and an analogue or digital electronics for control. The servomotor usualy used for a position control application (or speed for continuous rotation servos). + The user must give the command of the position setpoint or desired speed. This command is sent to the actuator in pulses spaced by 10 to 20 ms. The coding of these pulses is made such that a pulse of 1.5 ms corresponding to the centered position (rest), a pulse of 1 ms corresponds to an angle of 90° in the anticlockwise direction, and a pulse 2 ms corresponds to an angle of 90° clockwise. All other pulse widths give intermediate values. + A servomotor for continuous rotation, the pulse width control the rotational speed and the direction. It is recommended to use a voltage regulator to power the servomotor instead of using the Arduino board power. For simplicity, the function takes an input commnad in degrees from 0 to 180. Two actuators can be controlled with this toolbox. (modified version of 3 motors available) + </p> + </html>")); + end cmd_servo_move; + + function cmd_servo_detach "Command to release the pin which has been setup for servo motor" + extends Modelica.Icons.Function; + input Integer handle, servo_no; + + external cmd_servo_attach(handle, servo_no) annotation( + Library = "ServoMotor"); + annotation( + Documentation(info = "<html> + <h4>Syntax</h4> + <blockquote><pre> + Arduino.SerialCommunication.Functions.<b>cmd_servo_detach</b>(handle,servo_no); + </pre></blockquote> + <h4>Description</h4> + <p>A servomotor is an rotary actuator consist of an electric motor, gears, a potentiometer and an analogue or digital electronics for control. The servomotor usualy used for a position control application (or speed for continuous rotation servos). + The user must give the command of the position setpoint or desired speed. This command is sent to the actuator in pulses spaced by 10 to 20 ms. The coding of these pulses is made such that a pulse of 1.5 ms corresponding to the centered position (rest), a pulse of 1 ms corresponds to an angle of 90° in the anticlockwise direction, and a pulse 2 ms corresponds to an angle of 90° clockwise. All other pulse widths give intermediate values. + A servomotor for continuous rotation, the pulse width control the rotational speed and the direction. It is recommended to use a voltage regulator to power the servomotor instead of using the Arduino board power. For simplicity, the function takes an input commnad in degrees from 0 to 180. Two actuators can be controlled with this toolbox. (modified version of 3 motors available) + </p> + </html>")); + end cmd_servo_detach; + + function ieeesingle2num "ieee-745 floating point converter" + extends Modelica.Icons.Function; + input String hexa; + output Real y; + + external y = ieeesingle2num(hexa) annotation( + Library = "ieeesingle2num"); + annotation( + Documentation(info = "<html> +<h4>Syntax</h4> +<blockquote><pre> +Arduino.SerialCommunication.Functions.<b>ieeesingle2num</b>(hexa); +</pre></blockquote> +<h4>Description</h4> +<p>Converts an hexadecimal integer to ieee single precision format + </p> +</html>")); + end ieeesingle2num; + + function math_floor "Floor function" + extends Modelica.Icons.Function; + input Real x; + output Integer y; + + external y = mfloor(x) annotation( + Library = "floor"); + annotation( + Documentation(info = "<html> + <h4>Syntax</h4> + <blockquote><pre> + Arduino.SerialCommunication.Functions.<b>math_floor</b>(x); + </pre></blockquote> + <h4>Description</h4> + <p>Returns the greatest integer less than or equal to x + </p> + </html>")); + end math_floor; + + function getArduinoVersion "Returns the Arduino version used" + extends Modelica.Icons.Function; + output String arduinoVersion(fixed = true); + algorithm + arduinoVersion := "1.1"; + annotation( + Documentation(info = "<html> + <h4>Syntax</h4> + <blockquote><pre> + Arduino.SerialCommunication.<b>getArduinoVersion</b>(); + </pre></blockquote> + <h4>Description</h4> + <p>Gives the version of the arduino used. + </p> + </html>")); + end getArduinoVersion; + + function cmd_encoder_init "Initiates the encoder" + extends Modelica.Icons.Function; + input Integer h, encoder_mode, pin_no1, pin_no2; + + external cmd_encoder_init(h, encoder_mode, pin_no1, pin_no2) annotation( + Library = "Encoder"); + annotation( + Documentation(info = "<html> + <h4>Syntax</h4> + <blockquote><pre> + Arduino.SerialCommunication.<b>cmd_encoder_init</b>(handle,encoder_mode,pin_no1,pin_no2); + </pre></blockquote> + <h4>Description</h4> + <p>Used to read encoder signal from one or more channels + </p> + </html>")); + end cmd_encoder_init; + + //Incomplete + + package MDD_Servo + extends Modelica.Icons.Package; + + class Init + extends ExternalObject; + + function constructor "Return device handle" + extends .Modelica.Icons.Function; + import Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions; + import Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types; + import sComm = Arduino.SerialCommunication.Functions; + import Arduino.SerialCommunication.Functions.MDD_Servo; + input sComm.Types.Servo_no servo_no; + output sComm.Functions.MDD_Servo.Init servo; + + external "C" servo = MDD_avr_servo_initialize(servo_no) annotation( + Include = "#include \"/home/souradip/OpenModelica/Resources/Include/MDDAVRServo.h\""); + end constructor; + + function destructor "Destructor" + extends .Modelica.Icons.Function; + import Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types; + import sComm = Arduino.SerialCommunication.Functions; + import Arduino.SerialCommunication.Functions.MDD_Servo; + input sComm.Types.Servo_no servo_no "Device handle"; + + external "C" MDD_avr_servo_finalize(servo_no) annotation( + Include = "#include \"/home/souradip/OpenModelica/Resources/Include/MDDAVRServo.h\""); + end destructor; + end Init; + + function Move + extends Modelica.Icons.Function; + import sComm = Arduino.SerialCommunication.Functions; + input sComm.Functions.MDD_Servo.Init servo; + input Integer value; + + external "C" MDD_avr_servo_move(servo, value) annotation( + Include = "#include \"/home/souradip/OpenModelica/Resources/Include/MDDAVRServo.h\""); + end Move; + end MDD_Servo; + end Functions; + + package Examples + extends Modelica.Icons.ExamplesPackage; + + package led + extends Modelica.Icons.ExamplesPackage; + + model led_blue "Turn on Blue LED" + extends Modelica.Icons.Example; + import sComm = Arduino.SerialCommunication.Functions; + import strm = Modelica.Utilities.Streams; + Integer ok(fixed = false); + Integer digital_out(fixed = false); + Integer c_ok(fixed = false); + algorithm + when initial() then + ok := sComm.open_serial(1, 2, 115200) "At port 0 with baudrate of 115200"; + sComm.delay(2000); + if ok <> 0 then + strm.print("Check the serial port and try again"); + else + digital_out := sComm.cmd_digital_out(1, 9, 1) "This will turn ON the blue LED"; + end if; + strm.print(String(time)); + c_ok := sComm.close_serial(1) "To close the connection safely"; + end when; + annotation( + experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-6, Interval = 10)); + end led_blue; + + model led_blue_delay "Turn on Blue LED for a period of 2 seconds" + extends Modelica.Icons.Example; + import sComm = Arduino.SerialCommunication.Functions; + import strm = Modelica.Utilities.Streams; + Integer ok(fixed = false); + Integer digital_out(fixed = false); + Integer c_ok(fixed = false); + algorithm + when initial() then + ok := sComm.open_serial(1, 0, 115200) "At port 0 with baudrate of 115200"; + sComm.delay(2000); + if ok <> 0 then + strm.print("Check the serial port and try again"); + else + digital_out := sComm.cmd_digital_out(1, 9, 1) "This will turn the blue LED"; + sComm.delay(2000) "let the blue LED be on for two seconds"; + digital_out := sComm.cmd_digital_out(1, 9, 0) "turn off blue LED"; + sComm.delay(2000) "let the blue LED be off for two seconds"; + end if; + strm.print(String(time)); + c_ok := sComm.close_serial(1) "To close the connection safely"; + end when; + annotation( + experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-6, Interval = 10)); + end led_blue_delay; + + model led_blue_red "Turn on Red & Blue LED" + extends Modelica.Icons.Example; + import sComm = Arduino.SerialCommunication.Functions; + import strm = Modelica.Utilities.Streams; + Integer ok(fixed = false); + Integer digital_out(fixed = false); + Integer c_ok(fixed = false); + algorithm + when initial() then + ok := sComm.open_serial(1, 0, 115200) "At port 0 with baudrate of 115200"; + if ok <> 0 then + strm.print("Check the serial port and try again"); + else + sComm.delay(2000); + digital_out := sComm.cmd_digital_out(1, 9, 1) "This will turn the blue LED"; + digital_out := sComm.cmd_digital_out(1, 11, 1) "This will turn the red LED"; + sComm.delay(5000) "Delay for 5 seconds"; + digital_out := sComm.cmd_digital_out(1, 9, 0) "This turns off the blue Led"; + sComm.delay(3000) "Delay for 3 seconds"; + digital_out := sComm.cmd_digital_out(1, 11, 0) "This turns off the red Led"; + end if; + strm.print(String(time)); + c_ok := sComm.close_serial(1) "To close the connection safely"; + end when; + annotation( + experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-6, Interval = 10)); + end led_blue_red; + + model led_blink "This will turn on and turn off the user LED for every second for 10 times" + extends Modelica.Icons.Example; + import sComm = Arduino.SerialCommunication.Functions; + import strm = Modelica.Utilities.Streams; + Integer ok(fixed = false); + Integer digital_out(fixed = false); + Integer c_ok(fixed = false); + algorithm + when initial() then + ok := sComm.open_serial(1, 0, 115200) "At port 0 with baudrate of 115200"; + sComm.delay(2000); + if ok <> 0 then + strm.print("Check the serial port and try again"); + else + for i in 1:10 loop + digital_out := sComm.cmd_digital_out(1, 13, 0) "This will turn off the LED"; + sComm.delay(500) "Delay for 0.5 seconds"; + digital_out := sComm.cmd_digital_out(1, 13, 1) "This turns the Led"; + sComm.delay(500) "Delay for 0.5 seconds"; + end for; + end if; + c_ok := sComm.close_serial(1) "To close the connection safely"; + end when; + annotation( + experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-6, Interval = 10)); + end led_blink; + + model led_green_blink "This will turn on and turn off the green LED for every second for 5 times" + extends Modelica.Icons.Example; + import sComm = Arduino.SerialCommunication.Functions; + import strm = Modelica.Utilities.Streams; + Integer ok(fixed = false); + Integer digital_out(fixed = false); + Integer c_ok(fixed = false); + algorithm + when initial() then + ok := sComm.open_serial(1, 0, 115200) "At port 0 with baudrate of 115200"; + sComm.delay(1000); + if ok <> 0 then + strm.print("Check the serial port and try again"); + else + for i in 1:10 loop + digital_out := sComm.cmd_digital_out(1, 10, 0) "This will turn off the green LED"; + sComm.delay(1000) "Delay for 1 second"; + digital_out := sComm.cmd_digital_out(1, 10, 1) "This turns the green Led"; + sComm.delay(1000) "Delay for 1 second"; + end for; + end if; + strm.print(String(time)); + c_ok := sComm.close_serial(1) "To close the connection safely"; + end when; + annotation( + experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-6, Interval = 10)); + end led_green_blink; + end led; + + package push + extends Modelica.Icons.ExamplesPackage; + + model led_push_button "Conrolling LED with PushButton" + extends Modelica.Icons.Example; + import sComm = Arduino.SerialCommunication.Functions; + import strm = Modelica.Utilities.Streams; + Integer ok(fixed = false); + Integer digital_in(fixed = false); + Integer digital_out(fixed = false); + Integer c_ok(fixed = false); + algorithm + when initial() then + ok := sComm.open_serial(1, 0, 115200) "At port 0 with baudrate of 115200"; + end when; + if ok <> 0 then + strm.print("Unable to open serial port, please check"); + else + digital_in := sComm.cmd_digital_in(1, 12) "Read from digital pin 12"; + if digital_in == 0 then + digital_out := sComm.cmd_digital_out(1, 9, 0) "This will turn OFF the blue LED"; + sComm.delay(200); + else + digital_out := sComm.cmd_digital_out(1, 9, 1) "This will turn ON the blue LED"; + sComm.delay(200); + end if; + end if; +//for i in 1:1000 loop +//end for; +//strm.print(String(time)); + when terminal() then + c_ok := sComm.close_serial(1) "To close the connection safely"; + end when; + annotation( + experiment(StartTime = 0, StopTime = 1, Tolerance = 1e-6, Interval = 0.01)); + end led_push_button; + + model push_button_status "Checking Status of PushButton" + extends Modelica.Icons.Example; + import sComm = Arduino.SerialCommunication.Functions; + import strm = Modelica.Utilities.Streams; + Integer ok(fixed = false); + Integer digital_in(fixed = false); + Integer digital_out(start = 0, fixed = false); + Integer c_ok(fixed = false); + algorithm + when initial() then + ok := sComm.open_serial(1, 1, 115200) "At port 0 with baudrate of 115200"; + end when; + if ok <> 0 then + strm.print("Unable to open serial port, please check"); + else + digital_in := sComm.cmd_digital_in(1, 12); + if digital_in == 0 then + digital_out := sComm.cmd_digital_out(1, 9, 0) "This will turn OFF the blue LED"; + strm.print("LOW"); + sComm.delay(200); + else + digital_out := sComm.cmd_digital_out(1, 9, 1) "This will turn ON the blue LED"; + strm.print("HIGH"); + sComm.delay(200); + end if; + end if; +//for i in 1:1000 loop +//end for; + when terminal() then + c_ok := sComm.close_serial(1) "To close the connection safely"; + end when; +//sComm.cmd_arduino_meter(digital_in); + annotation( + experiment(StartTime = 0, StopTime = 1, Tolerance = 1e-6, Interval = 0.01)); + end push_button_status; + end push; + + package ldr + extends Modelica.Icons.ExamplesPackage; + + model ldr_led "LED indicating light sensor readings" + extends Modelica.Icons.Example; + import sComm = Arduino.SerialCommunication.Functions; + import strm = Modelica.Utilities.Streams; + Integer ok(fixed = false); + Integer analog_in(fixed = false); + Integer digital_out(fixed = false); + Integer c_ok(fixed = false); + algorithm + when initial() then + ok := sComm.open_serial(1, 2, 115200) "At port 0 with baudrate of 115200"; + sComm.delay(2000); + end when; + if ok <> 0 then + strm.print("Unable to open serial port, please check"); + else + analog_in := sComm.cmd_analog_in(1, 5) "read analog pin 5 (ldr)"; + strm.print(String(analog_in)); + if analog_in < 300 then + digital_out := sComm.cmd_digital_out(1, 9, 1) "Turn ON LED"; + else + digital_out := sComm.cmd_digital_out(1, 9, 0) "Turn OFF LED"; + end if; + sComm.delay(200); + end if; +//for i in 1:500 loop +//end for; +//strm.print(String(time)); + when terminal() then + c_ok := sComm.close_serial(1) "To close the connection safely"; + end when; +//Run for 500 iterations +//Setting Threshold value of 300 + annotation( + experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-6, Interval = 0.02)); + end ldr_led; + + model ldr_read "Reading light intensity using ldr" + extends Modelica.Icons.Example; + import sComm = Arduino.SerialCommunication.Functions; + import strm = Modelica.Utilities.Streams; + Integer ok(fixed = false); + Integer analog_in(fixed = false); + Integer c_ok(fixed = false); + algorithm + when initial() then + ok := sComm.open_serial(1, 2, 115200) "At port 0 with baudrate of 115200"; + sComm.delay(2000); + end when; + if ok <> 0 then + strm.print("Unable to open serial port, please check"); + else + analog_in := sComm.cmd_analog_in(1, 5) "read analog pin 5 (ldr)"; + strm.print("LDR Readings at time " + String(time) + " : " + String(analog_in)); + sComm.delay(500); + end if; +//for i in 1:10 loop +//end for; + when terminal() then + c_ok := sComm.close_serial(1) "To close the connection safely"; + end when; +//Run for 10 iterations + annotation( + experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-6, Interval = 1)); + end ldr_read; + end ldr; + + package pot + extends Modelica.Icons.ExamplesPackage; + + model pot_threshold + extends Modelica.Icons.Example; + import sComm = Arduino.SerialCommunication.Functions; + import strm = Modelica.Utilities.Streams; + Integer ok(fixed = false); + Integer analog_in(fixed = false); + Integer digital_out(fixed = false); + Integer c_ok(fixed = false); + algorithm + when initial() then + ok := sComm.open_serial(1, 0, 115200) "At port 0 with baudrate of 115200"; + sComm.delay(1000); + end when; + if ok <> 0 then + strm.print("Unable to open serial port, please check"); + else + analog_in := sComm.cmd_analog_in(1, 2) "read analog pin 2"; + strm.print("Potentiometer Readings:" + String(analog_in)); + if analog_in >= 0 and analog_in < 320 then + digital_out := sComm.cmd_digital_out(1, 11, 1) "Turn ON LED"; + sComm.delay(1000); + digital_out := sComm.cmd_digital_out(1, 11, 0) "Turn OFF LED"; + elseif analog_in >= 320 and analog_in <= 900 then + digital_out := sComm.cmd_digital_out(1, 10, 1) "Turn ON LED"; + sComm.delay(1000); + digital_out := sComm.cmd_digital_out(1, 10, 0) "Turn OFF LED"; + elseif analog_in > 900 and analog_in <= 1023 then + digital_out := sComm.cmd_digital_out(1, 9, 1) "Turn ON LED"; + sComm.delay(1000); + digital_out := sComm.cmd_digital_out(1, 9, 0) "Turn OFF LED"; + end if; + end if; +//for i in 1:10 loop +//end for; + when terminal() then + c_ok := sComm.close_serial(1) "To close the connection safely"; + end when; +//Run for 10 iterations +//Threshold 1 +//Threshold 2 + annotation( + experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-6, Interval = 0.01)); + end pot_threshold; + end pot; + + package thermistor + extends Modelica.Icons.ExamplesPackage; + + model therm_buzzer "Sound buzzer depending on thermistor readings" + extends Modelica.Icons.Example; + import sComm = Arduino.SerialCommunication.Functions; + import strm = Modelica.Utilities.Streams; + Integer ok(fixed = false); + Integer analog_in(fixed = false); + Integer digital_out(fixed = false); + Integer c_ok(fixed = false); + algorithm + when initial() then + ok := sComm.open_serial(1, 0, 115200) "At port 0 with baudrate of 115200"; + sComm.delay(2000); + end when; + if ok <> 0 then + strm.print("Unable to open serial port, please check"); + else + analog_in := sComm.cmd_analog_in(1, 4) "read analog pin 4"; + if analog_in > 500 then + digital_out := sComm.cmd_digital_out(1, 3, 1) "Turn ON Buzzer"; + else + digital_out := sComm.cmd_digital_out(1, 3, 0) "Turn OFF Buzzer"; + end if; + sComm.delay(200); + end if; +//for i in 1:500 loop +//end for; +//Run for 500 iterations +//Setting Threshold value of 500 + when terminal() then + c_ok := sComm.close_serial(1) "To close the connection safely"; + end when; + annotation( + experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-6, Interval = 0.02)); + end therm_buzzer; + + model therm_read "Thermistor Readings" + extends Modelica.Icons.Example; + import sComm = Arduino.SerialCommunication.Functions; + import strm = Modelica.Utilities.Streams; + Integer ok(fixed = false); + Integer analog_in(fixed = false); + Integer c_ok(fixed = false); + algorithm + when initial() then + ok := sComm.open_serial(1, 0, 115200) "At port 0 with baudrate of 115200"; + sComm.delay(2000); + end when; + if ok <> 0 then + strm.print("Unable to open serial port, please check"); + else + analog_in := sComm.cmd_analog_in(1, 4) "read analog pin 5 (ldr)"; + strm.print("Thermistor Readings " + " : " + String(analog_in)); + sComm.delay(500); + end if; +//for i in 1:20 loop +//end for; + when terminal() then + c_ok := sComm.close_serial(1) "To close the connection safely"; + end when; +//Run for 20 iterations + annotation( + experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-6, Interval = 0.5)); + end therm_read; + end thermistor; + + package dcmotor + extends Modelica.Icons.ExamplesPackage; + + model dcmotor_clock "Rotate DC Motor clockwise" + extends Modelica.Icons.Example; + import sComm = Arduino.SerialCommunication.Functions; + import strm = Modelica.Utilities.Streams; + Integer ok(fixed = false); + Integer c_ok(fixed = false); + algorithm + when initial() then + ok := sComm.open_serial(1, 0, 115200) "COM port is 0 and baud rate is 115200"; + if ok <> 0 then + strm.print("Unable to open serial port, please check"); + else + sComm.delay(2000); + sComm.cmd_dcmotor_setup(1, 3, 1, 9, 10) "Setup DC motor of type 3 (L293D), motor 1, pin 9 and 10"; + sComm.cmd_dcmotor_run(1, 1, 100) "Motor 1 runs at PWM 100"; + sComm.delay(3000) "This is allowed to continue for 3 seconds"; + sComm.cmd_dcmotor_release(1, 1) "Motor 1 is released"; + end if; + c_ok := sComm.close_serial(1) "To close the connection safely"; + end when; + annotation( + experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-6, Interval = 10)); + end dcmotor_clock; + + model dcmotor_both "Rotate DC Motor in both directions" + extends Modelica.Icons.Example; + import sComm = Arduino.SerialCommunication.Functions; + import strm = Modelica.Utilities.Streams; + Integer ok(fixed = false); + Integer c_ok(fixed = false); + algorithm + when initial() then + ok := sComm.open_serial(1, 0, 115200) "COM port is 0 and baud rate is 115200"; + if ok <> 0 then + strm.print("Unable to open serial port, please check"); + else + sComm.delay(2000); + sComm.cmd_dcmotor_setup(1, 3, 1, 9, 10) "Setup DC motor of type 3 (L293D), motor 1, pin 9 and 10"; + sComm.cmd_dcmotor_run(1, 1, 255) "Motor 1 runs at PWM 100"; + sComm.delay(3000) "for 3 seconds"; + sComm.cmd_dcmotor_run(1, 1, -255) "Motor 1 runs at PWM -100 in reverse direction"; + sComm.delay(2000) "for 2 seconds"; + sComm.cmd_dcmotor_release(1, 1) "Motor 1 is released"; + end if; + c_ok := sComm.close_serial(1) "To close the connection safely"; + end when; + annotation( + experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-6, Interval = 10)); + end dcmotor_both; + + model dcmotor_loop "Rotate DC Motor in both directions in a loop" + extends Modelica.Icons.Example; + import sComm = Arduino.SerialCommunication.Functions; + import strm = Modelica.Utilities.Streams; + Integer ok(fixed = false); + Integer c_ok(fixed = false); + algorithm + when initial() then + ok := sComm.open_serial(1, 0, 115200) "COM port is 0 and baud rate is 115200"; + if ok <> 0 then + strm.print("Unable to open serial port, please check"); + else + for i in 1:4 loop + sComm.cmd_dcmotor_setup(1, 3, 1, 9, 10) "Setup DC motor of type 3 (L293D), motor 1, pins 9 and 10"; + sComm.cmd_dcmotor_run(1, 1, 100) "Motor 1 runs at PWM 100"; + sComm.delay(2000) "for 3 seconds"; + sComm.cmd_dcmotor_run(1, 1, 0) "Halt the motor"; + sComm.delay(2000) "for 2 seconds"; + sComm.cmd_dcmotor_run(1, 1, -100) "Run it at PWM 100 in reverse direction"; + sComm.delay(2000) "for 2 seconds"; + sComm.cmd_dcmotor_release(1, 1) "Motor 1 is released"; + end for; + end if; + c_ok := sComm.close_serial(1) "To close the connection safely"; + end when; + annotation( + experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-6, Interval = 10)); + end dcmotor_loop; + end dcmotor; + + package servo + extends Modelica.Icons.ExamplesPackage; + + model servo_init "Rotate Servo Motor by 30 degrees.After the roataion reset it by 0" + extends Modelica.Icons.Example; + import sComm = Arduino.SerialCommunication.Functions; + import strm = Modelica.Utilities.Streams; + Integer ok(fixed = false); + Integer c_ok(fixed = false); + algorithm + when initial() then + ok := sComm.open_serial(1, 0, 115200) "COM port is 0 and baud rate is 115200"; + if ok <> 0 then + strm.print("Check the serial port and try again"); + else + sComm.delay(2000); + sComm.cmd_servo_attach(1, 1) "To attach the motor to pin 9 of servo1"; + sComm.cmd_servo_move(1, 1, 0) "tell servo to rotate by 30 degrees"; + sComm.delay(3000); + end if; + c_ok := sComm.close_serial(1) "To close the connection safely"; + end when; + annotation( + experiment(StartTime = 0, StopTime = 5, Tolerance = 1e-6, Interval = 5)); + end servo_init; + + model servo_loop "Rotate servo motor by 20 degrees 10 times" + extends Modelica.Icons.Example; + import sComm = Arduino.SerialCommunication.Functions; + import strm = Modelica.Utilities.Streams; + Integer ok(fixed = false); + Integer c_ok(fixed = false); + Integer angle(fixed = true); + algorithm + when initial() then + ok := sComm.open_serial(1, 0, 115200) "COM port is 0 and baud rate is 115200"; + if ok <> 0 then + strm.print("Check the serial port and try again"); + else + sComm.delay(2000); + sComm.cmd_servo_attach(1, 1) "Attach motor to pin 9. 1 means pin 9."; + sComm.delay(2000); + angle := 20 "Angle by which it has to move"; + for i in 1:10 loop + sComm.cmd_servo_move(1, 1, angle * i) "tell servo to rotate by 20 degrees"; + sComm.delay(1000) "waits for a sec"; + end for; + end if; + c_ok := sComm.close_serial(1) "To close the connection safely"; + end when; +//sComm.cmd_servo_detach(1, 1) "Detach the motor"; + annotation( + experiment(StartTime = 0, StopTime = 5, Tolerance = 1e-6, Interval = 5)); + end servo_loop; + + model servo_reverse + extends Modelica.Icons.Example; + import sComm = Arduino.SerialCommunication.Functions; + import strm = Modelica.Utilities.Streams; + Integer ok(fixed = false); + Integer c_ok(fixed = false); + algorithm + when initial() then + ok := sComm.open_serial(1, 0, 115200) "COM port is 0 and baud rate is 115200"; + if ok <> 0 then + strm.print("Check the serial port and try again"); + else + sComm.delay(2000); + sComm.cmd_servo_attach(1, 1) "Attach the motor to pin 9. 1 means 9"; + sComm.cmd_servo_move(1, 1, 90) "Move the servo to 90 degree"; + sComm.delay(1000) "be there for one second"; + sComm.cmd_servo_move(1, 1, 45) "Move the servo to 45 degree"; + sComm.delay(1000) "be there for one second"; + sComm.delay(1000); + end if; + c_ok := sComm.close_serial(1) "To close the connection safely"; + end when; +//sComm.cmd_servo_detach(1, 1) "Detach the motor"; + annotation( + experiment(StartTime = 0, StopTime = 5, Tolerance = 1e-6, Interval = 5)); + end servo_reverse; + + model servo_pot "Control Servo Motor using Potentiometer" + extends Modelica.Icons.Example; + import sComm = Arduino.SerialCommunication.Functions; + import strm = Modelica.Utilities.Streams; + Integer ok(fixed = false); + Integer c_ok(fixed = false); + Integer analog_in(fixed = false); + algorithm + when initial() then + ok := sComm.open_serial(1, 0, 115200) "COM port is 0 and baud rate is 115200"; + if ok <> 0 then + strm.print("Check the serial port and try again"); + else + sComm.delay(2000); + sComm.cmd_servo_attach(1, 1) "Attach the motor to pin 9"; + sComm.delay(2000); + for i in 1:5000 loop + analog_in := sComm.cmd_analog_in(1, 2) "Read potentiometer value"; + analog_in := sComm.math_floor(analog_in * (180 / 1023)) "Scale Potentiometer value to 0-180"; + sComm.cmd_servo_move(1, 1, analog_in) "Command the servo motor"; + sComm.delay(1000) "sleep for 500 milliseconds"; + strm.print("Potentiometer Reading at time" + String(time) + " : " + String(analog_in)); + end for; + end if; + sComm.cmd_servo_detach(1, 1) "Detach the motor"; + sComm.delay(5000); + c_ok := sComm.close_serial(1) "To close the connection safely"; + end when; +//5,000 itterations + annotation( + experiment(StartTime = 0, StopTime = 5, Tolerance = 1e-6, Interval = 5)); + end servo_pot; + end servo; + + package modbus + extends Modelica.Icons.ExamplesPackage; + + function read_voltage + extends Modelica.Icons.Function; + + external read_voltage() annotation( + Library = "Modbus"); + annotation( + Documentation(info = "<html> + <h4>Syntax</h4> + <blockquote><pre> + Arduino.SerialCommunication.Examples.modbus.<b>read_voltage</b>(); + </pre></blockquote> + <h4>Description</h4> + <p> + </p> + </html>")); + end read_voltage; + + function read_current + extends Modelica.Icons.Function; + + external read_voltage() annotation( + Library = "Modbus"); + annotation( + Documentation(info = "<html> + <h4>Syntax</h4> + <blockquote><pre> + Arduino.SerialCommunication.Examples.modbus.<b>read_current</b>(); + </pre></blockquote> + <h4>Description</h4> + <p> + </p> + </html>")); + end read_current; + + function read_val + extends Modelica.Icons.Function; + input Integer addr_byte; + output Real p; + + external p = read_val(addr_byte) annotation( + Library = "Modbus"); + annotation( + Documentation(info = "<html> + <h4>Syntax</h4> + <blockquote><pre> + Arduino.SerialCommunication.Examples.modbus.<b>read_val</b>(address_byte); + </pre></blockquote> + <h4>Description</h4> + <p> + </p> + </html>")); + end read_val; + + function read_active_power + extends Modelica.Icons.Function; + + external read_active_power() annotation( + Library = "Modbus"); + annotation( + Documentation(info = "<html> + <h4>Syntax</h4> + <blockquote><pre> + Arduino.SerialCommunication.Examples.modbus.<b>read_active_power</b>(); + </pre></blockquote> + <h4>Description</h4> + <p> + </p> + </html>")); + end read_active_power; + + model modbus_test + extends Modelica.Icons.Example; + import sComm = Arduino.SerialCommunication.Functions; + import modbus = Arduino.SerialCommunication.Examples.modbus; + Integer ok(fixed = false); + Integer c_ok(fixed = false); + algorithm + when initial() then + ok := sComm.open_serial(1, 0, 9600); + modbus.read_voltage(); + modbus.read_current(); + modbus.read_active_power(); + c_ok := sComm.close_serial(1); + end when; + end modbus_test; + end modbus; + end Examples; + + package MDD_Examples "Interfacing arduino with OpenModelica using Modelica Device Drivers" + extends Modelica.Icons.ExamplesPackage; + + package MDD_led + extends Modelica.Icons.ExamplesPackage; + + model MDD_led_blue "" + extends Modelica.Icons.Example; + inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation( + Placement(visible = true, transformation(origin = {-44, 66}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation( + Placement(visible = true, transformation(origin = {39, 41}, extent = {{-17, -17}, {17, 17}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.DigitalWriteBoolean digitalWriteBoolean1(pin = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Pin.'1', port = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Port.B) annotation( + Placement(visible = true, transformation(origin = {39, -21}, extent = {{-19, -19}, {19, 19}}, rotation = 0))); + Modelica.Blocks.Sources.BooleanExpression booleanExpression1(y = true) annotation( + Placement(visible = true, transformation(origin = {-41, -21}, extent = {{-15, -17}, {15, 17}}, rotation = 0))); + equation + connect(booleanExpression1.y, digitalWriteBoolean1.u) annotation( + Line(points = {{-24, -20}, {14, -20}, {14, -20}, {16, -20}}, color = {255, 0, 255})); + annotation( + Documentation(info = "<html> + <h4>Syntax</h4> + <blockquote><pre> + Arduino.SerialCommunication.MDD_Examples.MDD_led.<b>MDD-led_blue</b>(); + </pre></blockquote> + <h4>Description</h4> + <p> + </p> + </html>")); + end MDD_led_blue; + + model MDD_led_blue_delay + extends Modelica.Icons.Example; + inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation( + Placement(visible = true, transformation(origin = {-40, 40}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation( + Placement(visible = true, transformation(origin = {31, 41}, extent = {{-19, -19}, {19, 19}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.DigitalWriteBoolean digitalWriteBoolean1(pin = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Pin.'1', port = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Port.B) annotation( + Placement(visible = true, transformation(origin = {41, -17}, extent = {{-17, -17}, {17, 17}}, rotation = 0))); + Modelica.Blocks.Sources.BooleanExpression booleanExpression1(y = if time < 5 then true else false) annotation( + Placement(visible = true, transformation(origin = {-27, -16}, extent = {{-21, -16}, {21, 16}}, rotation = 0))); + equation + connect(booleanExpression1.y, digitalWriteBoolean1.u) annotation( + Line(points = {{-4, -16}, {20, -16}}, color = {255, 0, 255})); + end MDD_led_blue_delay; + + model MDD_led_blink + extends Modelica.Icons.Example; + inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation( + Placement(visible = true, transformation(origin = {-45, 71}, extent = {{-23, -23}, {23, 23}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.DigitalWriteBoolean digitalWriteBoolean1(pin = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Pin.'5', port = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Port.B) annotation( + Placement(visible = true, transformation(origin = {42, -22}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation( + Placement(visible = true, transformation(origin = {23, 71}, extent = {{-19, -19}, {19, 19}}, rotation = 0))); + Modelica.Blocks.Sources.BooleanExpression booleanExpression1(y = mod(time, 2) >= 1) annotation( + Placement(visible = true, transformation(origin = {-24, -21}, extent = {{-16, -15}, {16, 15}}, rotation = 0))); + equation + connect(booleanExpression1.y, digitalWriteBoolean1.u) annotation( + Line(points = {{-6, -21}, {16, -21}, {16, -22}, {18, -22}}, color = {255, 0, 255})); + end MDD_led_blink; + + model MDD_led_blue_red + extends Modelica.Icons.Example; + inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation( + Placement(visible = true, transformation(origin = {-47, 47}, extent = {{-21, -21}, {21, 21}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.DigitalWriteBoolean digitalWriteBoolean1(pin = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Pin.'1', port = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Port.B) annotation( + Placement(visible = true, transformation(origin = {38, -16}, extent = {{-16, -16}, {16, 16}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation( + Placement(visible = true, transformation(origin = {40, 44}, extent = {{-18, -18}, {18, 18}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.DigitalWriteBoolean digitalWriteBoolean2(pin = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Pin.'3', port = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Port.B) annotation( + Placement(visible = true, transformation(origin = {38, -62}, extent = {{-16, -16}, {16, 16}}, rotation = 0))); + Modelica.Blocks.Sources.BooleanExpression booleanExpression1(y = if time < 5 then true else false) annotation( + Placement(visible = true, transformation(origin = {-32, -16}, extent = {{-18, -14}, {18, 14}}, rotation = 0))); + Modelica.Blocks.Sources.BooleanExpression booleanExpression2(y = if time < 8 then true else false) annotation( + Placement(visible = true, transformation(origin = {-32, -62}, extent = {{-18, -16}, {18, 16}}, rotation = 0))); + equation + connect(digitalWriteBoolean2.u, booleanExpression2.y) annotation( + Line(points = {{18, -62}, {-12, -62}, {-12, -62}, {-12, -62}}, color = {255, 0, 255})); + connect(booleanExpression2.y, digitalWriteBoolean2.u) annotation( + Line(points = {{-12, -62}, {18, -62}, {18, -62}, {18, -62}}, color = {255, 0, 255})); + connect(booleanExpression1.y, digitalWriteBoolean1.u) annotation( + Line(points = {{-12, -16}, {18, -16}, {18, -16}, {18, -16}}, color = {255, 0, 255})); + end MDD_led_blue_red; + + model MDD_led_green_blink + extends Modelica.Icons.Example; + inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation( + Placement(visible = true, transformation(origin = {-40, 40}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.DigitalWriteBoolean digitalWriteBoolean1(pin = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Pin.'2', port = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Port.B) annotation( + Placement(visible = true, transformation(origin = {46, -30}, extent = {{-18, -18}, {18, 18}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation( + Placement(visible = true, transformation(origin = {39, 39}, extent = {{-19, -19}, {19, 19}}, rotation = 0))); + Modelica.Blocks.Sources.BooleanExpression booleanExpression1(y = mod(time, 2) >= 1) annotation( + Placement(visible = true, transformation(origin = {-17, -30}, extent = {{-15, -14}, {15, 14}}, rotation = 0))); + equation + connect(booleanExpression1.y, digitalWriteBoolean1.u) annotation( + Line(points = {{0, -30}, {24, -30}, {24, -30}, {24, -30}}, color = {255, 0, 255})); + end MDD_led_green_blink; + end MDD_led; + + package MDD_push + extends Modelica.Icons.ExamplesPackage; + + model MDD_led_push_button + extends Modelica.Icons.Example; + inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation( + Placement(visible = true, transformation(origin = {-46, 62}, extent = {{-18, -18}, {18, 18}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation( + Placement(visible = true, transformation(origin = {39, 41}, extent = {{-17, -17}, {17, 17}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.DigitalReadBoolean digitalReadBoolean1(pin = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Pin.'4', port = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Port.B) annotation( + Placement(visible = true, transformation(origin = {-44, -28}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.DigitalWriteBoolean digitalWriteBoolean1(pin = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Pin.'1', port = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Port.B) annotation( + Placement(visible = true, transformation(origin = {62, -28}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Logical.LogicalSwitch logicalSwitch1 annotation( + Placement(visible = true, transformation(origin = {8, -28}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Sources.BooleanExpression booleanExpression1(y = true) annotation( + Placement(visible = true, transformation(origin = {-32, 18}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Sources.BooleanExpression booleanExpression2(y = false) annotation( + Placement(visible = true, transformation(origin = {-32, -70}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + equation + connect(booleanExpression2.y, logicalSwitch1.u3) annotation( + Line(points = {{-20, -70}, {-16, -70}, {-16, -36}, {-4, -36}, {-4, -36}}, color = {255, 0, 255})); + connect(booleanExpression1.y, logicalSwitch1.u1) annotation( + Line(points = {{-20, 18}, {-14, 18}, {-14, -20}, {-4, -20}, {-4, -20}}, color = {255, 0, 255})); + connect(logicalSwitch1.y, digitalWriteBoolean1.u) annotation( + Line(points = {{20, -28}, {50, -28}, {50, -28}, {50, -28}}, color = {255, 0, 255})); + connect(digitalReadBoolean1.y, logicalSwitch1.u2) annotation( + Line(points = {{-32, -28}, {-4, -28}}, color = {255, 0, 255})); + end MDD_led_push_button; + + + model MDD_push_button_status + extends Modelica.Icons.Example; + inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation( + Placement(visible = true, transformation(origin = {-43, 43}, extent = {{-19, -19}, {19, 19}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation( + Placement(visible = true, transformation(origin = {20, 42}, extent = {{-18, -18}, {18, 18}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.DigitalReadBoolean digitalReadBoolean1(pin = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Pin.'4', port = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Port.B) annotation( + Placement(visible = true, transformation(origin = {-39, -19}, extent = {{-19, -19}, {19, 19}}, rotation = 0))); + Modelica.Blocks.Interaction.Show.BooleanValue booleanValue1(use_activePort = true) annotation( + Placement(visible = true, transformation(origin = {31, -19}, extent = {{-15, -17}, {15, 17}}, rotation = 0))); + equation + connect(digitalReadBoolean1.y, booleanValue1.activePort) annotation( + Line(points = {{-18, -18}, {14, -18}, {14, -18}, {14, -18}}, color = {255, 0, 255})); + end MDD_push_button_status; + + model pushTest1 + extends Modelica.Icons.Example; + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.DigitalReadBoolean digitalReadBoolean1(pin = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Pin.'4', port = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Port.B) annotation( + Placement(visible = true, transformation(origin = {-60, -2}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.DigitalWriteBoolean digitalWriteBoolean1(pin = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Pin.'2', port = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Port.B) annotation( + Placement(visible = true, transformation(origin = {60, -2}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Logical.LogicalSwitch logicalSwitch1 annotation( + Placement(visible = true, transformation(origin = {-2, -2}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Sources.BooleanExpression booleanExpression1(y = true) annotation( + Placement(visible = true, transformation(origin = {-44, 48}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Sources.BooleanExpression booleanExpression2(y = false) annotation( + Placement(visible = true, transformation(origin = {-46, -58}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation( + Placement(visible = true, transformation(origin = {-70, 78}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); +equation + connect(booleanExpression1.y, logicalSwitch1.u1) annotation( + Line(points = {{-33, 48}, {-28, 48}, {-28, 6}, {-14, 6}}, color = {255, 0, 255})); + connect(logicalSwitch1.y, digitalWriteBoolean1.u) annotation( + Line(points = {{10, -2}, {48, -2}, {48, -2}, {48, -2}}, color = {255, 0, 255})); + connect(digitalReadBoolean1.y, logicalSwitch1.u2) annotation( + Line(points = {{-48, -2}, {-14, -2}, {-14, -2}, {-14, -2}}, color = {255, 0, 255})); + connect(booleanExpression2.y, logicalSwitch1.u3) annotation( + Line(points = {{-34, -58}, {-24, -58}, {-24, -10}, {-14, -10}, {-14, -10}}, color = {255, 0, 255})); + annotation( + uses(Modelica_DeviceDrivers(version = "1.5.0"), Modelica(version = "3.2.2"))); +end pushTest1; + end MDD_push; + + package MDD_ldr + extends Modelica.Icons.ExamplesPackage; + + model MDD_ldr_led + extends Modelica.Icons.Example; + inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation( + Placement(visible = true, transformation(origin = {-45, 65}, extent = {{-21, -21}, {21, 21}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation( + Placement(visible = true, transformation(origin = {40, 60}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.DigitalWriteBoolean digitalWriteBoolean1(pin = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Pin.'1', port = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Port.B) annotation( + Placement(visible = true, transformation(origin = {79, -23}, extent = {{-17, -17}, {17, 17}}, rotation = 0))); + Modelica.Blocks.Sources.BooleanExpression booleanExpression1(y = true) annotation( + Placement(visible = true, transformation(origin = {-60, 12}, extent = {{-14, -16}, {14, 16}}, rotation = 0))); + Modelica.Blocks.Sources.BooleanExpression booleanExpression2 annotation( + Placement(visible = true, transformation(origin = {-59, -79}, extent = {{-13, -17}, {13, 17}}, rotation = 0))); + Modelica.Blocks.Logical.LogicalSwitch logicalSwitch1 annotation( + Placement(visible = true, transformation(origin = {28, -22}, extent = {{-16, -16}, {16, 16}}, rotation = 0))); + Modelica.Blocks.Logical.GreaterThreshold greaterThreshold1(threshold = 600) annotation( + Placement(visible = true, transformation(origin = {-21, -23}, extent = {{-11, -11}, {11, 11}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.ADC adc(analogPort = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.AnalogPort.A5, prescaler = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.AnalogPrescaler.'1/128', voltageReference = 1024, voltageReferenceSelect = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.VRefSelect.Internal) annotation( + Placement(visible = true, transformation(origin = {-72, -22}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + equation + connect(adc.y, greaterThreshold1.u) annotation( + Line(points = {{-50, -22}, {-34, -22}}, color = {0, 0, 127})); + connect(greaterThreshold1.y, logicalSwitch1.u2) annotation( + Line(points = {{-8, -22}, {8, -22}, {8, -22}, {8, -22}}, color = {255, 0, 255})); + connect(logicalSwitch1.y, digitalWriteBoolean1.u) annotation( + Line(points = {{46, -22}, {58, -22}, {58, -22}, {58, -22}}, color = {255, 0, 255})); + connect(booleanExpression1.y, logicalSwitch1.u1) annotation( + Line(points = {{-44, 12}, {8, 12}, {8, -10}, {8, -10}}, color = {255, 0, 255})); + connect(booleanExpression2.y, logicalSwitch1.u3) annotation( + Line(points = {{-44, -78}, {6, -78}, {6, -34}, {8, -34}}, color = {255, 0, 255})); + end MDD_ldr_led; + + model MDD_ldr_read + extends Modelica.Icons.Example; + inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation( + Placement(visible = true, transformation(origin = {-37, 39}, extent = {{-19, -19}, {19, 19}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation( + Placement(visible = true, transformation(origin = {50, 38}, extent = {{-22, -22}, {22, 22}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.ADC adc(analogPort = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.AnalogPort.A5, prescaler = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.AnalogPrescaler.'1/128', voltageReference = 1024, voltageReferenceSelect = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.VRefSelect.Internal) annotation( + Placement(visible = true, transformation(origin = {-39, -17}, extent = {{-17, -17}, {17, 17}}, rotation = 0))); + Modelica.Blocks.Interaction.Show.RealValue realValue1(use_numberPort = true) annotation( + Placement(visible = true, transformation(origin = {30, -17}, extent = {{-18, -17}, {18, 17}}, rotation = 0))); + equation + connect(adc.y, realValue1.numberPort) annotation( + Line(points = {{-20, -17}, {7, -17}}, color = {0, 0, 127})); + end MDD_ldr_read; + end MDD_ldr; + + package MDD_pot + extends Modelica.Icons.ExamplesPackage; + + model MDD_pot_threshold "" + extends Modelica.Icons.Example; + inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation( + Placement(visible = true, transformation(origin = {-79, 79}, extent = {{-19, -19}, {19, 19}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation( + Placement(visible = true, transformation(origin = {80, 80}, extent = {{-18, -18}, {18, 18}}, rotation = 0))); + Modelica.Blocks.Logical.Switch switch11 annotation( + Placement(visible = true, transformation(origin = {2, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Logical.Switch switch12 annotation( + Placement(visible = true, transformation(origin = {10, -64}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Logical.Greater greater1 annotation( + Placement(visible = true, transformation(origin = {42, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Logical.Greater greater2 annotation( + Placement(visible = true, transformation(origin = {36, 70}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.DigitalWriteBoolean digitalWriteBoolean1(pin = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Pin.'1', port = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Port.B) annotation( + Placement(visible = true, transformation(origin = {82, 40}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.DigitalWriteBoolean digitalWriteBoolean2(pin = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Pin.'2', port = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Port.B) annotation( + Placement(visible = true, transformation(origin = {82, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.DigitalWriteBoolean digitalWriteBoolean3(pin = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Pin.'3', port = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Port.B) annotation( + Placement(visible = true, transformation(origin = {82, -64}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Logical.GreaterEqualThreshold greaterEqualThreshold1(threshold = 0) annotation( + Placement(visible = true, transformation(origin = {-42, 44}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Logical.GreaterEqualThreshold greaterEqualThreshold2(threshold = 320) annotation( + Placement(visible = true, transformation(origin = {-42, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Logical.GreaterEqualThreshold greaterEqualThreshold3(threshold = 900) annotation( + Placement(visible = true, transformation(origin = {-40, -64}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Sources.RealExpression realExpression1(y = 0) annotation( + Placement(visible = true, transformation(origin = {-40, -92}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Sources.RealExpression realExpression2(y = 1) annotation( + Placement(visible = true, transformation(origin = {-44, 84}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Logical.Switch switch1 annotation( + Placement(visible = true, transformation(origin = {0, 70}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Math.RealToBoolean realToBoolean1(threshold = 0.5) annotation( + Placement(visible = true, transformation(origin = {44, -64}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.ADC adc(analogPort = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.AnalogPort.A2, prescaler = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.AnalogPrescaler.'1/128', voltageReference = 1024, voltageReferenceSelect = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.VRefSelect.Internal) annotation( + Placement(visible = true, transformation(origin = {-88, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + equation + connect(adc.y, greaterEqualThreshold1.u) annotation( + Line(points = {{-76, 0}, {-70, 0}, {-70, 46}, {-54, 46}}, color = {0, 0, 127})); + connect(greaterEqualThreshold1.y, switch1.u2) annotation( + Line(points = {{-31, 46}, {-24, 46}, {-24, 70}, {-12, 70}}, color = {255, 0, 255})); + connect(adc.y, greaterEqualThreshold3.u) annotation( + Line(points = {{-76, 0}, {-70, 0}, {-70, -64}, {-52, -64}, {-52, -64}}, color = {0, 0, 127})); + connect(adc.y, greaterEqualThreshold2.u) annotation( + Line(points = {{-76, 0}, {-54, 0}, {-54, 0}, {-54, 0}}, color = {0, 0, 127})); + connect(realToBoolean1.y, digitalWriteBoolean3.u) annotation( + Line(points = {{56, -64}, {70, -64}, {70, -64}, {70, -64}}, color = {255, 0, 255})); + connect(switch12.y, realToBoolean1.u) annotation( + Line(points = {{22, -64}, {32, -64}, {32, -64}, {32, -64}}, color = {0, 0, 127})); + connect(realExpression1.y, switch1.u3) annotation( + Line(points = {{-28, -92}, {-16, -92}, {-16, 62}, {-12, 62}, {-12, 62}}, color = {0, 0, 127})); + connect(realExpression2.y, switch1.u1) annotation( + Line(points = {{-32, 84}, {-20, 84}, {-20, 78}, {-12, 78}, {-12, 78}}, color = {0, 0, 127})); + connect(switch1.y, greater2.u1) annotation( + Line(points = {{12, 70}, {22, 70}, {22, 70}, {24, 70}}, color = {0, 0, 127})); + connect(greater1.y, digitalWriteBoolean2.u) annotation( + Line(points = {{54, 0}, {70, 0}}, color = {255, 0, 255})); + connect(switch11.y, greater2.u2) annotation( + Line(points = {{14, 0}, {18, 0}, {18, 62}, {24, 62}, {24, 62}}, color = {0, 0, 127})); + connect(switch11.y, greater1.u1) annotation( + Line(points = {{14, 0}, {30, 0}}, color = {0, 0, 127})); + connect(switch12.y, greater1.u2) annotation( + Line(points = {{22, -64}, {22, -64}, {22, -8}, {30, -8}, {30, -8}}, color = {0, 0, 127})); + connect(greaterEqualThreshold2.y, switch11.u2) annotation( + Line(points = {{-30, 0}, {-10, 0}, {-10, 0}, {-10, 0}}, color = {255, 0, 255})); + connect(greater2.y, digitalWriteBoolean1.u) annotation( + Line(points = {{48, 70}, {56, 70}, {56, 40}, {70, 40}, {70, 40}}, color = {255, 0, 255})); + connect(realExpression2.y, switch12.u1) annotation( + Line(points = {{-32, 84}, {-20, 84}, {-20, -56}, {-2, -56}, {-2, -56}}, color = {0, 0, 127})); + connect(realExpression2.y, switch11.u1) annotation( + Line(points = {{-32, 84}, {-20, 84}, {-20, 8}, {-10, 8}, {-10, 8}}, color = {0, 0, 127})); + connect(realExpression1.y, switch11.u3) annotation( + Line(points = {{-28, -92}, {-16, -92}, {-16, -8}, {-10, -8}, {-10, -8}}, color = {0, 0, 127})); + connect(realExpression1.y, switch12.u3) annotation( + Line(points = {{-28, -92}, {-16, -92}, {-16, -72}, {-2, -72}, {-2, -72}}, color = {0, 0, 127})); + connect(greaterEqualThreshold3.y, switch12.u2) annotation( + Line(points = {{-28, -64}, {-2, -64}, {-2, -64}, {-2, -64}}, color = {255, 0, 255})); + annotation( + Documentation(info = "<html> + <h4>Syntax</h4> + <blockquote><pre> + Arduino.SerialCommunication.MDD_Examples.MDD_pot.<b>MDD_pot_threshold</b>(); + </pre></blockquote> + <h4>Description</h4> + <p>Voltage reference used to represent 10 bit precision(1024) of ADC along with prescaling by by 128.Internal voltage reference is applied to adc. + </p> + </html>")); + end MDD_pot_threshold; + end MDD_pot; + + package MDD_thermistor + extends Modelica.Icons.ExamplesPackage; + + model MDD_therm_read + extends Modelica.Icons.Example; + inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation( + Placement(visible = true, transformation(origin = {-40, 40}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation( + Placement(visible = true, transformation(origin = {40, 42}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.ADC adc(analogPort = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.AnalogPort.A4, prescaler = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.AnalogPrescaler.'1/128', voltageReference = 1024, voltageReferenceSelect = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.VRefSelect.Internal) annotation( + Placement(visible = true, transformation(origin = {-40, -20}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica.Blocks.Interaction.Show.RealValue realValue1(use_numberPort = true) annotation( + Placement(visible = true, transformation(origin = {39, -21}, extent = {{-15, -19}, {15, 19}}, rotation = 0))); + equation + connect(adc.y, realValue1.numberPort) annotation( + Line(points = {{-18, -20}, {20, -20}, {20, -20}, {22, -20}}, color = {0, 0, 127})); + end MDD_therm_read; + + model MDD_therm_buzzer + extends Modelica.Icons.Example; + inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation( + Placement(visible = true, transformation(origin = {-61, 61}, extent = {{-21, -21}, {21, 21}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.ADC adc(analogPort = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.AnalogPort.A4, prescaler = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.AnalogPrescaler.'1/128', voltageReference = 1024, voltageReferenceSelect = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.VRefSelect.Internal) annotation( + Placement(visible = true, transformation(origin = {-68, 1.77636e-15}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation( + Placement(visible = true, transformation(origin = {41, 61}, extent = {{-19, -19}, {19, 19}}, rotation = 0))); + Modelica.Blocks.Interaction.Show.RealValue realValue1(use_numberPort = true) annotation( + Placement(visible = true, transformation(origin = {12, -56}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.DigitalWriteBoolean digitalWriteBoolean1(pin = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Pin.'3', port = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Port.D) annotation( + Placement(visible = true, transformation(origin = {78, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Logical.LogicalSwitch logicalSwitch1 annotation( + Placement(visible = true, transformation(origin = {40, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Sources.BooleanExpression booleanExpression1(y = false) annotation( + Placement(visible = true, transformation(origin = {10, -32}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Sources.BooleanExpression booleanExpression2(y = true) annotation( + Placement(visible = true, transformation(origin = {10, 32}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Logical.GreaterEqualThreshold greaterEqualThreshold1(threshold = 550) annotation( + Placement(visible = true, transformation(origin = {-4, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + equation + connect(greaterEqualThreshold1.y, logicalSwitch1.u2) annotation( + Line(points = {{8, 0}, {28, 0}, {28, 0}, {28, 0}}, color = {255, 0, 255})); + connect(adc.y, greaterEqualThreshold1.u) annotation( + Line(points = {{-46, 0}, {-16, 0}, {-16, 0}, {-16, 0}}, color = {0, 0, 127})); + connect(adc.y, realValue1.numberPort) annotation( + Line(points = {{-46, 0}, {-32, 0}, {-32, -56}, {0, -56}}, color = {0, 0, 127})); + connect(logicalSwitch1.y, digitalWriteBoolean1.u) annotation( + Line(points = {{52, 0}, {66, 0}, {66, 0}, {66, 0}}, color = {255, 0, 255})); + connect(booleanExpression2.y, logicalSwitch1.u1) annotation( + Line(points = {{22, 32}, {24, 32}, {24, 8}, {28, 8}, {28, 8}}, color = {255, 0, 255})); + connect(booleanExpression1.y, logicalSwitch1.u3) annotation( + Line(points = {{22, -32}, {24, -32}, {24, -8}, {28, -8}, {28, -8}}, color = {255, 0, 255})); + end MDD_therm_buzzer; + end MDD_thermistor; + + package MDD_dcmotor + extends Modelica.Icons.ExamplesPackage; + + model MDD_dcmotor_clock + extends Modelica.Icons.Example; + inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation( + Placement(visible = true, transformation(origin = {-40, 40}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation( + Placement(visible = true, transformation(origin = {39, 41}, extent = {{-19, -19}, {19, 19}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.PWM pwm(fastPWM = true, initialValues = {0}, prescaler = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerPrescaler.'1/1024', timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer1, timerNumbers = {Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerNumber.B}) annotation( + Placement(visible = true, transformation(origin = {51, -3}, extent = {{-19, -19}, {19, 19}}, rotation = 0))); + Modelica.Blocks.Sources.IntegerExpression integerExpression1(y = if time < 5 then 255 else 0) annotation( + Placement(visible = true, transformation(origin = {-40, -3}, extent = {{-16, -13}, {16, 13}}, rotation = 0))); + equation + connect(pwm.u[1], integerExpression1.y) annotation( + Line(points = {{28, -3}, {-22, -3}}, color = {255, 127, 0}, thickness = 0.5)); + end MDD_dcmotor_clock; + + model MDD_dcmotor_both + extends Modelica.Icons.Example; + inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation( + Placement(visible = true, transformation(origin = {-40, 60}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation( + Placement(visible = true, transformation(origin = {56, 60}, extent = {{-18, -18}, {18, 18}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.PWM pwm(fastPWM = true, initialValues = {0}, prescaler = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerPrescaler.'1/1024', timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer1, timerNumbers = {Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerNumber.A}) annotation( + Placement(visible = true, transformation(origin = {54, 1.77636e-15}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica.Blocks.Sources.IntegerExpression integerExpression1(y = if mod(time, 5) >= 2.5 then 100 else 0) annotation( + Placement(visible = true, transformation(origin = {-41, 3.55271e-15}, extent = {{-23, -20}, {23, 20}}, rotation = 0))); + Modelica.Blocks.Sources.IntegerExpression integerExpression2(y = if mod(time, 5) < 2.5 then 100 else 0) annotation( + Placement(visible = true, transformation(origin = {-39, -48}, extent = {{-23, -20}, {23, 20}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.PWM pwm1(fastPWM = true, initialValues = {0}, prescaler = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerPrescaler.'1/1024', timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer1, timerNumbers = {Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerNumber.B}) annotation( + Placement(visible = true, transformation(origin = {54, -48}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + equation + connect(integerExpression2.y, pwm1.u[1]) annotation( + Line(points = {{-14, -48}, {28, -48}, {28, -48}, {30, -48}}, color = {255, 127, 0})); + connect(integerExpression1.y, pwm.u[1]) annotation( + Line(points = {{-16, 0}, {28, 0}, {28, 0}, {30, 0}}, color = {255, 127, 0})); + end MDD_dcmotor_both; + + model MDD_dcmotor_loop + extends Modelica.Icons.Example; + inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation( + Placement(visible = true, transformation(origin = {-40, 62}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation( + Placement(visible = true, transformation(origin = {40, 60}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.PWM pwm(fastPWM = true, initialValues = {0}, prescaler = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerPrescaler.'1/1024', timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer1, timerNumbers = {Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerNumber.A}) annotation( + Placement(visible = true, transformation(origin = {44, 16}, extent = {{-16, -16}, {16, 16}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.PWM pwm1(fastPWM = true, initialValues = {0}, prescaler = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerPrescaler.'1/1024', timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer1, timerNumbers = {Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerNumber.B}) annotation( + Placement(visible = true, transformation(origin = {44, -30}, extent = {{-16, -16}, {16, 16}}, rotation = 0))); + Modelica.Blocks.Sources.IntegerExpression integerExpression1(y = if mod(time, 6) < 3 then 255 else 0) annotation( + Placement(visible = true, transformation(origin = {-53, 16}, extent = {{-17, -16}, {17, 16}}, rotation = 0))); + Modelica.Blocks.Sources.IntegerExpression integerExpression2(y = if mod(time, 6) > 3 then 255 else 0) annotation( + Placement(visible = true, transformation(origin = {-52, -30}, extent = {{-16, -14}, {16, 14}}, rotation = 0))); + equation + connect(integerExpression2.y, pwm1.u[1]) annotation( + Line(points = {{-34, -30}, {24, -30}}, color = {255, 127, 0})); + connect(integerExpression1.y, pwm.u[1]) annotation( + Line(points = {{-34, 16}, {24, 16}}, color = {255, 127, 0})); + end MDD_dcmotor_loop; + end MDD_dcmotor; + + package MDD_servo + extends Modelica.Icons.ExamplesPackage; + + model MDD_servo_init + extends Modelica.Icons.Example; + inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation( + Placement(visible = true, transformation(origin = {-40, 58}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation( + Placement(visible = true, transformation(origin = {59, 59}, extent = {{-19, -19}, {19, 19}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.PWM pwm(fastPWM = true, initialValues = {0}, prescaler = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerPrescaler.'1/1024', timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer1, timerNumbers = {Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerNumber.A}) annotation( + Placement(visible = true, transformation(origin = {44, -6}, extent = {{-28, -28}, {28, 28}}, rotation = 0))); + Modelica.Blocks.Sources.IntegerExpression integerExpression1(y = 30) annotation( + Placement(visible = true, transformation(origin = {-57, -6}, extent = {{-23, -18}, {23, 18}}, rotation = 0))); + equation + connect(integerExpression1.y, pwm.u[1]) annotation( + Line(points = {{-32, -6}, {10, -6}}, color = {255, 127, 0})); + end MDD_servo_init; + + model MDD_servo_loop + extends Modelica.Icons.Example; + inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation( + Placement(visible = true, transformation(origin = {-41, 41}, extent = {{-19, -19}, {19, 19}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation( + Placement(visible = true, transformation(origin = {39, 41}, extent = {{-17, -17}, {17, 17}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.PWM pwm(fastPWM = true, initialValues = {0}, prescaler = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerPrescaler.'1/1024', timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer1, timerNumbers = {Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerNumber.A}) annotation( + Placement(visible = true, transformation(origin = {80, -8}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.MathInteger.TriggeredAdd triggeredAdd1(use_reset = false, use_set = false) annotation( + Placement(visible = true, transformation(origin = {10, -8}, extent = {{-6, -6}, {6, 6}}, rotation = 0))); + Modelica.Blocks.Sources.IntegerExpression integerExpression1(y = 10) annotation( + Placement(visible = true, transformation(origin = {-34, -8}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Sources.BooleanExpression booleanExpression1(y = if mod(time, 0.2) > 0.1 then true else false) annotation( + Placement(visible = true, transformation(origin = {-22, -32}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + equation + connect(booleanExpression1.y, triggeredAdd1.trigger) annotation( + Line(points = {{-10, -32}, {6, -32}, {6, -16}, {6, -16}}, color = {255, 0, 255})); + connect(integerExpression1.y, triggeredAdd1.u) annotation( + Line(points = {{-22, -8}, {2, -8}, {2, -8}, {2, -8}}, color = {255, 127, 0})); + connect(triggeredAdd1.y, pwm.u[1]) annotation( + Line(points = {{17, -8}, {68, -8}}, color = {255, 127, 0})); + end MDD_servo_loop; + + model MDD_servo_pot + extends Modelica.Icons.Example; + inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation( + Placement(visible = true, transformation(origin = {-40, 60}, extent = {{-20, -20}, {20, 20}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation( + Placement(visible = true, transformation(origin = {39, 61}, extent = {{-19, -19}, {19, 19}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.ADC adc(analogPort = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.AnalogPort.A2, prescaler = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.AnalogPrescaler.'1/128', voltageReference = 180, voltageReferenceSelect = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.VRefSelect.Internal) annotation( + Placement(visible = true, transformation(origin = {-52, -10}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.PWM pwm(fastPWM = true, initialValues = {0}, prescaler = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerPrescaler.'1/1024', timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer1, timerNumbers = {Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerNumber.A}) annotation( + Placement(visible = true, transformation(origin = {48, -10}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Math.RealToInteger realToInteger1 annotation( + Placement(visible = true, transformation(origin = {-6, -10}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + equation + connect(adc.y, realToInteger1.u) annotation( + Line(points = {{-40, -10}, {-18, -10}, {-18, -10}, {-18, -10}, {-18, -10}}, color = {0, 0, 127})); + connect(realToInteger1.y, pwm.u[1]) annotation( + Line(points = {{6, -10}, {36, -10}, {36, -10}, {36, -10}}, color = {255, 127, 0})); + end MDD_servo_pot; + + model MDD_servo_reverse + extends Modelica.Icons.Example; + inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.01, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation( + Placement(visible = true, transformation(origin = {-59, 61}, extent = {{-19, -19}, {19, 19}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation( + Placement(visible = true, transformation(origin = {55, 61}, extent = {{-19, -19}, {19, 19}}, rotation = 0))); + Modelica.Blocks.Sources.IntegerExpression integerExpression1(y = if time < 0.2 then 22 else 15) annotation( + Placement(visible = true, transformation(origin = {-44, 0}, extent = {{-22, -22}, {22, 22}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.PWM pwm(fastPWM = true, initialValues = {0}, prescaler = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerPrescaler.'1/1024', timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer1, timerNumbers = {Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerNumber.A}) annotation( + Placement(visible = true, transformation(origin = {44, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + equation + connect(integerExpression1.y, pwm.u[1]) annotation( + Line(points = {{-20, 0}, {32, 0}}, color = {255, 127, 0})); + end MDD_servo_reverse; + end MDD_servo; + + package MDD_modbus + extends Modelica.Icons.ExamplesPackage; + + model MDD_read_val + extends Modelica.Icons.Example; + inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation( + Placement(visible = true, transformation(origin = {-45, 67}, extent = {{-15, -15}, {15, 15}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation( + Placement(visible = true, transformation(origin = {28, 68}, extent = {{-12, -12}, {12, 12}}, rotation = 0))); + Modelica.Blocks.MathInteger.MultiSwitch multiSwitch1(expr = {86, 88, 78}, nu = 3, use_pre_as_default = true, y_default = 0) annotation( + Placement(visible = true, transformation(origin = {-32.6577, -10}, extent = {{-10.0019, -22}, {30.0056, 22}}, rotation = 0))); + Modelica.Blocks.Interaction.Show.RealValue realValue1 annotation( + Placement(visible = true, transformation(origin = {60, -10}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Blocks.Read_Val read_Val1 annotation( + Placement(visible = true, transformation(origin = {26, -10}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + equation + connect(read_Val1.y, realValue1.numberPort) annotation( + Line(points = {{38, -10}, {48, -10}, {48, -10}, {48, -10}}, color = {0, 0, 127})); + connect(multiSwitch1.y, read_Val1.u) annotation( + Line(points = {{-2, -10}, {14, -10}, {14, -10}, {14, -10}}, color = {255, 127, 0})); + end MDD_read_val; + end MDD_modbus; + end MDD_Examples; + + package Blocks + extends Modelica.Icons.Package; + + model Read_Val + extends Modelica.Blocks.Interfaces.SISO; + import Modelica_DeviceDrivers.EmbeddedTargets.AVR; + import sComm = Arduino.SerialCommunication.Functions; + outer Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu; + annotation( + defaultComponentName = "Read_Val", + Icon(graphics = {Text(extent = {{-95, -95}, {95, 95}}, textString = "Read_Val", fontName = "Arial")})); + end Read_Val; + end Blocks; + + package Icons "Collection of icons used for library components" + extends Modelica.Icons.IconsPackage; + + partial package GenericICPackage "Icon with a generic IC" + annotation( + Icon(coordinateSystem(preserveAspectRatio = true, extent = {{-100, -100}, {100, 100}}), graphics = {Bitmap(extent = {{-95, -95}, {95, 95}}, fileName = "Resources/Images/Icons/tqfp32.png", rotation = 0)}), + Documentation(info = "<html> + <p> + This partial class is intended to design a <em>default icon for microcontrollers</em>. + </p> + </html>")); + end GenericICPackage; + + partial block GenericIC "Icon with a generic IC" + annotation( + Icon(coordinateSystem(preserveAspectRatio = true, extent = {{-100, -100}, {100, 100}}), graphics = {Bitmap(extent = {{-95, -95}, {95, 95}}, fileName = "Resources/Images/Icons/tqfp32.png", rotation = 0)}), + Documentation(info = "<html> + <p> + This partial class is intended to design a <em>default icon for microcontrollers</em>. + </p> + </html>")); + end GenericIC; + + partial package FunctionLayerIcon "Icon for packages that represent the function layer" + extends Modelica.Icons.Package; + annotation( + Icon(coordinateSystem(preserveAspectRatio = false, extent = {{-100, -100}, {100, 100}}), graphics = {Text(lineColor = {128, 128, 128}, extent = {{-90, -90}, {90, 90}}, textString = "f"), Ellipse(lineColor = {128, 128, 128}, extent = {{-80, -80}, {80, 80}})}), + Documentation(info = "<html> + <p>This icon indicates Modelica functions.</p> + </html>")); + end FunctionLayerIcon; + annotation( + preferredView = "info", + Documentation(info = "<html> + <p> + A collection of basic icons to be used for different elements of the library. + </p> + </html>")); + end Icons; + annotation( + Documentation(info = "<html> +<h4>Description</h4> +<p> +A serial communication package for hardware interfacing. +</p> +</html>")); + end SerialCommunication; + annotation( + uses(Modelica_DeviceDrivers(version = "1.5.0"), Modelica(version = "3.2.2"))); +end Arduino; diff --git a/OpenModelica_Arduino_With_MDD/Instructions.txt b/OpenModelica_Arduino_With_MDD/Instructions.txt new file mode 100644 index 0000000..3c8a081 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/Instructions.txt @@ -0,0 +1,14 @@ +Compiling sources: +gcc -c -Wall -fPIC filename.c +gcc -shared -fPIC -o libfilename.so file1.o file2.o .... + +MDD: +Executing Blink example within MOdelica_DeviceDrivers EmbeddedTargets Package:- +Put the runMDDAvr.mos file in a (build) directory and execute following commands on the command line: + +omc --simCodeTarget=ExperimentalEmbeddedC runMDDAvr.mos + +avr-gcc -Os -std=c11 -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000UL -Wl,--gc-sections Blink_main.c -o Blink -I /path_to_MDD/Modelica_DeviceDrivers/Resources/Include -I /usr/include/omc/c + +avr-objcopy -O ihex -R .eeprom Blink Blink.hex +avrdude -F -V -c arduino -p ATMEGA328P -P /dev/ttyACM0 -b 115200 -U flash:w:Blink.hex diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/dcmotor/dcmotor_both b/OpenModelica_Arduino_With_MDD/MDD_build/dcmotor/dcmotor_both Binary files differnew file mode 100644 index 0000000..49bd982 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/dcmotor/dcmotor_both diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/dcmotor/dcmotor_both.hex b/OpenModelica_Arduino_With_MDD/MDD_build/dcmotor/dcmotor_both.hex new file mode 100644 index 0000000..6092d32 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/dcmotor/dcmotor_both.hex @@ -0,0 +1,121 @@ +:100000000C9434000C9451000C9451000C94510049
+:100010000C9451000C9451000C9451000C942C0140
+:100020000C9451000C9451000C9451000C94FB0062
+:100030000C9451000C9451000C94CA000C94510083
+:100040000C9451000C9451000C9451000C945100EC
+:100050000C9451000C9451000C9451000C945100DC
+:100060000C9451000C94510011241FBECFEFD8E026
+:10007000DEBFCDBF11E0A0E0B1E0E4E5F7E002C0F3
+:1000800005900D92A831B107D9F711E0A8E1B1E0D0
+:1000900001C01D92AD31B107E1F70E94A4010C949B
+:1000A000A8030C940000CF92DF92EF92FF92CF93BF
+:1000B000DF93EC01C880D980EA80FB80C701B601DC
+:1000C0000E9479029B01AC01C701B6010E94D301D5
+:1000D0006B017C0120E030E040E05FE30E944103DF
+:1000E00087FD03C084E690E002C080E090E09D833D
+:1000F0008C8320E030E040E05FE3C701B6010E945E
+:10010000380287FF03C084E690E002C080E090E000
+:100110009F838E838E899F898230910561F0833021
+:10012000910599F00197C9F416BC80916E00826028
+:1001300080936E0016C0109285001092840080910A
+:100140006F00826080936F000CC01092B2008091AB
+:10015000700082608093700004C081E090E00E9493
+:10016000A80378949FB7F89480911A019FBF8823C1
+:10017000C9F310921A01EE85FF858C818083EA898C
+:10018000FB898E818083DF91CF91FF90EF90DF908C
+:10019000CF9008951F920F920FB60F9211242F93B4
+:1001A0003F938F939F93809118019091190101962D
+:1001B000909319018093180180911A01813091F078
+:1001C000209118013091190180911B0190911C011F
+:1001D0002817390738F081E080931A01109219012D
+:1001E000109218019F918F913F912F910F900FBE08
+:1001F0000F901F9018951F920F920FB60F92112417
+:100200002F933F938F939F938091180190911901A1
+:100210000196909319018093180180911A01813001
+:1002200091F0209118013091190180911B0190915A
+:100230001C012817390738F081E080931A011092C9
+:100240001901109218019F918F913F912F910F905A
+:100250000FBE0F901F9018951F920F920FB60F921E
+:1002600011242F933F938F939F9380911801909126
+:1002700019010196909319018093180180911A0138
+:10028000813091F0209118013091190180911B016A
+:1002900090911C012817390738F081E080931A01EA
+:1002A00010921901109218019F918F913F912F91F7
+:1002B0000F900FBE0F901F901895CF93DF93FC0106
+:1002C000C1E8D0E088818D60888322E030E0318B06
+:1002D000208B229A40E850E0DA018C9181628C9365
+:1002E0008AE890E0DC0111961C921E921C92938B7E
+:1002F000828B88818D60888335872487219ADA01F3
+:100300008C9181688C93A8E8B0E011961C921E92A3
+:100310001C92B787A68785B5836085BD81E090E094
+:10032000958B848B2AE030E030931C0120931B01D5
+:1003300024B5226024BD29EF27BD978B868B80E0F2
+:1003400090E0DF91CF910895CF92DF92EF92FF92EC
+:1003500080E091E00E945D01C12CD12C760160E02B
+:1003600070E0CB0160930001709301018093020162
+:100370009093030180E091E00E9453008FEFC81A30
+:10038000D80AE80AF80AC701B6010E943C022FE623
+:1003900032E143E05BE30E94450320E030E0A90145
+:1003A0000E94D401DFCF5058BB27AA270ED018C116
+:1003B00009D130F00ED120F031F49F3F11F41EF43A
+:1003C000FEC00EF4E095E7FBCBC0E92F1AD180F315
+:1003D000BA17620773078407950718F071F49EF542
+:1003E00049C10EF4E0950B2EBA2FA02D0B01B901D7
+:1003F00090010C01CA01A0011124FF27591B99F09B
+:10040000593F50F4503E68F11A16F040A22F232FA6
+:10041000342F4427585FF3CF469537952795A795F6
+:10042000F0405395C9F77EF41F16BA0B620B730B9D
+:10043000840BBAF09150A1F0FF0FBB1F661F771F0E
+:10044000881FC2F70EC0BA0F621F731F841F48F4C3
+:10045000879577956795B795F7959E3F08F0B3CF49
+:100460009395880F08F09927EE0F97958795089533
+:1004700053D008F481E00895E89409C097FB3EF456
+:1004800090958095709561957F4F8F4F9F4F9923E1
+:10049000A9F0F92F96E9BB279395F695879577955F
+:1004A0006795B795F111F8CFFAF4BB0F11F460FF1F
+:1004B0001BC06F5F7F4F8F4F9F4F16C0882311F077
+:1004C00096E911C0772321F09EE8872F762F05C08B
+:1004D000662371F096E8862F70E060E02AF09A9526
+:1004E000660F771F881FDAF7880F9695879597F91B
+:1004F0000895A9D080F09F3740F491110EF0BBC051
+:1005000060E070E080E89FEB089526F41B16611D03
+:10051000711D811D2BC045C0990F0008550FAA0BF6
+:10052000E0E8FEEF16161706E807F907C0F0121606
+:100530001306E407F50798F0621B730B840B950B09
+:1005400039F40A2661F0232B242B252B21F408955E
+:100550000A2609F4A140A6958FEF811D811D0895FB
+:1005600097F99F6780E870E060E00895882371F450
+:10057000772321F09850872B762F07C0662311F43C
+:1005800099270DC09051862B70E060E02AF09A9573
+:10059000660F771F881FDAF7880F9695879597F96A
+:1005A00008959F3F31F0915020F487957795679596
+:1005B000B795880F911D9695879597F908959FEFA8
+:1005C00080EC089500240A941616170618060906EA
+:1005D000089500240A9412161306140605060895B9
+:1005E000092E0394000C11F4882352F0BB0F40F441
+:1005F000BF2B11F460FF04C06F5F7F4F8F4F9F4F81
+:10060000089557FD9058440F551F59F05F3F71F002
+:100610004795880F97FB991F61F09F3F79F0879569
+:100620000895121613061406551FF2CF4695F1DFF2
+:1006300008C0161617061806991FF1CF8695710582
+:10064000610508940895E5DFA0F0BEE7B91788F4C6
+:10065000BB279F3860F41616B11D672F782F8827A7
+:10066000985FF7CF869577956795B11D93959639E5
+:10067000C8F30895E894BB2766277727CB0197F93D
+:1006800008954ADF08F48FEF08950BD0A9CF9ADFC1
+:1006900028F09FDF18F0952309F062CF90CF112446
+:1006A000EACFAFDFA0F3959FD1F3950F50E0551F30
+:1006B000629FF001729FBB27F00DB11D639FAA27B7
+:1006C000F00DB11DAA1F649F6627B00DA11D661F06
+:1006D000829F2227B00DA11D621F739FB00DA11D27
+:1006E000621F839FA00D611D221F749F3327A00DE1
+:1006F000611D231F849F600D211D822F762F6A2F7D
+:1007000011249F5750408AF0E1F088234AF0EE0F01
+:10071000FF1FBB1F661F771F881F91505040A9F70E
+:100720009E3F510570F01CCFA6CF5F3FECF3983E83
+:10073000DCF3869577956795B795F795E7959F5F75
+:10074000C1F7FE2B880F911D9695879597F908950F
+:04075000F894FFCF4B
+:1007540000000000000000000AD7233C0000000055
+:0807640000000000000000008D
+:00000001FF
diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/dcmotor/dcmotor_both.sh b/OpenModelica_Arduino_With_MDD/MDD_build/dcmotor/dcmotor_both.sh new file mode 100644 index 0000000..762735b --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/dcmotor/dcmotor_both.sh @@ -0,0 +1,61 @@ +#!/bin/bash +clear +if [ "$#" -ne 2 ]; then + echo "Usage: $0 port baudrate" >&2 + exit 1 +fi + +re='^[0-9]+$' +if ! [[ $1 =~ $re ]] ; then + echo "error: $1 -> Not a number" >&2; exit 1 +fi + +if ! [[ $2 =~ $re ]] ; then + echo "error: $2-> Not a number" >&2; exit 1 +fi + +b_rate=$2 + +present=`pwd` +unamestr=`uname` + +if [[ "$unamestr" == 'Linux' ]]; then + mdd_path=($(locate Modelica_DeviceDrivers/Modelica_DeviceDrivers/Resources/Include)) + om_path=($(locate /usr/include/omc/c)) + port="/dev/ttyACM$1" + omc --simCodeTarget=ExperimentalEmbeddedC runMDD_dcmotor_both.mos + if [ $? -ne 0 ]; then + exit 1 + fi +else + cd c: + om_path=($(dir -d OpenModelica*/include/omc/c/)) + path_to_om="C:$om_path" + cd f: + mdd_path=($(dir -d */Modelica_DeviceDrivers/Modelica_DeviceDrivers/Resources/Include/)) + if [ $? -eq 0 ]; then + path_to_mdd="F:/$mdd_path" + else + exit 1 + fi + + port="COM$1" + cd $present + omc --simCodeTarget=ExperimentalEmbeddedC run_dcmotor_both.mos + if [ $? -ne 0 ]; then + exit 1 + fi +fi + +avr-gcc -Os -std=c11 -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000UL -Wl,--gc-sections dcmotor_both_main.c -o dcmotor_both -I${mdd_path[0]} -I${path_to_om} -I${path_to_mdd} -I${om_path[0]} +if [ $? -ne 0 ]; then + exit 1 +fi +avr-objcopy -O ihex -R .eeprom dcmotor_both dcmotor_both.hex +if [ $? -ne 0 ]; then + exit 1 +fi +avrdude -F -V -c arduino -p ATMEGA328P -P $port -b $b_rate -U flash:w:dcmotor_both.hex +if [ $? -ne 0 ]; then + exit 1 +fi
\ No newline at end of file diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/dcmotor/dcmotor_both_main.c b/OpenModelica_Arduino_With_MDD/MDD_build/dcmotor/dcmotor_both_main.c new file mode 100644 index 0000000..dbf03a2 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/dcmotor/dcmotor_both_main.c @@ -0,0 +1,217 @@ +#define fmi2TypesPlatform_h + +#define fmi2TypesPlatform "default" /* Compatible */ + +typedef struct dcmotor_both_fmi2Component_s* fmi2Component; +typedef void* fmi2ComponentEnvironment; /* Pointer to FMU environment */ +typedef void* fmi2FMUstate; /* Pointer to internal FMU state */ +typedef unsigned int fmi2ValueReference; +typedef double fmi2Real; +typedef int fmi2Integer; +typedef int fmi2Boolean; +typedef char fmi2Char; +typedef const fmi2Char* fmi2String; +typedef char fmi2Byte; + +#define fmi2True 1 +#define fmi2False 0 + +#include "fmi2/fmi2Functions.h" + +#include <stdint.h> +#include <stdio.h> + +void ModelicaFormatMessage(const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + vprintf(fmt, args); + va_end(args); +} + +typedef struct dcmotor_both_fmi2Component_s { + fmi2Real currentTime; + fmi2Integer fmi2IntegerVars[2]; + fmi2Real fmi2RealParameter[1]; + void* extObjs[6]; +} dcmotor_both_fmi2Component; + +dcmotor_both_fmi2Component dcmotor_both_component = { + .fmi2IntegerVars = { + 0 /*pwm._u[1]*/, + 0 /*pwm1._u[1]*/, + }, + .fmi2RealParameter = { + 0.01 /*synchronizeRealtime1._actualInterval*/, + }, +}; + +#include <math.h> +/* TODO: Generate used builtin functions before SimCode */ +static inline double om_mod(double x, double y) +{ + return x-floor(x/y)*y; +} + +#include "MDDAVRTimer.h" +#include "MDDAVRRealTime.h" +#include "MDDAVRAnalog.h" + +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_set(fmi2Component comp, void* om_pwm, fmi2Integer om_value); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_pin, fmi2Integer om_initialValue, fmi2Boolean om_inverted); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_Init_destructor(fmi2Component comp, void* om_pwm); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer); + +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_set(fmi2Component comp, void* om_pwm, fmi2Integer om_value) +{ + MDD_avr_pwm_set(om_pwm, om_value); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_pin, fmi2Integer om_initialValue, fmi2Boolean om_inverted) +{ + void* om_pwm; + om_pwm = MDD_avr_pwm_init(om_timer, om_pin, om_initialValue, om_inverted); + return om_pwm; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_Init_destructor(fmi2Component comp, void* om_pwm) +{ + MDD_avr_pwm_close(om_pwm); +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt) +{ + MDD_avr_rt_wait(om_rt); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle) +{ + void* om_rt; + om_rt = MDD_avr_rt_init(om_timer, om_timerValue, om_numTimerInterruptsPerCycle); + return om_rt; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt) +{ + MDD_avr_rt_close(om_rt); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch) +{ + void* om_timer; + om_timer = MDD_avr_timer_init(om_timerSelect, om_clockSelect, om_clearTimerOnMatch); + return om_timer; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer) +{ + MDD_avr_timer_close(om_timer); +} + +fmi2Component dcmotor_both_fmi2Instantiate(fmi2String name, fmi2Type ty, fmi2String GUID, fmi2String resources, const fmi2CallbackFunctions* functions, fmi2Boolean visible, fmi2Boolean loggingOn) +{ + static int initDone=0; + if (initDone) { + return NULL; + } + return &dcmotor_both_component; +} + +fmi2Status dcmotor_both_fmi2SetupExperiment(fmi2Component comp, fmi2Boolean toleranceDefined, fmi2Real tolerance, fmi2Real startTime, fmi2Boolean stopTimeDefined, fmi2Real stopTime) +{ + return fmi2OK; +} + +fmi2Status dcmotor_both_fmi2EnterInitializationMode(fmi2Component comp) +{ + comp->extObjs[2] /* pwm1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(comp, 2, 7, fmi2True); + comp->extObjs[3] /* pwm1._pwm[1] EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.PWM.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_Init_constructor(comp, comp->extObjs[2] /* pwm1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */, 2, 0, fmi2False); + comp->extObjs[0] /* pwm._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(comp, 2, 7, fmi2True); + comp->extObjs[1] /* pwm._pwm[1] EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.PWM.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_Init_constructor(comp, comp->extObjs[0] /* pwm._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */, 1, 0, fmi2False); + comp->extObjs[4] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(comp, 1, 4, fmi2False); + comp->extObjs[5] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(comp, comp->extObjs[4] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */, 249, 10); + return fmi2OK; +} + +fmi2Status dcmotor_both_fmi2ExitInitializationMode(fmi2Component comp) +{ + return fmi2OK; +} + +static fmi2Status dcmotor_both_functionODE(fmi2Component comp) +{ +} + +static fmi2Status dcmotor_both_functionOutputs(fmi2Component comp) +{ + comp->fmi2IntegerVars[0] /* pwm._u[1] DISCRETE */ = ((om_mod(comp->currentTime,1.0))>=(0.5)) ? (100) : (0); /* equation 4 */ + comp->fmi2IntegerVars[1] /* pwm1._u[1] DISCRETE */ = ((om_mod(comp->currentTime,1.0))<(0.5)) ? (100) : (0); /* equation 5 */Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(comp, comp->extObjs[5] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */);Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_set(comp, comp->extObjs[1] /* pwm._pwm[1] EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.PWM.Init */, comp->fmi2IntegerVars[0] /* pwm._u[1] DISCRETE */);Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_set(comp, comp->extObjs[3] /* pwm1._pwm[1] EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.PWM.Init */, comp->fmi2IntegerVars[1] /* pwm1._u[1] DISCRETE */); +} + +fmi2Status dcmotor_both_fmi2DoStep(fmi2Component comp, fmi2Real currentCommunicationPoint, fmi2Real communicationStepSize, fmi2Boolean noSetFMUStatePriorToCurrentPoint) +{ + comp->currentTime = currentCommunicationPoint; + /* TODO: Calculate time/state-dependent variables here... */ + dcmotor_both_functionOutputs(comp); + return fmi2OK; +} + +int main(int argc, char **argv) +{ + int terminateSimulation = 0; + fmi2Status status = fmi2OK; + fmi2CallbackFunctions cbf = { + .logger = NULL, + .allocateMemory = NULL /*calloc*/, + .freeMemory = NULL /*free*/, + .stepFinished = NULL, //synchronous execution + .componentEnvironment = NULL + }; + + fmi2Component comp = dcmotor_both_fmi2Instantiate("", fmi2CoSimulation, "", "", &cbf, fmi2False, fmi2False); + if (comp==NULL) { + return 1; + } + dcmotor_both_fmi2SetupExperiment(comp, fmi2False, 0.0, 0.0, fmi2False, 1.0); + dcmotor_both_fmi2EnterInitializationMode(comp); + // Set start-values? Nah... + dcmotor_both_fmi2ExitInitializationMode(comp); + + double currentTime = 0.0; + double h = 0.002; + uint32_t i = 0; + + while (status == fmi2OK) { + //retrieve outputs + // fmi2GetReal(m, ..., 1, &y1); + //set inputs + // fmi2SetReal(m, ..., 1, &y2); + + //call slave and check status + status = dcmotor_both_fmi2DoStep(comp, currentTime, h, fmi2True); + switch (status) { + case fmi2Discard: + case fmi2Error: + case fmi2Fatal: + case fmi2Pending /* Cannot happen */: + terminateSimulation = 1; + break; + case fmi2OK: + case fmi2Warning: + break; + } + if (terminateSimulation) { + break; + } + i++; + /* increment master time */ + currentTime = 0.0 + h*i; + } + +#if 0 + if ((status != fmi2Error) && (status != fmi2Fatal)) { + fmi2Terminate(m); + } + if (status != fmi2Fatal) { + fmi2FreeInstance(m); + } +#endif +} + diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/dcmotor/dcmotor_clock b/OpenModelica_Arduino_With_MDD/MDD_build/dcmotor/dcmotor_clock Binary files differnew file mode 100644 index 0000000..0e58a0e --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/dcmotor/dcmotor_clock diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/dcmotor/dcmotor_clock.hex b/OpenModelica_Arduino_With_MDD/MDD_build/dcmotor/dcmotor_clock.hex new file mode 100644 index 0000000..f752eb8 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/dcmotor/dcmotor_clock.hex @@ -0,0 +1,101 @@ +:100000000C9434000C9451000C9451000C94510049
+:100010000C9451000C9451000C9451000C94E50088
+:100020000C9451000C9451000C9451000C94B400A9
+:100030000C9451000C9451000C9483000C945100CA
+:100040000C9451000C9451000C9451000C945100EC
+:100050000C9451000C9451000C9451000C945100DC
+:100060000C9451000C94510011241FBECFEFD8E026
+:10007000DEBFCDBF11E0A0E0B1E0ECE1F6E002C0F0
+:1000800005900D92A231B107D9F711E0A2E1B1E0DC
+:1000900001C01D92A731B107E1F70E9445010C9400
+:1000A0000C030C9400008230910561F083309105BF
+:1000B00099F00197C9F416BC80916E00826080931C
+:1000C0006E0016C0109285001092840080916F001F
+:1000D000826080936F000CC01092B200809170001B
+:1000E00082608093700004C081E090E00E940C0365
+:1000F00078949FB7F894809114019FBF8823C9F327
+:100100001092140108951F920F920FB60F921124AE
+:100110002F933F938F939F9380911201909113019E
+:100120000196909313018093120180911401813004
+:1001300091F020911201309113018091150190915D
+:1001400016012817390738F081E0809314011092C6
+:100150001301109212019F918F913F912F910F9057
+:100160000FBE0F901F9018951F920F920FB60F920F
+:1001700011242F933F938F939F938091120190911D
+:100180001301019690931301809312018091140141
+:10019000813091F02091120130911301809115016D
+:1001A000909116012817390738F081E080931401E7
+:1001B00010921301109212019F918F913F912F91F4
+:1001C0000F900FBE0F901F9018951F920F920FB6B1
+:1001D0000F9211242F933F938F939F93809112013D
+:1001E00090911301019690931301809312018091D5
+:1001F0001401813091F0209112013091130180910E
+:100200001501909116012817390738F081E0809385
+:10021000140110921301109212019F918F913F913E
+:100220002F910F900FBE0F901F901895FC01A1E821
+:10023000B0E08C918D608C9382E090E09387828710
+:10024000229AA0E8B0E08C9181628C93AAE8B0E099
+:1002500011961C921E921C92B587A48785B5836067
+:1002600085BD81E090E0978786872AE030E0309373
+:1002700016012093150124B5226024BD29EF27BD66
+:10028000918B808B80E090E00895CF92DF92EF9287
+:10029000FF9280E091E00E941601C12CD12C7601E2
+:1002A00060E070E0CB0160930001709301018093E6
+:1002B00002019093030120E030E040E85FE30E94F8
+:1002C000F30187FF03C08FEF90E002C080E090E071
+:1002D0009093050180930401809110019091110188
+:1002E0000E945300E0910C01F0910D0180910401F6
+:1002F00080838FEFC81AD80AE80AF80AC701B60146
+:100300000E94F7012FE632E143E05BE30E94A9027D
+:1003100020E030E0A9010E948F01C5CF5058BB27D3
+:10032000AA270ED0DCC0CDD030F0D2D020F031F4EE
+:100330009F3F11F41EF4C2C00EF4E095E7FBB8C075
+:10034000E92FDED080F3BA17620773078407950799
+:1003500018F071F49EF5F6C00EF4E0950B2EBA2F4E
+:10036000A02D0B01B90190010C01CA01A0011124BB
+:10037000FF27591B99F0593F50F4503E68F11A1667
+:10038000F040A22F232F342F4427585FF3CF4695F8
+:1003900037952795A795F0405395C9F77EF41F161A
+:1003A000BA0B620B730B840BBAF09150A1F0FF0FE4
+:1003B000BB1F661F771F881FC2F70EC0BA0F621FD0
+:1003C000731F841F48F4879577956795B795F795C0
+:1003D0009E3F08F0B3CF9395880F08F09927EE0F52
+:1003E00097958795089540D008F481E00895E894A2
+:1003F00009C097FB3EF490958095709561957F4F6D
+:100400008F4F9F4F9923A9F0F92F96E9BB2793951A
+:10041000F695879577956795B795F111F8CFFAF42A
+:10042000BB0F11F460FF1BC06F5F7F4F8F4F9F4F5B
+:1004300016C0882311F096E911C0772321F09EE8B9
+:10044000872F762F05C0662371F096E8862F70E01F
+:1004500060E02AF09A95660F771F881FDAF7880FF9
+:100460009695879597F90895990F0008550FAA0B4F
+:10047000E0E8FEEF16161706E807F907C0F01216B7
+:100480001306E407F50798F0621B730B840B950BBA
+:1004900039F40A2661F0232B242B252B21F408950F
+:1004A0000A2609F4A140A6958FEF811D811D0895AC
+:1004B00097F99F6780E870E060E008959FEF80EC17
+:1004C000089500240A9416161706180609060895BA
+:1004D00000240A9412161306140605060895092E20
+:1004E0000394000C11F4882352F0BB0F40F4BF2B8F
+:1004F00011F460FF04C06F5F7F4F8F4F9F4F0895CF
+:1005000057FD9058440F551F59F05F3F71F04795C4
+:10051000880F97FB991F61F09F3F79F087950895A9
+:10052000121613061406551FF2CF4695F1DF08C0C8
+:10053000161617061806991FF1CF869571056105E5
+:1005400008940895E894BB2766277727CB0197F98D
+:1005500008950BD0C4CFB5DF28F0BADF18F095238B
+:1005600009F0A6CFABCF1124EECFCADFA0F3959F41
+:10057000D1F3950F50E0551F629FF001729FBB278A
+:10058000F00DB11D639FAA27F00DB11DAA1F649F36
+:100590006627B00DA11D661F829F2227B00DA11DE9
+:1005A000621F739FB00DA11D621F839FA00D611D6F
+:1005B000221F749F3327A00D611D231F849F600D90
+:1005C000211D822F762F6A2F11249F5750408AF0C9
+:1005D000E1F088234AF0EE0FFF1FBB1F661F771F55
+:1005E000881F91505040A9F79E3F510570F060CF91
+:1005F000AACF5F3FECF3983EDCF38695779567953D
+:10060000B795F795E7959F5FC1F7FE2B880F911D72
+:0C0610009695879597F90895F894FFCF10
+:10061C0000000000FF000AD7233C0000000000008F
+:02062C000000CC
+:00000001FF
diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/dcmotor/dcmotor_clock.sh b/OpenModelica_Arduino_With_MDD/MDD_build/dcmotor/dcmotor_clock.sh new file mode 100644 index 0000000..9ef5c4d --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/dcmotor/dcmotor_clock.sh @@ -0,0 +1,61 @@ +#!/bin/bash +clear +if [ "$#" -ne 2 ]; then + echo "Usage: $0 port baudrate" >&2 + exit 1 +fi + +re='^[0-9]+$' +if ! [[ $1 =~ $re ]] ; then + echo "error: $1 -> Not a number" >&2; exit 1 +fi + +if ! [[ $2 =~ $re ]] ; then + echo "error: $2-> Not a number" >&2; exit 1 +fi + +b_rate=$2 + +present=`pwd` +unamestr=`uname` + +if [[ "$unamestr" == 'Linux' ]]; then + mdd_path=($(locate Modelica_DeviceDrivers/Modelica_DeviceDrivers/Resources/Include)) + om_path=($(locate /usr/include/omc/c)) + port="/dev/ttyACM$1" + omc --simCodeTarget=ExperimentalEmbeddedC runMDD_dcmotor_clock.mos + if [ $? -ne 0 ]; then + exit 1 + fi +else + cd c: + om_path=($(dir -d OpenModelica*/include/omc/c/)) + path_to_om="C:$om_path" + cd f: + mdd_path=($(dir -d */Modelica_DeviceDrivers/Modelica_DeviceDrivers/Resources/Include/)) + if [ $? -eq 0 ]; then + path_to_mdd="F:/$mdd_path" + else + exit 1 + fi + + port="COM$1" + cd $present + omc --simCodeTarget=ExperimentalEmbeddedC run_dcmotor_clock.mos + if [ $? -ne 0 ]; then + exit 1 + fi +fi + +avr-gcc -Os -std=c11 -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000UL -Wl,--gc-sections dcmotor_clock_main.c -o dcmotor_clock -I${mdd_path[0]} -I${path_to_om} -I${path_to_mdd} -I${om_path[0]} +if [ $? -ne 0 ]; then + exit 1 +fi +avr-objcopy -O ihex -R .eeprom dcmotor_clock dcmotor_clock.hex +if [ $? -ne 0 ]; then + exit 1 +fi +avrdude -F -V -c arduino -p ATMEGA328P -P $port -b $b_rate -U flash:w:dcmotor_clock.hex +if [ $? -ne 0 ]; then + exit 1 +fi
\ No newline at end of file diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/dcmotor/dcmotor_clock_main.c b/OpenModelica_Arduino_With_MDD/MDD_build/dcmotor/dcmotor_clock_main.c new file mode 100644 index 0000000..ae3eff7 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/dcmotor/dcmotor_clock_main.c @@ -0,0 +1,213 @@ +#define fmi2TypesPlatform_h + +#define fmi2TypesPlatform "default" /* Compatible */ + +typedef struct dcmotor_clock_fmi2Component_s* fmi2Component; +typedef void* fmi2ComponentEnvironment; /* Pointer to FMU environment */ +typedef void* fmi2FMUstate; /* Pointer to internal FMU state */ +typedef unsigned int fmi2ValueReference; +typedef double fmi2Real; +typedef int fmi2Integer; +typedef int fmi2Boolean; +typedef char fmi2Char; +typedef const fmi2Char* fmi2String; +typedef char fmi2Byte; + +#define fmi2True 1 +#define fmi2False 0 + +#include "fmi2/fmi2Functions.h" + +#include <stdint.h> +#include <stdio.h> + +void ModelicaFormatMessage(const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + vprintf(fmt, args); + va_end(args); +} + +typedef struct dcmotor_clock_fmi2Component_s { + fmi2Real currentTime; + fmi2Integer fmi2IntegerVars[1]; + fmi2Real fmi2RealParameter[1]; + void* extObjs[4]; +} dcmotor_clock_fmi2Component; + +dcmotor_clock_fmi2Component dcmotor_clock_component = { + .fmi2IntegerVars = { + 255 /*pwm._u[1]*/, + }, + .fmi2RealParameter = { + 0.01 /*synchronizeRealtime1._actualInterval*/, + }, +}; + +#include <math.h> +/* TODO: Generate used builtin functions before SimCode */ +static inline double om_mod(double x, double y) +{ + return x-floor(x/y)*y; +} + +#include "MDDAVRTimer.h" +#include "MDDAVRRealTime.h" +#include "MDDAVRAnalog.h" + +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_set(fmi2Component comp, void* om_pwm, fmi2Integer om_value); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_pin, fmi2Integer om_initialValue, fmi2Boolean om_inverted); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_Init_destructor(fmi2Component comp, void* om_pwm); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer); + +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_set(fmi2Component comp, void* om_pwm, fmi2Integer om_value) +{ + MDD_avr_pwm_set(om_pwm, om_value); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_pin, fmi2Integer om_initialValue, fmi2Boolean om_inverted) +{ + void* om_pwm; + om_pwm = MDD_avr_pwm_init(om_timer, om_pin, om_initialValue, om_inverted); + return om_pwm; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_Init_destructor(fmi2Component comp, void* om_pwm) +{ + MDD_avr_pwm_close(om_pwm); +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt) +{ + MDD_avr_rt_wait(om_rt); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle) +{ + void* om_rt; + om_rt = MDD_avr_rt_init(om_timer, om_timerValue, om_numTimerInterruptsPerCycle); + return om_rt; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt) +{ + MDD_avr_rt_close(om_rt); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch) +{ + void* om_timer; + om_timer = MDD_avr_timer_init(om_timerSelect, om_clockSelect, om_clearTimerOnMatch); + return om_timer; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer) +{ + MDD_avr_timer_close(om_timer); +} + +fmi2Component dcmotor_clock_fmi2Instantiate(fmi2String name, fmi2Type ty, fmi2String GUID, fmi2String resources, const fmi2CallbackFunctions* functions, fmi2Boolean visible, fmi2Boolean loggingOn) +{ + static int initDone=0; + if (initDone) { + return NULL; + } + return &dcmotor_clock_component; +} + +fmi2Status dcmotor_clock_fmi2SetupExperiment(fmi2Component comp, fmi2Boolean toleranceDefined, fmi2Real tolerance, fmi2Real startTime, fmi2Boolean stopTimeDefined, fmi2Real stopTime) +{ + return fmi2OK; +} + +fmi2Status dcmotor_clock_fmi2EnterInitializationMode(fmi2Component comp) +{ + comp->extObjs[0] /* pwm._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(comp, 2, 7, fmi2True); + comp->extObjs[1] /* pwm._pwm[1] EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.PWM.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_Init_constructor(comp, comp->extObjs[0] /* pwm._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */, 2, 0, fmi2False); + comp->extObjs[2] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(comp, 1, 4, fmi2False); + comp->extObjs[3] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(comp, comp->extObjs[2] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */, 249, 10); + return fmi2OK; +} + +fmi2Status dcmotor_clock_fmi2ExitInitializationMode(fmi2Component comp) +{ + return fmi2OK; +} + +static fmi2Status dcmotor_clock_functionODE(fmi2Component comp) +{ +} + +static fmi2Status dcmotor_clock_functionOutputs(fmi2Component comp) +{ + comp->fmi2IntegerVars[0] /* pwm._u[1] DISCRETE */ = ((comp->currentTime)<(1.0)) ? (255) : (0); /* equation 3 */Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(comp, comp->extObjs[3] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */);Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_set(comp, comp->extObjs[1] /* pwm._pwm[1] EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.PWM.Init */, comp->fmi2IntegerVars[0] /* pwm._u[1] DISCRETE */); +} + +fmi2Status dcmotor_clock_fmi2DoStep(fmi2Component comp, fmi2Real currentCommunicationPoint, fmi2Real communicationStepSize, fmi2Boolean noSetFMUStatePriorToCurrentPoint) +{ + comp->currentTime = currentCommunicationPoint; + /* TODO: Calculate time/state-dependent variables here... */ + dcmotor_clock_functionOutputs(comp); + return fmi2OK; +} + +int main(int argc, char **argv) +{ + int terminateSimulation = 0; + fmi2Status status = fmi2OK; + fmi2CallbackFunctions cbf = { + .logger = NULL, + .allocateMemory = NULL /*calloc*/, + .freeMemory = NULL /*free*/, + .stepFinished = NULL, //synchronous execution + .componentEnvironment = NULL + }; + + fmi2Component comp = dcmotor_clock_fmi2Instantiate("", fmi2CoSimulation, "", "", &cbf, fmi2False, fmi2False); + if (comp==NULL) { + return 1; + } + dcmotor_clock_fmi2SetupExperiment(comp, fmi2False, 0.0, 0.0, fmi2False, 1.0); + dcmotor_clock_fmi2EnterInitializationMode(comp); + // Set start-values? Nah... + dcmotor_clock_fmi2ExitInitializationMode(comp); + + double currentTime = 0.0; + double h = 0.002; + uint32_t i = 0; + + while (status == fmi2OK) { + //retrieve outputs + // fmi2GetReal(m, ..., 1, &y1); + //set inputs + // fmi2SetReal(m, ..., 1, &y2); + + //call slave and check status + status = dcmotor_clock_fmi2DoStep(comp, currentTime, h, fmi2True); + switch (status) { + case fmi2Discard: + case fmi2Error: + case fmi2Fatal: + case fmi2Pending /* Cannot happen */: + terminateSimulation = 1; + break; + case fmi2OK: + case fmi2Warning: + break; + } + if (terminateSimulation) { + break; + } + i++; + /* increment master time */ + currentTime = 0.0 + h*i; + } + +#if 0 + if ((status != fmi2Error) && (status != fmi2Fatal)) { + fmi2Terminate(m); + } + if (status != fmi2Fatal) { + fmi2FreeInstance(m); + } +#endif +} + diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/dcmotor/dcmotor_loop b/OpenModelica_Arduino_With_MDD/MDD_build/dcmotor/dcmotor_loop Binary files differnew file mode 100644 index 0000000..36d8f3b --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/dcmotor/dcmotor_loop diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/dcmotor/dcmotor_loop.hex b/OpenModelica_Arduino_With_MDD/MDD_build/dcmotor/dcmotor_loop.hex new file mode 100644 index 0000000..119035b --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/dcmotor/dcmotor_loop.hex @@ -0,0 +1,135 @@ +:100000000C9434000C9451000C9451000C94510049
+:100010000C9451000C9451000C9451000C94380134
+:100020000C9451000C9451000C9451000C94070155
+:100030000C9451000C9451000C94D6000C94510077
+:100040000C9451000C9451000C9451000C945100EC
+:100050000C9451000C9451000C9451000C945100DC
+:100060000C9451000C94510011241FBECFEFD8E026
+:10007000DEBFCDBF11E0A0E0B1E0E8E3F8E002C0F0
+:1000800005900D92A831B107D9F711E0A8E1B1E0D0
+:1000900001C01D92AD31B107E1F70E94AE010C9491
+:1000A0001A040C940000CF92DF92EF92FF92CF934C
+:1000B000DF93EC01C880D980EA80FB8020E030E04B
+:1000C00040EC50E4C701B6010E9446020E94EB02D8
+:1000D00020E030E040EC50E40E94B7039B01AC010B
+:1000E000C701B6010E94DD016B017C0120E030E018
+:1000F00040E450E40E94420287FF03C08FEF90E08B
+:1001000002C080E090E09D838C8320E030E040E4FA
+:1001100050E4C701B6010E94B30318161CF48FEF18
+:1001200090E002C080E090E09F838E838E899F895B
+:100130008230910561F08330910599F00197C9F4FF
+:1001400016BC80916E00826080936E0016C0109283
+:1001500085001092840080916F00826080936F0010
+:100160000CC01092B2008091700082608093700089
+:1001700004C081E090E00E941A0478949FB7F8943C
+:1001800080911A019FBF8823C9F310921A01EE854E
+:10019000FF858C818083EA89FB898E818083DF9152
+:1001A000CF91FF90EF90DF90CF9008951F920F9224
+:1001B0000FB60F9211242F933F938F939F938091AB
+:1001C00018019091190101969093190180931801DB
+:1001D00080911A01813091F020911801309119011C
+:1001E00080911B0190911C012817390738F081E09C
+:1001F00080931A0110921901109218019F918F910A
+:100200003F912F910F900FBE0F901F9018951F9246
+:100210000F920FB60F9211242F933F938F939F93BA
+:100220008091180190911901019690931901809382
+:10023000180180911A01813091F0209118013091BC
+:10024000190180911B0190911C012817390738F082
+:1002500081E080931A0110921901109218019F9168
+:100260008F913F912F910F900FBE0F901F90189577
+:100270001F920F920FB60F9211242F933F938F93DB
+:100280009F93809118019091190101969093190103
+:100290008093180180911A01813091F0209118010A
+:1002A0003091190180911B0190911C012817390789
+:1002B00038F081E080931A01109219011092180110
+:1002C0009F918F913F912F910F900FBE0F901F9094
+:1002D0001895CF93DF93FC01C1E8D0E088818D6051
+:1002E000888382E090E0918B808B229A40E850E0F6
+:1002F000DA012C9121622C932AE830E0D901119681
+:100300001C921E921C92338B228B28812D60288395
+:1003100095878487219ADA012C9121682C93A8E88B
+:10032000B0E011961C921E921C92B787A68725B545
+:10033000236025BD21E030E0358B248B90931C0198
+:1003400080931B0184B5826084BD89EF87BD378BA4
+:10035000268B80E090E0DF91CF910895CF92DF92DD
+:10036000EF92FF9280E091E00E946901C12CD12CB4
+:10037000760160E070E0CB016093000170930101B1
+:10038000809302019093030180E091E00E9453006A
+:100390008FEFC81AD80AE80AF80AC701B6010E9406
+:1003A000AE022FE632E143E05BE30E94B70320E0B8
+:1003B00030E0A9010E94DE01DFCF5058BB27AA27F9
+:1003C0000ED080C171D130F076D120F031F49F3F52
+:1003D00011F41EF466C10EF4E095E7FB33C1E92F7A
+:1003E00082D180F3BA17620773078407950718F064
+:1003F00071F49EF5B1C10EF4E0950B2EBA2FA02D2D
+:100400000B01B90190010C01CA01A0011124FF27C1
+:10041000591B99F0593F50F4503E68F11A16F040BC
+:10042000A22F232F342F4427585FF3CF46953795BB
+:100430002795A795F0405395C9F77EF41F16BA0B80
+:10044000620B730B840BBAF09150A1F0FF0FBB1F2E
+:10045000661F771F881FC2F70EC0BA0F621F731F77
+:10046000841F48F4879577956795B795F7959E3FD4
+:1004700008F0B3CF9395880F08F09927EE0F979562
+:1004800087950895BBD008F481E008950CD01AC177
+:1004900012D140F009D130F021F45F3F19F0D2C001
+:1004A00051115BC1FEC01FD198F39923C9F35523A5
+:1004B000B1F3951B550BBB27AA2762177307840757
+:1004C00038F09F5F5F4F220F331F441FAA1FA9F30D
+:1004D00033D00E2E3AF0E0E830D091505040E695FF
+:1004E000001CCAF729D0FE2F27D0660F771F881F60
+:1004F000BB1F261737074807AB07B0E809F0BB0B4F
+:10050000802DBF01FF2793585F4F2AF09E3F510572
+:1005100068F098C022C15F3FECF3983EDCF386950B
+:1005200077956795B795F7959F5FC9F7880F911DE8
+:100530009695879597F90895E1E0660F771F881FD4
+:10054000BB1F621773078407BA0720F0621B730B87
+:10055000840BBA0BEE1F88F7E0950895E89409C064
+:1005600097FB3EF490958095709561957F4F8F4FE6
+:100570009F4F9923A9F0F92F96E9BB279395F695FC
+:10058000879577956795B795F111F8CFFAF4BB0F7A
+:1005900011F460FF1BC06F5F7F4F8F4F9F4F16C0DE
+:1005A000882311F096E911C0772321F09EE8872F68
+:1005B000762F05C0662371F096E8862F70E060E024
+:1005C0002AF09A95660F771F881FDAF7880F96959D
+:1005D000879597F90895A9D080F09F3740F491113D
+:1005E0000EF0BBC060E070E080E89FEB089526F459
+:1005F0001B16611D711D811D2BC045C0990F000880
+:10060000550FAA0BE0E8FEEF16161706E807F907E4
+:10061000C0F012161306E407F50798F0621B730B7F
+:10062000840B950B39F40A2661F0232B242B252B00
+:1006300021F408950A2609F4A140A6958FEF811DA3
+:10064000811D089597F99F6780E870E060E0089544
+:10065000882371F4772321F09850872B762F07C0D9
+:10066000662311F499270DC09051862B70E060E04D
+:100670002AF09A95660F771F881FDAF7880F9695EC
+:10068000879597F908959F3F31F0915020F4879511
+:1006900077956795B795880F911D9695879597F9EA
+:1006A00008959FEF80EC089500240A94161617060B
+:1006B00018060906089500240A9412161306140653
+:1006C00005060895092E0394000C11F4882352F0B6
+:1006D000BB0F40F4BF2B11F460FF04C06F5F7F4F6E
+:1006E0008F4F9F4F089557FD9058440F551F59F055
+:1006F0005F3F71F04795880F97FB991F61F09F3F0F
+:1007000079F087950895121613061406551FF2CF37
+:100710004695F1DF08C0161617061806991FF1CF87
+:1007200086957105610508940895E5DFA0F0BEE7A0
+:10073000B91788F4BB279F3860F41616B11D672FD0
+:10074000782F8827985FF7CF869577956795B11DA5
+:1007500093959639C8F30895E894BB2766277727C1
+:10076000CB0197F908954ADF08F48FEF08950BD075
+:10077000A9CF9ADF28F09FDF18F0952309F062CF08
+:1007800090CF1124EACFAFDFA0F3959FD1F3950F5F
+:1007900050E0551F629FF001729FBB27F00DB11D05
+:1007A000639FAA27F00DB11DAA1F649F6627B00D95
+:1007B000A11D661F829F2227B00DA11D621F739F7E
+:1007C000B00DA11D621F839FA00D611D221F749F8C
+:1007D0003327A00D611D231F849F600D211D822FD3
+:1007E000762F6A2F11249F5750408AF0E1F088231A
+:1007F0004AF0EE0FFF1FBB1F661F771F881F915027
+:100800005040A9F79E3F510570F01CCFA6CF5F3F27
+:10081000ECF3983EDCF3869577956795B795F79559
+:10082000E7959F5FC1F7FE2B880F911D96958795E1
+:0808300097F90895F894FFCF39
+:1008380000000000000000006F12033B00000000F1
+:080848000000000000000000A8
+:00000001FF
diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/dcmotor/dcmotor_loop.sh b/OpenModelica_Arduino_With_MDD/MDD_build/dcmotor/dcmotor_loop.sh new file mode 100644 index 0000000..38ca771 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/dcmotor/dcmotor_loop.sh @@ -0,0 +1,61 @@ +#!/bin/bash +clear +if [ "$#" -ne 2 ]; then + echo "Usage: $0 port baudrate" >&2 + exit 1 +fi + +re='^[0-9]+$' +if ! [[ $1 =~ $re ]] ; then + echo "error: $1 -> Not a number" >&2; exit 1 +fi + +if ! [[ $2 =~ $re ]] ; then + echo "error: $2-> Not a number" >&2; exit 1 +fi + +b_rate=$2 + +present=`pwd` +unamestr=`uname` + +if [[ "$unamestr" == 'Linux' ]]; then + mdd_path=($(locate Modelica_DeviceDrivers/Modelica_DeviceDrivers/Resources/Include)) + om_path=($(locate /usr/include/omc/c)) + port="/dev/ttyACM$1" + omc --simCodeTarget=ExperimentalEmbeddedC runMDD_dcmotor_loop.mos + if [ $? -ne 0 ]; then + exit 1 + fi +else + cd c: + om_path=($(dir -d OpenModelica*/include/omc/c/)) + path_to_om="C:$om_path" + cd f: + mdd_path=($(dir -d */Modelica_DeviceDrivers/Modelica_DeviceDrivers/Resources/Include/)) + if [ $? -eq 0 ]; then + path_to_mdd="F:/$mdd_path" + else + exit 1 + fi + + port="COM$1" + cd $present + omc --simCodeTarget=ExperimentalEmbeddedC run_dcmotor_loop.mos + if [ $? -ne 0 ]; then + exit 1 + fi +fi + +avr-gcc -Os -std=c11 -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000UL -Wl,--gc-sections dcmotor_loop_main.c -o dcmotor_loop -I${mdd_path[0]} -I${path_to_om} -I${path_to_mdd} -I${om_path[0]} +if [ $? -ne 0 ]; then + exit 1 +fi +avr-objcopy -O ihex -R .eeprom dcmotor_loop dcmotor_loop.hex +if [ $? -ne 0 ]; then + exit 1 +fi +avrdude -F -V -c arduino -p ATMEGA328P -P $port -b $b_rate -U flash:w:dcmotor_loop.hex +if [ $? -ne 0 ]; then + exit 1 +fi
\ No newline at end of file diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/dcmotor/dcmotor_loop_main.c b/OpenModelica_Arduino_With_MDD/MDD_build/dcmotor/dcmotor_loop_main.c new file mode 100644 index 0000000..581a9d6 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/dcmotor/dcmotor_loop_main.c @@ -0,0 +1,217 @@ +#define fmi2TypesPlatform_h + +#define fmi2TypesPlatform "default" /* Compatible */ + +typedef struct dcmotor_loop_fmi2Component_s* fmi2Component; +typedef void* fmi2ComponentEnvironment; /* Pointer to FMU environment */ +typedef void* fmi2FMUstate; /* Pointer to internal FMU state */ +typedef unsigned int fmi2ValueReference; +typedef double fmi2Real; +typedef int fmi2Integer; +typedef int fmi2Boolean; +typedef char fmi2Char; +typedef const fmi2Char* fmi2String; +typedef char fmi2Byte; + +#define fmi2True 1 +#define fmi2False 0 + +#include "fmi2/fmi2Functions.h" + +#include <stdint.h> +#include <stdio.h> + +void ModelicaFormatMessage(const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + vprintf(fmt, args); + va_end(args); +} + +typedef struct dcmotor_loop_fmi2Component_s { + fmi2Real currentTime; + fmi2Integer fmi2IntegerVars[2]; + fmi2Real fmi2RealParameter[1]; + void* extObjs[6]; +} dcmotor_loop_fmi2Component; + +dcmotor_loop_fmi2Component dcmotor_loop_component = { + .fmi2IntegerVars = { + 0 /*pwm._u[1]*/, + 0 /*pwm1._u[1]*/, + }, + .fmi2RealParameter = { + 0.002 /*synchronizeRealtime1._actualInterval*/, + }, +}; + +#include <math.h> +/* TODO: Generate used builtin functions before SimCode */ +static inline double om_mod(double x, double y) +{ + return x-floor(x/y)*y; +} + +#include "MDDAVRTimer.h" +#include "MDDAVRRealTime.h" +#include "MDDAVRAnalog.h" + +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_set(fmi2Component comp, void* om_pwm, fmi2Integer om_value); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_pin, fmi2Integer om_initialValue, fmi2Boolean om_inverted); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_Init_destructor(fmi2Component comp, void* om_pwm); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer); + +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_set(fmi2Component comp, void* om_pwm, fmi2Integer om_value) +{ + MDD_avr_pwm_set(om_pwm, om_value); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_pin, fmi2Integer om_initialValue, fmi2Boolean om_inverted) +{ + void* om_pwm; + om_pwm = MDD_avr_pwm_init(om_timer, om_pin, om_initialValue, om_inverted); + return om_pwm; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_Init_destructor(fmi2Component comp, void* om_pwm) +{ + MDD_avr_pwm_close(om_pwm); +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt) +{ + MDD_avr_rt_wait(om_rt); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle) +{ + void* om_rt; + om_rt = MDD_avr_rt_init(om_timer, om_timerValue, om_numTimerInterruptsPerCycle); + return om_rt; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt) +{ + MDD_avr_rt_close(om_rt); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch) +{ + void* om_timer; + om_timer = MDD_avr_timer_init(om_timerSelect, om_clockSelect, om_clearTimerOnMatch); + return om_timer; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer) +{ + MDD_avr_timer_close(om_timer); +} + +fmi2Component dcmotor_loop_fmi2Instantiate(fmi2String name, fmi2Type ty, fmi2String GUID, fmi2String resources, const fmi2CallbackFunctions* functions, fmi2Boolean visible, fmi2Boolean loggingOn) +{ + static int initDone=0; + if (initDone) { + return NULL; + } + return &dcmotor_loop_component; +} + +fmi2Status dcmotor_loop_fmi2SetupExperiment(fmi2Component comp, fmi2Boolean toleranceDefined, fmi2Real tolerance, fmi2Real startTime, fmi2Boolean stopTimeDefined, fmi2Real stopTime) +{ + return fmi2OK; +} + +fmi2Status dcmotor_loop_fmi2EnterInitializationMode(fmi2Component comp) +{ + comp->extObjs[2] /* pwm1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(comp, 2, 7, fmi2True); + comp->extObjs[3] /* pwm1._pwm[1] EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.PWM.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_Init_constructor(comp, comp->extObjs[2] /* pwm1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */, 2, 0, fmi2False); + comp->extObjs[0] /* pwm._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(comp, 2, 7, fmi2True); + comp->extObjs[1] /* pwm._pwm[1] EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.PWM.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_Init_constructor(comp, comp->extObjs[0] /* pwm._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */, 1, 0, fmi2False); + comp->extObjs[4] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(comp, 1, 4, fmi2False); + comp->extObjs[5] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(comp, comp->extObjs[4] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */, 249, 2); + return fmi2OK; +} + +fmi2Status dcmotor_loop_fmi2ExitInitializationMode(fmi2Component comp) +{ + return fmi2OK; +} + +static fmi2Status dcmotor_loop_functionODE(fmi2Component comp) +{ +} + +static fmi2Status dcmotor_loop_functionOutputs(fmi2Component comp) +{ + comp->fmi2IntegerVars[0] /* pwm._u[1] DISCRETE */ = ((om_mod(comp->currentTime,6.0))<(3.0)) ? (255) : (0); /* equation 4 */ + comp->fmi2IntegerVars[1] /* pwm1._u[1] DISCRETE */ = ((om_mod(comp->currentTime,6.0))>(3.0)) ? (255) : (0); /* equation 5 */Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(comp, comp->extObjs[5] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */);Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_set(comp, comp->extObjs[1] /* pwm._pwm[1] EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.PWM.Init */, comp->fmi2IntegerVars[0] /* pwm._u[1] DISCRETE */);Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_set(comp, comp->extObjs[3] /* pwm1._pwm[1] EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.PWM.Init */, comp->fmi2IntegerVars[1] /* pwm1._u[1] DISCRETE */); +} + +fmi2Status dcmotor_loop_fmi2DoStep(fmi2Component comp, fmi2Real currentCommunicationPoint, fmi2Real communicationStepSize, fmi2Boolean noSetFMUStatePriorToCurrentPoint) +{ + comp->currentTime = currentCommunicationPoint; + /* TODO: Calculate time/state-dependent variables here... */ + dcmotor_loop_functionOutputs(comp); + return fmi2OK; +} + +int main(int argc, char **argv) +{ + int terminateSimulation = 0; + fmi2Status status = fmi2OK; + fmi2CallbackFunctions cbf = { + .logger = NULL, + .allocateMemory = NULL /*calloc*/, + .freeMemory = NULL /*free*/, + .stepFinished = NULL, //synchronous execution + .componentEnvironment = NULL + }; + + fmi2Component comp = dcmotor_loop_fmi2Instantiate("", fmi2CoSimulation, "", "", &cbf, fmi2False, fmi2False); + if (comp==NULL) { + return 1; + } + dcmotor_loop_fmi2SetupExperiment(comp, fmi2False, 0.0, 0.0, fmi2False, 1.0); + dcmotor_loop_fmi2EnterInitializationMode(comp); + // Set start-values? Nah... + dcmotor_loop_fmi2ExitInitializationMode(comp); + + double currentTime = 0.0; + double h = 0.002; + uint32_t i = 0; + + while (status == fmi2OK) { + //retrieve outputs + // fmi2GetReal(m, ..., 1, &y1); + //set inputs + // fmi2SetReal(m, ..., 1, &y2); + + //call slave and check status + status = dcmotor_loop_fmi2DoStep(comp, currentTime, h, fmi2True); + switch (status) { + case fmi2Discard: + case fmi2Error: + case fmi2Fatal: + case fmi2Pending /* Cannot happen */: + terminateSimulation = 1; + break; + case fmi2OK: + case fmi2Warning: + break; + } + if (terminateSimulation) { + break; + } + i++; + /* increment master time */ + currentTime = 0.0 + h*i; + } + +#if 0 + if ((status != fmi2Error) && (status != fmi2Fatal)) { + fmi2Terminate(m); + } + if (status != fmi2Fatal) { + fmi2FreeInstance(m); + } +#endif +} + diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/dcmotor/runMDD_dcmotor_both.mos b/OpenModelica_Arduino_With_MDD/MDD_build/dcmotor/runMDD_dcmotor_both.mos new file mode 100644 index 0000000..c776b9a --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/dcmotor/runMDD_dcmotor_both.mos @@ -0,0 +1,11 @@ +loadModel(Modelica); +getErrorString(); + +loadFile("/home/souradip/Modelica_DeviceDrivers/Modelica_DeviceDrivers/package.mo"); +getErrorString(); + +loadFile("/home/souradip/OpenModelica/Arduino.mo"); +getErrorString(); + +translateModel(Arduino.SerialCommunication.MDD_Examples.MDD_dcmotor.MDD_dcmotor_both, fileNamePrefix="dcmotor_both"); +getErrorString(); diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/dcmotor/runMDD_dcmotor_clock.mos b/OpenModelica_Arduino_With_MDD/MDD_build/dcmotor/runMDD_dcmotor_clock.mos new file mode 100644 index 0000000..4f2e6ed --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/dcmotor/runMDD_dcmotor_clock.mos @@ -0,0 +1,11 @@ +loadModel(Modelica); +getErrorString(); + +loadFile("/home/souradip/Modelica_DeviceDrivers/Modelica_DeviceDrivers/package.mo"); +getErrorString(); + +loadFile("/home/souradip/OpenModelica/Arduino.mo"); +getErrorString(); + +translateModel(Arduino.SerialCommunication.MDD_Examples.MDD_dcmotor.MDD_dcmotor_clock, fileNamePrefix="dcmotor_clock"); +getErrorString(); diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/dcmotor/runMDD_dcmotor_loop.mos b/OpenModelica_Arduino_With_MDD/MDD_build/dcmotor/runMDD_dcmotor_loop.mos new file mode 100644 index 0000000..05800fc --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/dcmotor/runMDD_dcmotor_loop.mos @@ -0,0 +1,11 @@ +loadModel(Modelica); +getErrorString(); + +loadFile("/home/souradip/Modelica_DeviceDrivers/Modelica_DeviceDrivers/package.mo"); +getErrorString(); + +loadFile("/home/souradip/OpenModelica/Arduino.mo"); +getErrorString(); + +translateModel(Arduino.SerialCommunication.MDD_Examples.MDD_dcmotor.MDD_dcmotor_loop, fileNamePrefix="dcmotor_loop"); +getErrorString(); diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/ldr/ldr_led b/OpenModelica_Arduino_With_MDD/MDD_build/ldr/ldr_led Binary files differnew file mode 100644 index 0000000..08ef23c --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/ldr/ldr_led diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/ldr/ldr_led.hex b/OpenModelica_Arduino_With_MDD/MDD_build/ldr/ldr_led.hex new file mode 100644 index 0000000..cc58777 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/ldr/ldr_led.hex @@ -0,0 +1,120 @@ +:100000000C9434000C9451000C9451000C94510049
+:100010000C9451000C9451000C9451000C9431013B
+:100020000C9451000C9451000C9451000C9400015C
+:100030000C9451000C9451000C94CF000C9451007E
+:100040000C9451000C9451000C9451000C945100EC
+:100050000C9451000C9451000C9451000C945100DC
+:100060000C9451000C94510011241FBECFEFD8E026
+:10007000DEBFCDBF11E0A0E0B1E0E4E4F7E002C0F4
+:1000800005900D92AE31B107D9F711E0AEE1B1E0C4
+:1000900001C01D92A332B107E1F70E948B010C94BD
+:1000A000A0030C9400000F931F93CF93DF93EC01F8
+:1000B00080917C00857E856080937C0080917A00B1
+:1000C000806480937A0080917A0086FDFCCF6091F5
+:1000D00078007091790080E090E00E94870220E033
+:1000E00030E040E854E40E94190320E030EC4FE790
+:1000F00054E40E941F026C837D838E839F8301E002
+:1001000010E02E853F85488959890E9415031816ED
+:1001100014F000E010E01D870C878C8D9D8D8230DF
+:10012000910561F08330910599F00197C9F416BCEF
+:1001300080916E00826080936E0016C010928500E0
+:100140001092840080916F00826080936F000CC0D9
+:100150001092B2008091700082608093700004C0A1
+:1001600081E090E00E94A00378949FB7F89480917A
+:1001700020019FBF8823C9F310922001E88DF98DDB
+:100180008C859D85892B19F08081826002C08081D9
+:100190008D7F8083DF91CF911F910F9108951F92E2
+:1001A0000F920FB60F9211242F933F938F939F932B
+:1001B00080911E0190911F01019690931F018093E1
+:1001C0001E0180912001813091F020911E0130911B
+:1001D0001F0180912101909122012817390738F0E1
+:1001E00081E08093200110921F0110921E019F91C7
+:1001F0008F913F912F910F900FBE0F901F901895E8
+:100200001F920F920FB60F9211242F933F938F934B
+:100210009F9380911E0190911F01019690931F0161
+:1002200080931E0180912001813091F020911E0168
+:1002300030911F01809121019091220128173907E7
+:1002400038F081E08093200110921F0110921E016E
+:100250009F918F913F912F910F900FBE0F901F9004
+:1002600018951F920F920FB60F9211242F933F9360
+:100270008F939F9380911E0190911F0101969093FF
+:100280001F0180931E0180912001813091F0209107
+:100290001E0130911F0180912101909122012817A8
+:1002A000390738F081E08093200110921F011092ED
+:1002B0001E019F918F913F912F910F900FBE0F9034
+:1002C0001F901895FC01ACE7B0E08C91806C8C938A
+:1002D000AAE7B0E08C9187688C93178A168A219AD6
+:1002E00085E290E0918F808F85B5836085BD81E048
+:1002F00090E0938F828F22E030E0309322012093B0
+:10030000210124B5226024BD29EF27BD958F848F5C
+:1003100080E090E00895CF92DF92EF92FF9280E02C
+:1003200091E00E946201C12CD12C760160E070E066
+:10033000CB016093000170930101809302019093BF
+:10034000030180E091E00E9453008FEFC81AD80AA1
+:10035000E80AF80AC701B6010E9487022FE632E1D7
+:1003600043E05BE30E94190320E030E0A9010E9412
+:10037000BB01DFCF5058BB27AA270ED01CC10DD11F
+:1003800030F012D120F031F49F3F11F41EF402C17D
+:100390000EF4E095E7FBF8C0E92F1ED180F3BA1701
+:1003A000620773078407950718F071F49EF536C14C
+:1003B0000EF4E0950B2EBA2FA02D0B01B901900180
+:1003C0000C01CA01A0011124FF27591B99F0593FC4
+:1003D00050F4503E68F11A16F040A22F232F342F0C
+:1003E0004427585FF3CF469537952795A795F0405A
+:1003F0005395C9F77EF41F16BA0B620B730B840B6F
+:10040000BAF09150A1F0FF0FBB1F661F771F881F26
+:10041000C2F70EC0BA0F621F731F841F48F487957E
+:1004200077956795B795F7959E3F08F0B3CF93956D
+:10043000880F08F09927EE0F9795879508950CD0AF
+:10044000BAC0B2D040F0A9D030F021F45F3F19F02B
+:100450009BC05111E4C09EC0BFD098F39923C9F34B
+:100460005523B1F3951B550BBB27AA2762177307BA
+:10047000840738F09F5F5F4F220F331F441FAA1F6E
+:10048000A9F333D00E2E3AF0E0E830D0915050402E
+:10049000E695001CCAF729D0FE2F27D0660F771FDC
+:1004A000881FBB1F261737074807AB07B0E809F0BE
+:1004B000BB0B802DBF01FF2793585F4F2AF09E3F53
+:1004C000510568F061C0ABC05F3FECF3983EDCF3D0
+:1004D000869577956795B795F7959F5FC9F7880FCC
+:1004E000911D9695879597F90895E1E0660F771F1E
+:1004F000881FBB1F621773078407BA0720F0621BAF
+:10050000730B840BBA0BEE1F88F7E0950895E894FF
+:1005100009C097FB3EF490958095709561957F4F4B
+:100520008F4F9F4F9923A9F0F92F96E9BB279395F9
+:10053000F695879577956795B795F111F8CFFAF409
+:10054000BB0F11F460FF1BC06F5F7F4F8F4F9F4F3A
+:1005500016C0882311F096E911C0772321F09EE898
+:10056000872F762F05C0662371F096E8862F70E0FE
+:1005700060E02AF09A95660F771F881FDAF7880FD8
+:100580009695879597F9089597F99F6780E870E0A9
+:1005900060E008959FEF80EC089500240A941616F9
+:1005A000170618060906089500240A941216130661
+:1005B000140605060895092E0394000C11F48823EF
+:1005C00052F0BB0F40F4BF2B11F460FF04C06F5F0B
+:1005D0007F4F8F4F9F4F089557FD9058440F551FE1
+:1005E00059F05F3F71F04795880F97FB991F61F0B5
+:1005F0009F3F79F087950895121613061406551F2C
+:10060000F2CF4695F1DF08C0161617061806991F97
+:10061000F1CF86957105610508940895E894BB278C
+:1006200066277727CB0197F9089566D008F48FEFF6
+:1006300008950BD0C0CFB1DF28F0B6DF18F09523B6
+:1006400009F0A2CFA7CF1124EACFC6DFA0F3959F70
+:10065000D1F3950F50E0551F629FF001729FBB27A9
+:10066000F00DB11D639FAA27F00DB11DAA1F649F55
+:100670006627B00DA11D661F829F2227B00DA11D08
+:10068000621F739FB00DA11D621F839FA00D611D8E
+:10069000221F749F3327A00D611D231F849F600DAF
+:1006A000211D822F762F6A2F11249F5750408AF0E8
+:1006B000E1F088234AF0EE0FFF1FBB1F661F771F74
+:1006C000881F91505040A9F79E3F510570F05CCFB4
+:1006D000A6CF5F3FECF3983EDCF386957795679560
+:1006E000B795F795E7959F5FC1F7FE2B880F911D92
+:1006F0009695879597F90895990F0008550FAA0BBD
+:10070000E0E8FEEF16161706E807F907C0F0121624
+:100710001306E407F50798F0621B730B840B950B27
+:1007200039F40A2661F0232B242B252B21F408957C
+:100730000A2609F4A140A6958FEF811D811D089519
+:04074000F894FFCF5B
+:1007440000000000000000000000000000000000A5
+:0E07540016446F12033B00000000000000007E
+:00000001FF
diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/ldr/ldr_led.sh b/OpenModelica_Arduino_With_MDD/MDD_build/ldr/ldr_led.sh new file mode 100644 index 0000000..48dfad2 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/ldr/ldr_led.sh @@ -0,0 +1,61 @@ +#!/bin/bash +clear +if [ "$#" -ne 2 ]; then + echo "Usage: $0 port baudrate" >&2 + exit 1 +fi + +re='^[0-9]+$' +if ! [[ $1 =~ $re ]] ; then + echo "error: $1 -> Not a number" >&2; exit 1 +fi + +if ! [[ $2 =~ $re ]] ; then + echo "error: $2-> Not a number" >&2; exit 1 +fi + +b_rate=$2 + +present=`pwd` +unamestr=`uname` + +if [[ "$unamestr" == 'Linux' ]]; then + mdd_path=($(locate Modelica_DeviceDrivers/Resources/Include)) + om_path=($(locate /usr/include/omc/c)) + port="/dev/ttyACM$1" + omc --simCodeTarget=ExperimentalEmbeddedC runMDD_ldr_led.mos + if [ $? -ne 0 ]; then + exit 1 + fi +else + cd c: + om_path=($(dir -d OpenModelica*/include/omc/c/)) + path_to_om="C:$om_path" + cd f: + mdd_path=($(dir -d */Modelica_DeviceDrivers/Resources/Include/)) + if [ $? -eq 0 ]; then + path_to_mdd="F:/$mdd_path" + else + exit 1 + fi + + port="COM$1" + cd $present + omc --simCodeTarget=ExperimentalEmbeddedC run_ldr_led.mos + if [ $? -ne 0 ]; then + exit 1 + fi +fi + +avr-gcc -Os -std=c11 -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000UL -Wl,--gc-sections ldr_led_main.c -o ldr_led -I${mdd_path[0]} -I${path_to_om} -I${path_to_mdd} -I${om_path[0]} +if [ $? -ne 0 ]; then + exit 1 +fi +avr-objcopy -O ihex -R .eeprom ldr_led ldr_led.hex +if [ $? -ne 0 ]; then + exit 1 +fi +avrdude -F -V -c arduino -p ATMEGA328P -P $port -b $b_rate -U flash:w:ldr_led.hex +if [ $? -ne 0 ]; then + exit 1 +fi diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/ldr/ldr_led.sh~ b/OpenModelica_Arduino_With_MDD/MDD_build/ldr/ldr_led.sh~ new file mode 100644 index 0000000..48dfad2 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/ldr/ldr_led.sh~ @@ -0,0 +1,61 @@ +#!/bin/bash +clear +if [ "$#" -ne 2 ]; then + echo "Usage: $0 port baudrate" >&2 + exit 1 +fi + +re='^[0-9]+$' +if ! [[ $1 =~ $re ]] ; then + echo "error: $1 -> Not a number" >&2; exit 1 +fi + +if ! [[ $2 =~ $re ]] ; then + echo "error: $2-> Not a number" >&2; exit 1 +fi + +b_rate=$2 + +present=`pwd` +unamestr=`uname` + +if [[ "$unamestr" == 'Linux' ]]; then + mdd_path=($(locate Modelica_DeviceDrivers/Resources/Include)) + om_path=($(locate /usr/include/omc/c)) + port="/dev/ttyACM$1" + omc --simCodeTarget=ExperimentalEmbeddedC runMDD_ldr_led.mos + if [ $? -ne 0 ]; then + exit 1 + fi +else + cd c: + om_path=($(dir -d OpenModelica*/include/omc/c/)) + path_to_om="C:$om_path" + cd f: + mdd_path=($(dir -d */Modelica_DeviceDrivers/Resources/Include/)) + if [ $? -eq 0 ]; then + path_to_mdd="F:/$mdd_path" + else + exit 1 + fi + + port="COM$1" + cd $present + omc --simCodeTarget=ExperimentalEmbeddedC run_ldr_led.mos + if [ $? -ne 0 ]; then + exit 1 + fi +fi + +avr-gcc -Os -std=c11 -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000UL -Wl,--gc-sections ldr_led_main.c -o ldr_led -I${mdd_path[0]} -I${path_to_om} -I${path_to_mdd} -I${om_path[0]} +if [ $? -ne 0 ]; then + exit 1 +fi +avr-objcopy -O ihex -R .eeprom ldr_led ldr_led.hex +if [ $? -ne 0 ]; then + exit 1 +fi +avrdude -F -V -c arduino -p ATMEGA328P -P $port -b $b_rate -U flash:w:ldr_led.hex +if [ $? -ne 0 ]; then + exit 1 +fi diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/ldr/ldr_led_main.c b/OpenModelica_Arduino_With_MDD/MDD_build/ldr/ldr_led_main.c new file mode 100644 index 0000000..3b4bcd7 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/ldr/ldr_led_main.c @@ -0,0 +1,243 @@ +#define fmi2TypesPlatform_h + +#define fmi2TypesPlatform "default" /* Compatible */ + +typedef struct ldr_led_fmi2Component_s* fmi2Component; +typedef void* fmi2ComponentEnvironment; /* Pointer to FMU environment */ +typedef void* fmi2FMUstate; /* Pointer to internal FMU state */ +typedef unsigned int fmi2ValueReference; +typedef double fmi2Real; +typedef int fmi2Integer; +typedef int fmi2Boolean; +typedef char fmi2Char; +typedef const fmi2Char* fmi2String; +typedef char fmi2Byte; + +#define fmi2True 1 +#define fmi2False 0 + +#include "fmi2/fmi2Functions.h" + +#include <stdint.h> +#include <stdio.h> + +void ModelicaFormatMessage(const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + vprintf(fmt, args); + va_end(args); +} + +typedef struct ldr_led_fmi2Component_s { + fmi2Real currentTime; + fmi2Real fmi2RealVars[1]; + fmi2Boolean fmi2BooleanVars[3]; + fmi2Real fmi2RealParameter[2]; + void* extObjs[4]; +} ldr_led_fmi2Component; + +ldr_led_fmi2Component ldr_led_component = { + .fmi2RealVars = { + 0.0 /*adc._y*/, + }, + .fmi2BooleanVars = { + fmi2False /*booleanExpression1._y*/, + fmi2False /*booleanExpression2._y*/, + fmi2False /*digitalWriteBoolean1._u*/, + }, + .fmi2RealParameter = { + 600.0 /*greaterThreshold1._threshold*/, + 0.002 /*synchronizeRealtime1._actualInterval*/, + }, +}; + +#include <math.h> +/* TODO: Generate used builtin functions before SimCode */ +static inline double om_mod(double x, double y) +{ + return x-floor(x/y)*y; +} + +static const char * const OMCLIT0 = "ElectricPotential"; +static const char * const OMCLIT1 = "V"; +#include "MDDAVRTimer.h" +#include "MDDAVRRealTime.h" +#include "MDDAVRDigital.h" +#include "MDDAVRAnalog.h" + +static inline fmi2Real Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_read__voltage(fmi2Component comp, fmi2Integer om_analogPort, fmi2Real om_vref, fmi2Integer om_voltageResolution); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_constructor(fmi2Component comp, fmi2Integer om_divisionFactor, fmi2Integer om_referenceVoltage); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_destructor(fmi2Component comp, void* om_avr); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(fmi2Component comp, void* om_port, fmi2Integer om_pin, fmi2Boolean om_value); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_destructor(fmi2Component comp, void* om_digital); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer); + +static inline fmi2Real Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_read__voltage(fmi2Component comp, fmi2Integer om_analogPort, fmi2Real om_vref, fmi2Integer om_voltageResolution) +{ + fmi2Real om_value; + om_value = MDD_avr_analog_read(om_analogPort, om_vref, om_voltageResolution); + return om_value; +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_constructor(fmi2Component comp, fmi2Integer om_divisionFactor, fmi2Integer om_referenceVoltage) +{ + void* om_avr; + om_avr = MDD_avr_analog_init(om_divisionFactor, om_referenceVoltage); + return om_avr; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_destructor(fmi2Component comp, void* om_avr) +{ + MDD_avr_analog_close(om_avr); +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(fmi2Component comp, void* om_port, fmi2Integer om_pin, fmi2Boolean om_value) +{ + MDD_avr_digital_pin_write(om_port, om_pin, om_value); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin) +{ + void* om_dig; + om_dig = MDD_avr_digital_pin_init(om_port, om_pin, fmi2True); + return om_dig; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_destructor(fmi2Component comp, void* om_digital) +{ + MDD_avr_digital_pin_close(om_digital); +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt) +{ + MDD_avr_rt_wait(om_rt); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle) +{ + void* om_rt; + om_rt = MDD_avr_rt_init(om_timer, om_timerValue, om_numTimerInterruptsPerCycle); + return om_rt; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt) +{ + MDD_avr_rt_close(om_rt); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch) +{ + void* om_timer; + om_timer = MDD_avr_timer_init(om_timerSelect, om_clockSelect, om_clearTimerOnMatch); + return om_timer; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer) +{ + MDD_avr_timer_close(om_timer); +} + +fmi2Component ldr_led_fmi2Instantiate(fmi2String name, fmi2Type ty, fmi2String GUID, fmi2String resources, const fmi2CallbackFunctions* functions, fmi2Boolean visible, fmi2Boolean loggingOn) +{ + static int initDone=0; + if (initDone) { + return NULL; + } + return &ldr_led_component; +} + +fmi2Status ldr_led_fmi2SetupExperiment(fmi2Component comp, fmi2Boolean toleranceDefined, fmi2Real tolerance, fmi2Real startTime, fmi2Boolean stopTimeDefined, fmi2Real stopTime) +{ + return fmi2OK; +} + +fmi2Status ldr_led_fmi2EnterInitializationMode(fmi2Component comp) +{ + comp->extObjs[0] /* adc._analog EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Analog.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_constructor(comp, 7, 4); + comp->extObjs[1] /* digitalWriteBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(comp, 2, 2); + comp->extObjs[2] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(comp, 1, 4, fmi2False); + comp->extObjs[3] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(comp, comp->extObjs[2] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */, 249, 2); + return fmi2OK; +} + +fmi2Status ldr_led_fmi2ExitInitializationMode(fmi2Component comp) +{ + return fmi2OK; +} + +static fmi2Status ldr_led_functionODE(fmi2Component comp) +{ +} + +static fmi2Status ldr_led_functionOutputs(fmi2Component comp) +{ + comp->fmi2RealVars[0] /* adc._y variable */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_read__voltage(comp, 6, 1024.0, 10); /* equation 6 */ + comp->fmi2BooleanVars[2] /* digitalWriteBoolean1._u DISCRETE */ = (comp->fmi2RealVars[0] /* adc._y variable */)>(comp->fmi2RealParameter[0] /* greaterThreshold1._threshold PARAM */); /* equation 7 */Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(comp, comp->extObjs[3] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */);Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(comp, comp->extObjs[1] /* digitalWriteBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */, 2, comp->fmi2BooleanVars[2] /* digitalWriteBoolean1._u DISCRETE */); +} + +fmi2Status ldr_led_fmi2DoStep(fmi2Component comp, fmi2Real currentCommunicationPoint, fmi2Real communicationStepSize, fmi2Boolean noSetFMUStatePriorToCurrentPoint) +{ + comp->currentTime = currentCommunicationPoint; + /* TODO: Calculate time/state-dependent variables here... */ + ldr_led_functionOutputs(comp); + return fmi2OK; +} + +int main(int argc, char **argv) +{ + int terminateSimulation = 0; + fmi2Status status = fmi2OK; + fmi2CallbackFunctions cbf = { + .logger = NULL, + .allocateMemory = NULL /*calloc*/, + .freeMemory = NULL /*free*/, + .stepFinished = NULL, //synchronous execution + .componentEnvironment = NULL + }; + + fmi2Component comp = ldr_led_fmi2Instantiate("", fmi2CoSimulation, "", "", &cbf, fmi2False, fmi2False); + if (comp==NULL) { + return 1; + } + ldr_led_fmi2SetupExperiment(comp, fmi2False, 0.0, 0.0, fmi2False, 1.0); + ldr_led_fmi2EnterInitializationMode(comp); + // Set start-values? Nah... + ldr_led_fmi2ExitInitializationMode(comp); + + double currentTime = 0.0; + double h = 0.002; + uint32_t i = 0; + + while (status == fmi2OK) { + //retrieve outputs + // fmi2GetReal(m, ..., 1, &y1); + //set inputs + // fmi2SetReal(m, ..., 1, &y2); + + //call slave and check status + status = ldr_led_fmi2DoStep(comp, currentTime, h, fmi2True); + switch (status) { + case fmi2Discard: + case fmi2Error: + case fmi2Fatal: + case fmi2Pending /* Cannot happen */: + terminateSimulation = 1; + break; + case fmi2OK: + case fmi2Warning: + break; + } + if (terminateSimulation) { + break; + } + i++; + /* increment master time */ + currentTime = 0.0 + h*i; + } + +#if 0 + if ((status != fmi2Error) && (status != fmi2Fatal)) { + fmi2Terminate(m); + } + if (status != fmi2Fatal) { + fmi2FreeInstance(m); + } +#endif +} + diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/ldr/ldr_read.sh b/OpenModelica_Arduino_With_MDD/MDD_build/ldr/ldr_read.sh new file mode 100644 index 0000000..ead2010 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/ldr/ldr_read.sh @@ -0,0 +1,61 @@ +#!/bin/bash +clear +if [ "$#" -ne 2 ]; then + echo "Usage: $0 port baudrate" >&2 + exit 1 +fi + +re='^[0-9]+$' +if ! [[ $1 =~ $re ]] ; then + echo "error: $1 -> Not a number" >&2; exit 1 +fi + +if ! [[ $2 =~ $re ]] ; then + echo "error: $2-> Not a number" >&2; exit 1 +fi + +b_rate=$2 + +present=`pwd` +unamestr=`uname` + +if [[ "$unamestr" == 'Linux' ]]; then + mdd_path=($(locate Modelica_DeviceDrivers/Resources/Include)) + om_path=($(locate /usr/include/omc/c)) + port="/dev/ttyACM$1" + omc --simCodeTarget=ExperimentalEmbeddedC runMDD_ldr_read.mos + if [ $? -ne 0 ]; then + exit 1 + fi +else + cd c: + om_path=($(dir -d OpenModelica*/include/omc/c/)) + path_to_om="C:$om_path" + cd f: + mdd_path=($(dir -d */Modelica_DeviceDrivers/Resources/Include/)) + if [ $? -eq 0 ]; then + path_to_mdd="F:/$mdd_path" + else + exit 1 + fi + + port="COM$1" + cd $present + omc --simCodeTarget=ExperimentalEmbeddedC run_ldr_read.mos + if [ $? -ne 0 ]; then + exit 1 + fi +fi + +avr-gcc -Os -std=c11 -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000UL -Wl,--gc-sections ldr_read_main.c -o ldr_read -I${mdd_path[0]} -I${path_to_om} -I${path_to_mdd} -I${om_path[0]} +if [ $? -ne 0 ]; then + exit 1 +fi +avr-objcopy -O ihex -R .eeprom ldr_read ldr_read.hex +if [ $? -ne 0 ]; then + exit 1 +fi +avrdude -F -V -c arduino -p ATMEGA328P -P $port -b $b_rate -U flash:w:ldr_read.hex +if [ $? -ne 0 ]; then + exit 1 +fi diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/ldr/ldr_read.sh~ b/OpenModelica_Arduino_With_MDD/MDD_build/ldr/ldr_read.sh~ new file mode 100644 index 0000000..f9c21db --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/ldr/ldr_read.sh~ @@ -0,0 +1,61 @@ +#!/bin/bash +clear +if [ "$#" -ne 2 ]; then + echo "Usage: $0 port baudrate" >&2 + exit 1 +fi + +re='^[0-9]+$' +if ! [[ $1 =~ $re ]] ; then + echo "error: $1 -> Not a number" >&2; exit 1 +fi + +if ! [[ $2 =~ $re ]] ; then + echo "error: $2-> Not a number" >&2; exit 1 +fi + +b_rate=$2 + +present=`pwd` +unamestr=`uname` + +if [[ "$unamestr" == 'Linux' ]]; then + mdd_path=($(locate Modelica_DeviceDrivers/Resources/Include)) + om_path=($(locate /usr/include/omc/c)) + port="/dev/ttyACM$1" + omc --simCodeTarget=ExperimentalEmbeddedC runMDD_ldr_read.mos + if [ $? -ne 0 ]; then + exit 1 + fi +else + cd c: + om_path=($(dir -d OpenModelica*/include/omc/c/)) + path_to_om="C:$om_path" + cd f: + mdd_path=($(dir -d */Modelica_DeviceDrivers/Modelica_DeviceDrivers/Resources/Include/)) + if [ $? -eq 0 ]; then + path_to_mdd="F:/$mdd_path" + else + exit 1 + fi + + port="COM$1" + cd $present + omc --simCodeTarget=ExperimentalEmbeddedC run_ldr_read.mos + if [ $? -ne 0 ]; then + exit 1 + fi +fi + +avr-gcc -Os -std=c11 -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000UL -Wl,--gc-sections ldr_read_main.c -o ldr_read -I${mdd_path[0]} -I${path_to_om} -I${path_to_mdd} -I${om_path[0]} +if [ $? -ne 0 ]; then + exit 1 +fi +avr-objcopy -O ihex -R .eeprom ldr_read ldr_read.hex +if [ $? -ne 0 ]; then + exit 1 +fi +avrdude -F -V -c arduino -p ATMEGA328P -P $port -b $b_rate -U flash:w:ldr_read.hex +if [ $? -ne 0 ]; then + exit 1 +fi diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/ldr/runMDD_ldr_led.mos b/OpenModelica_Arduino_With_MDD/MDD_build/ldr/runMDD_ldr_led.mos new file mode 100644 index 0000000..ff9d4a1 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/ldr/runMDD_ldr_led.mos @@ -0,0 +1,11 @@ +loadModel(Modelica); +getErrorString(); + +loadFile("/home/sumeet/Modelica_DeviceDrivers/package.mo"); +getErrorString(); + +loadFile("/home/sumeet/MDD_Arduino/linux-version-4/OpenModelica-Arduino-MDD_Arduino_Revised/Arduino.mo"); +getErrorString(); + +translateModel(Arduino.SerialCommunication.MDD_Examples.MDD_ldr.MDD_ldr_led, fileNamePrefix="ldr_led"); +getErrorString(); diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/ldr/runMDD_ldr_led.mos~ b/OpenModelica_Arduino_With_MDD/MDD_build/ldr/runMDD_ldr_led.mos~ new file mode 100644 index 0000000..76aef31 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/ldr/runMDD_ldr_led.mos~ @@ -0,0 +1,11 @@ +loadModel(Modelica); +getErrorString(); + +loadFile("/home/souradip/Modelica_DeviceDrivers/Modelica_DeviceDrivers/package.mo"); +getErrorString(); + +loadFile("/home/souradip/OpenModelica/Arduino.mo"); +getErrorString(); + +translateModel(Arduino.SerialCommunication.MDD_Examples.MDD_ldr.MDD_ldr_led, fileNamePrefix="ldr_led"); +getErrorString(); diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/ldr/runMDD_ldr_read.mos b/OpenModelica_Arduino_With_MDD/MDD_build/ldr/runMDD_ldr_read.mos new file mode 100644 index 0000000..ff9d4a1 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/ldr/runMDD_ldr_read.mos @@ -0,0 +1,11 @@ +loadModel(Modelica); +getErrorString(); + +loadFile("/home/sumeet/Modelica_DeviceDrivers/package.mo"); +getErrorString(); + +loadFile("/home/sumeet/MDD_Arduino/linux-version-4/OpenModelica-Arduino-MDD_Arduino_Revised/Arduino.mo"); +getErrorString(); + +translateModel(Arduino.SerialCommunication.MDD_Examples.MDD_ldr.MDD_ldr_led, fileNamePrefix="ldr_led"); +getErrorString(); diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/ldr/runMDD_ldr_read.mos~ b/OpenModelica_Arduino_With_MDD/MDD_build/ldr/runMDD_ldr_read.mos~ new file mode 100644 index 0000000..76aef31 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/ldr/runMDD_ldr_read.mos~ @@ -0,0 +1,11 @@ +loadModel(Modelica); +getErrorString(); + +loadFile("/home/souradip/Modelica_DeviceDrivers/Modelica_DeviceDrivers/package.mo"); +getErrorString(); + +loadFile("/home/souradip/OpenModelica/Arduino.mo"); +getErrorString(); + +translateModel(Arduino.SerialCommunication.MDD_Examples.MDD_ldr.MDD_ldr_led, fileNamePrefix="ldr_led"); +getErrorString(); diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/led/MDD_led_blink.hex b/OpenModelica_Arduino_With_MDD/MDD_build/led/MDD_led_blink.hex new file mode 100644 index 0000000..89858ca --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/led/MDD_led_blink.hex @@ -0,0 +1,114 @@ +:100000000C9434000C9451000C9451000C94510049
+:100010000C9451000C9451000C9451000C942A0142
+:100020000C9451000C9451000C9451000C94F90064
+:100030000C9451000C9451000C94C8000C94510085
+:100040000C9451000C9451000C9451000C945100EC
+:100050000C9451000C9451000C9451000C945100DC
+:100060000C9451000C94510011241FBECFEFD8E026
+:10007000DEBFCDBF11E0A0E0B1E0E4EFF6E002C0EA
+:1000800005900D92A031B107D9F711E0A0E1B1E0E0
+:1000900001C01D92A531B107E1F70E9478010C94CF
+:1000A00078030C940000CF92DF92EF92FF920F93AF
+:1000B0001F93CF93DF93EC01C880D980EA80FB8047
+:1000C00020E030E040E05FE3C701B6010E94F102AA
+:1000D0000E9449029B01AC010E94A8019B01AC0156
+:1000E000C701B6010E94A70101E010E020E030E066
+:1000F00040E85FE30E94ED0287FF02C000E010E0ED
+:100100001D830C838E859F858230910561F083303D
+:10011000910599F00197C9F416BC80916E00826038
+:1001200080936E0016C0109285001092840080911A
+:100130006F00826080936F000CC01092B2008091BB
+:10014000700082608093700004C081E090E00E94A3
+:10015000780378949FB7F894809112019FBF882309
+:10016000C9F310921201EA85FB858C819D81892B50
+:1001700019F08081806202C080818F7D8083DF9151
+:10018000CF911F910F91FF90EF90DF90CF90089546
+:100190001F920F920FB60F9211242F933F938F93BC
+:1001A0009F938091100190911101019690931101FC
+:1001B0008093100180911201813091F02091100103
+:1001C0003091110180911301909114012817390782
+:1001D00038F081E080931201109211011092100109
+:1001E0009F918F913F912F910F900FBE0F901F9075
+:1001F00018951F920F920FB60F9211242F933F93D1
+:100200008F939F938091100190911101019690938B
+:1002100011018093100180911201813091F02091A1
+:100220001001309111018091130190911401281750
+:10023000390738F081E08093120110921101109279
+:1002400010019F918F913F912F910F900FBE0F90B2
+:100250001F9018951F920F920FB60F9211242F9393
+:100260003F938F939F93809110019091110101967C
+:10027000909311018093100180911201813091F0CF
+:10028000209110013091110180911301909114017E
+:100290002817390738F081E080931201109211017C
+:1002A000109210019F918F913F912F910F900FBE4F
+:1002B0000F901F901895FC0185B5836085BD81E086
+:1002C00090E09587848722E030E0309314012093FA
+:1002D000130124B5226024BD29EF27BD97878687A7
+:1002E000259A85E290E09387828780E090E00895E8
+:1002F000CF92DF92EF92FF9280E091E00E945B014B
+:10030000C12CD12C760160E070E0CB01609300013C
+:1003100070930101809302019093030180E091E0CA
+:100320000E9453008FEFC81AD80AE80AF80AC701DA
+:10033000B6010E940C022FE632E143E05BE30E942B
+:10034000F10220E030E0A9010E94A801DFCF50585F
+:10035000BB27AA270ED0F0C0E1D030F0E6D020F0C5
+:1003600031F49F3F11F41EF4D6C00EF4E095E7FB84
+:10037000A3C0E92FF2D080F3BA176207730784078E
+:10038000950718F071F49EF521C10EF4E0950B2E3F
+:10039000BA2FA02D0B01B90190010C01CA01A001D7
+:1003A0001124FF27591B99F0593F50F4503E68F132
+:1003B0001A16F040A22F232F342F4427585FF3CF73
+:1003C000469537952795A795F0405395C9F77EF444
+:1003D0001F16BA0B620B730B840BBAF09150A1F08D
+:1003E000FF0FBB1F661F771F881FC2F70EC0BA0F13
+:1003F000621F731F841F48F4879577956795B7959B
+:10040000F7959E3F08F0B3CF9395880F08F0992792
+:10041000EE0F979587950895E89409C097FB3EF4F1
+:1004200090958095709561957F4F8F4F9F4F992341
+:10043000A9F0F92F96E9BB279395F69587957795BF
+:100440006795B795F111F8CFFAF4BB0F11F460FF7F
+:100450001BC06F5F7F4F8F4F9F4F16C0882311F0D7
+:1004600096E911C0772321F09EE8872F762F05C0EB
+:10047000662371F096E8862F70E060E02AF09A9586
+:10048000660F771F881FDAF7880F9695879597F97B
+:10049000089585D080F09F3740F491110EF097C0F9
+:1004A00060E070E080E89FEB089526F41B16611D64
+:1004B000711D811D07C021C097F99F6780E870E01A
+:1004C00060E00895882371F4772321F09850872BFA
+:1004D000762F07C0662311F499270DC09051862B03
+:1004E00070E060E02AF09A95660F771F881FDAF7B0
+:1004F000880F9695879597F908959F3F31F0915011
+:1005000020F4879577956795B795880F911D9695F7
+:10051000879597F908959FEF80EC089500240A9439
+:100520001616170618060906089500240A941216CE
+:100530001306140605060895092E0394000C11F401
+:10054000882352F0BB0F40F4BF2B11F460FF04C0AE
+:100550006F5F7F4F8F4F9F4F089557FD9058440F07
+:10056000551F59F05F3F71F04795880F97FB991F12
+:1005700061F09F3F79F087950895121613061406CF
+:10058000551FF2CF4695F1DF08C01616170618065C
+:10059000991FF1CF86957105610508940895E5DFEF
+:1005A000A0F0BEE7B91788F4BB279F3860F4161691
+:1005B000B11D672F782F8827985FF7CF869577959D
+:1005C0006795B11D93959639C8F30895E894BB27B4
+:1005D00066277727CB0197F9089566D008F48FEF47
+:1005E00008950BD0A9CF9ADF28F09FDF18F095234C
+:1005F00009F062CF90CF1124EACFAFDFA0F3959F2F
+:10060000D1F3950F50E0551F629FF001729FBB27F9
+:10061000F00DB11D639FAA27F00DB11DAA1F649FA5
+:100620006627B00DA11D661F829F2227B00DA11D58
+:10063000621F739FB00DA11D621F839FA00D611DDE
+:10064000221F749F3327A00D611D231F849F600DFF
+:10065000211D822F762F6A2F11249F5750408AF038
+:10066000E1F088234AF0EE0FFF1FBB1F661F771FC4
+:10067000881F91505040A9F79E3F510570F01CCF44
+:10068000A6CF5F3FECF3983EDCF3869577956795B0
+:10069000B795F795E7959F5FC1F7FE2B880F911DE2
+:1006A0009695879597F90895990F0008550FAA0B0D
+:1006B000E0E8FEEF16161706E807F907C0F0121675
+:1006C0001306E407F50798F0621B730B840B950B78
+:1006D00039F40A2661F0232B242B252B21F40895CD
+:1006E0000A2609F4A140A6958FEF811D811D08956A
+:0406F000F894FFCFAC
+:1006F4000000000000006F12033B00000000000037
+:00000001FF
diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/led/MDD_led_blue.hex b/OpenModelica_Arduino_With_MDD/MDD_build/led/MDD_led_blue.hex new file mode 100644 index 0000000..05d7448 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/led/MDD_led_blue.hex @@ -0,0 +1,93 @@ +:100000000C9434000C9451000C9451000C94510049
+:100010000C9451000C9451000C9451000C94E50088
+:100020000C9451000C9451000C9451000C94B400A9
+:100030000C9451000C9451000C9483000C945100CA
+:100040000C9451000C9451000C9451000C945100EC
+:100050000C9451000C9451000C9451000C945100DC
+:100060000C9451000C94510011241FBECFEFD8E026
+:10007000DEBFCDBF11E0A0E0B1E0EAEAF5E002C0EA
+:1000800005900D92A031B107D9F721E0A0E1B1E0D0
+:1000900001C01D92A531B207E1F70E9433010C9413
+:1000A000D3020C9400008230910561F083309105F9
+:1000B00099F00197C9F416BC80916E00826080931C
+:1000C0006E0016C0109285001092840080916F001F
+:1000D000826080936F000CC01092B200809170001B
+:1000E00082608093700004C081E090E00E94D3029F
+:1000F00078949FB7F894809112019FBF8823C9F329
+:100100001092120108951F920F920FB60F921124B0
+:100110002F933F938F939F938091100190911101A2
+:10012000019690931101809310018091120181300A
+:1001300091F0209110013091110180911301909163
+:1001400014012817390738F081E0809312011092CA
+:100150001101109210019F918F913F912F910F905B
+:100160000FBE0F901F9018951F920F920FB60F920F
+:1001700011242F933F938F939F938091100190911F
+:100180001101019690931101809310018091120149
+:10019000813091F020911001309111018091130173
+:1001A000909114012817390738F081E080931201EB
+:1001B00010921101109210019F918F913F912F91F8
+:1001C0000F900FBE0F901F9018951F920F920FB6B1
+:1001D0000F9211242F933F938F939F93809110013F
+:1001E00090911101019690931101809310018091DB
+:1001F0001201813091F02091100130911101809114
+:100200001301909114012817390738F081E0809389
+:10021000120110921101109210019F918F913F9144
+:100220002F910F900FBE0F901F901895FC01219AEF
+:1002300085E290E09387828785B5836085BD21E064
+:1002400030E03587248782E090E09093140180931A
+:10025000130184B5826084BD89EF87BD3787268707
+:1002600080E090E00895CF92DF92EF92FF9280E0DD
+:1002700091E00E941601C12CD12C760160E070E063
+:10028000CB01609300017093010180930201909370
+:10029000030180910E0190910F010E945300E091A3
+:1002A0000A01F0910B018081826080838FEFC81A70
+:1002B000D80AE80AF80AC701B6010E94D8012FE659
+:1002C00032E143E05BE30E94660220E030E0A901F6
+:1002D0000E946C01D6CF5058BB27AA270E948301E9
+:1002E0000C942C020E941E0238F00E94250220F07D
+:1002F00039F49F3F19F426F40C941B020EF4E09598
+:10030000E7FB0C941502E92F0E943D0258F3BA173F
+:10031000620773078407950720F079F4A6F50C941B
+:100320005F020EF4E0950B2EBA2FA02D0B01B90140
+:1003300090010C01CA01A0011124FF27591B99F05B
+:10034000593F50F4503E68F11A16F040A22F232F67
+:10035000342F4427585FF3CF469537952795A795B7
+:10036000F0405395C9F77EF41F16BA0B620B730B5E
+:10037000840BBAF09150A1F0FF0FBB1F661F771FCF
+:10038000881FC2F70EC0BA0F621F731F841F48F484
+:10039000879577956795B795F7959E3F08F0B0CF0D
+:1003A0009395880F08F09927EE0F979587950895F4
+:1003B000E89409C097FB3EF49095809570956195FF
+:1003C0007F4F8F4F9F4F9923A9F0F92F96E9BB27B5
+:1003D0009395F695879577956795B795F111F8CF31
+:1003E000FAF4BB0F11F460FF1BC06F5F7F4F8F4F9C
+:1003F0009F4F16C0882311F096E911C0772321F092
+:100400009EE8872F762F05C0662371F096E8862F29
+:1004100070E060E02AF09A95660F771F881FDAF780
+:10042000880F9695879597F9089597F99F6780E8C3
+:1004300070E060E008959FEF80EC089500240A9436
+:100440001616170618060906089500240A941216AF
+:100450001306140605060895092E0394000C11F4E2
+:10046000882352F0BB0F40F4BF2B11F460FF04C08F
+:100470006F5F7F4F8F4F9F4F089557FD9058440FE8
+:10048000551F59F05F3F71F04795880F97FB991FF3
+:1004900061F09F3F79F087950895121613061406B0
+:1004A000551FF2CF4695F1DF08C01616170618063D
+:1004B000991FF1CF86957105610508940895E89418
+:1004C000BB2766277727CB0197F908950E94790209
+:1004D0000C942C020E941E0238F00E94250220F08B
+:1004E000952311F00C9415020C941B0211240C940A
+:1004F00060020E943D0270F3959FC1F3950F50E09A
+:10050000551F629FF001729FBB27F00DB11D639FC5
+:10051000AA27F00DB11DAA1F649F6627B00DA11D6B
+:10052000661F829F2227B00DA11D621F739FB00D11
+:10053000A11D621F839FA00D611D221F749F332781
+:10054000A00D611D231F849F600D211D822F762F1A
+:100550006A2F11249F5750409AF0F1F088234AF0F7
+:10056000EE0FFF1FBB1F661F771F881F9150504063
+:10057000A9F79E3F510580F00C9415020C9460027F
+:100580005F3FE4F3983ED4F3869577956795B795EA
+:10059000F795E7959F5FC1F7FE2B880F911D969504
+:0A05A000879597F90895F894FFCFAE
+:1005AA000000000000006F12033B00000000000082
+:00000001FF
diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/led/MDD_traffic_light b/OpenModelica_Arduino_With_MDD/MDD_build/led/MDD_traffic_light Binary files differnew file mode 100755 index 0000000..9616b97 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/led/MDD_traffic_light diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/led/MDD_traffic_light.hex b/OpenModelica_Arduino_With_MDD/MDD_build/led/MDD_traffic_light.hex new file mode 100644 index 0000000..95ea020 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/led/MDD_traffic_light.hex @@ -0,0 +1,95 @@ +:100000000C9434000C9451000C9451000C94510049
+:100010000C9451000C9451000C9451000C94E50088
+:100020000C9451000C9451000C9451000C94B400A9
+:100030000C9451000C9451000C9483000C945100CA
+:100040000C9451000C9451000C9451000C945100EC
+:100050000C9451000C9451000C9451000C945100DC
+:100060000C9451000C94510011241FBECFEFD8E026
+:10007000DEBFCDBF11E0A0E0B1E0E6ECF5E002C0EC
+:1000800005900D92A031B107D9F721E0A0E1B1E0D0
+:1000900001C01D92A531B207E1F70E9441010C9405
+:1000A000E1020C9400008230910561F083309105EB
+:1000B00099F00197C9F416BC80916E00826080931C
+:1000C0006E0016C0109285001092840080916F001F
+:1000D000826080936F000CC01092B200809170001B
+:1000E00082608093700004C081E090E00E94E10291
+:1000F00078949FB7F894809112019FBF8823C9F329
+:100100001092120108951F920F920FB60F921124B0
+:100110002F933F938F939F938091100190911101A2
+:10012000019690931101809310018091120181300A
+:1001300091F0209110013091110180911301909163
+:1001400014012817390738F081E0809312011092CA
+:100150001101109210019F918F913F912F910F905B
+:100160000FBE0F901F9018951F920F920FB60F920F
+:1001700011242F933F938F939F938091100190911F
+:100180001101019690931101809310018091120149
+:10019000813091F020911001309111018091130173
+:1001A000909114012817390738F081E080931201EB
+:1001B00010921101109210019F918F913F912F91F8
+:1001C0000F900FBE0F901F9018951F920F920FB6B1
+:1001D0000F9211242F933F938F939F93809110013F
+:1001E00090911101019690931101809310018091DB
+:1001F0001201813091F02091100130911101809114
+:100200001301909114012817390738F081E0809389
+:10021000120110921101109210019F918F913F9144
+:100220002F910F900FBE0F901F901895DC01E0E00A
+:10023000F0E08081806180831B961C921E921A9749
+:10024000E1E8F0E080818360808322E030E01D9669
+:100250003C932E931C9781E090E09093140180933F
+:10026000130180818860808389EF90E090938900FA
+:10027000809388001F963C932E931E9780E090E019
+:100280000895CF92DF92EF92FF9280E091E00E947A
+:100290001601C12CD12C760160E070E0CB01609397
+:1002A00000017093010180930201909303018091FA
+:1002B0000E0190910F010E945300E0910A01F0910C
+:1002C0000B018081806180838FEFC81AD80AE80A09
+:1002D000F80AC701B6010E94E6012FE632E143E0C9
+:1002E0005BE30E94740220E030E0A9010E947A01E1
+:1002F000D6CF5058BB27AA270E9491010C943A02EE
+:100300000E942C0238F00E94330220F039F49F3F03
+:1003100019F426F40C9429020EF4E095E7FB0C94F2
+:100320002302E92F0E944B0258F3BA1762077307A2
+:100330008407950720F079F4A6F50C946D020EF46D
+:10034000E0950B2EBA2FA02D0B01B90190010C01E5
+:10035000CA01A0011124FF27591B99F0593F50F4FD
+:10036000503E68F11A16F040A22F232F342F442755
+:10037000585FF3CF469537952795A795F04053954D
+:10038000C9F77EF41F16BA0B620B730B840BBAF01D
+:100390009150A1F0FF0FBB1F661F771F881FC2F788
+:1003A0000EC0BA0F621F731F841F48F4879577959C
+:1003B0006795B795F7959E3F08F0B0CF9395880F56
+:1003C00008F09927EE0F979587950895E89409C04E
+:1003D00097FB3EF490958095709561957F4F8F4F78
+:1003E0009F4F9923A9F0F92F96E9BB279395F6958E
+:1003F000879577956795B795F111F8CFFAF4BB0F0C
+:1004000011F460FF1BC06F5F7F4F8F4F9F4F16C06F
+:10041000882311F096E911C0772321F09EE8872FF9
+:10042000762F05C0662371F096E8862F70E060E0B5
+:100430002AF09A95660F771F881FDAF7880F96952E
+:10044000879597F9089597F99F6780E870E060E0D5
+:1004500008959FEF80EC089500240A94161617065D
+:1004600018060906089500240A94121613061406A5
+:1004700005060895092E0394000C11F4882352F008
+:10048000BB0F40F4BF2B11F460FF04C06F5F7F4FC0
+:100490008F4F9F4F089557FD9058440F551F59F0A7
+:1004A0005F3F71F04795880F97FB991F61F09F3F61
+:1004B00079F087950895121613061406551FF2CF8A
+:1004C0004695F1DF08C0161617061806991FF1CFDA
+:1004D00086957105610508940895E894BB27662701
+:1004E0007727CB0197F908950E9487020C943A026E
+:1004F0000E942C0238F00E94330220F0952311F064
+:100500000C9423020C94290211240C946E020E9474
+:100510004B0270F3959FC1F3950F50E0551F629FFA
+:10052000F001729FBB27F00DB11D639FAA27F00D4C
+:10053000B11DAA1F649F6627B00DA11D661F829F73
+:100540002227B00DA11D621F739FB00DA11D621F58
+:10055000839FA00D611D221F749F3327A00D611D75
+:10056000231F849F600D211D822F762F6A2F112457
+:100570009F5750409AF0F1F088234AF0EE0FFF1F8A
+:10058000BB1F661F771F881F91505040A9F79E3FE1
+:10059000510580F00C9423020C946E025F3FE4F34B
+:1005A000983ED4F3869577956795B795F795E79537
+:1005B0009F5FC1F7FE2B880F911D9695879597F940
+:0605C0000895F894FFCF3E
+:1005C6000000000000006F12033B00000000000066
+:00000001FF
diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/led/led_blink b/OpenModelica_Arduino_With_MDD/MDD_build/led/led_blink Binary files differnew file mode 100644 index 0000000..3953004 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/led/led_blink diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/led/led_blink.hex b/OpenModelica_Arduino_With_MDD/MDD_build/led/led_blink.hex new file mode 100644 index 0000000..89858ca --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/led/led_blink.hex @@ -0,0 +1,114 @@ +:100000000C9434000C9451000C9451000C94510049
+:100010000C9451000C9451000C9451000C942A0142
+:100020000C9451000C9451000C9451000C94F90064
+:100030000C9451000C9451000C94C8000C94510085
+:100040000C9451000C9451000C9451000C945100EC
+:100050000C9451000C9451000C9451000C945100DC
+:100060000C9451000C94510011241FBECFEFD8E026
+:10007000DEBFCDBF11E0A0E0B1E0E4EFF6E002C0EA
+:1000800005900D92A031B107D9F711E0A0E1B1E0E0
+:1000900001C01D92A531B107E1F70E9478010C94CF
+:1000A00078030C940000CF92DF92EF92FF920F93AF
+:1000B0001F93CF93DF93EC01C880D980EA80FB8047
+:1000C00020E030E040E05FE3C701B6010E94F102AA
+:1000D0000E9449029B01AC010E94A8019B01AC0156
+:1000E000C701B6010E94A70101E010E020E030E066
+:1000F00040E85FE30E94ED0287FF02C000E010E0ED
+:100100001D830C838E859F858230910561F083303D
+:10011000910599F00197C9F416BC80916E00826038
+:1001200080936E0016C0109285001092840080911A
+:100130006F00826080936F000CC01092B2008091BB
+:10014000700082608093700004C081E090E00E94A3
+:10015000780378949FB7F894809112019FBF882309
+:10016000C9F310921201EA85FB858C819D81892B50
+:1001700019F08081806202C080818F7D8083DF9151
+:10018000CF911F910F91FF90EF90DF90CF90089546
+:100190001F920F920FB60F9211242F933F938F93BC
+:1001A0009F938091100190911101019690931101FC
+:1001B0008093100180911201813091F02091100103
+:1001C0003091110180911301909114012817390782
+:1001D00038F081E080931201109211011092100109
+:1001E0009F918F913F912F910F900FBE0F901F9075
+:1001F00018951F920F920FB60F9211242F933F93D1
+:100200008F939F938091100190911101019690938B
+:1002100011018093100180911201813091F02091A1
+:100220001001309111018091130190911401281750
+:10023000390738F081E08093120110921101109279
+:1002400010019F918F913F912F910F900FBE0F90B2
+:100250001F9018951F920F920FB60F9211242F9393
+:100260003F938F939F93809110019091110101967C
+:10027000909311018093100180911201813091F0CF
+:10028000209110013091110180911301909114017E
+:100290002817390738F081E080931201109211017C
+:1002A000109210019F918F913F912F910F900FBE4F
+:1002B0000F901F901895FC0185B5836085BD81E086
+:1002C00090E09587848722E030E0309314012093FA
+:1002D000130124B5226024BD29EF27BD97878687A7
+:1002E000259A85E290E09387828780E090E00895E8
+:1002F000CF92DF92EF92FF9280E091E00E945B014B
+:10030000C12CD12C760160E070E0CB01609300013C
+:1003100070930101809302019093030180E091E0CA
+:100320000E9453008FEFC81AD80AE80AF80AC701DA
+:10033000B6010E940C022FE632E143E05BE30E942B
+:10034000F10220E030E0A9010E94A801DFCF50585F
+:10035000BB27AA270ED0F0C0E1D030F0E6D020F0C5
+:1003600031F49F3F11F41EF4D6C00EF4E095E7FB84
+:10037000A3C0E92FF2D080F3BA176207730784078E
+:10038000950718F071F49EF521C10EF4E0950B2E3F
+:10039000BA2FA02D0B01B90190010C01CA01A001D7
+:1003A0001124FF27591B99F0593F50F4503E68F132
+:1003B0001A16F040A22F232F342F4427585FF3CF73
+:1003C000469537952795A795F0405395C9F77EF444
+:1003D0001F16BA0B620B730B840BBAF09150A1F08D
+:1003E000FF0FBB1F661F771F881FC2F70EC0BA0F13
+:1003F000621F731F841F48F4879577956795B7959B
+:10040000F7959E3F08F0B3CF9395880F08F0992792
+:10041000EE0F979587950895E89409C097FB3EF4F1
+:1004200090958095709561957F4F8F4F9F4F992341
+:10043000A9F0F92F96E9BB279395F69587957795BF
+:100440006795B795F111F8CFFAF4BB0F11F460FF7F
+:100450001BC06F5F7F4F8F4F9F4F16C0882311F0D7
+:1004600096E911C0772321F09EE8872F762F05C0EB
+:10047000662371F096E8862F70E060E02AF09A9586
+:10048000660F771F881FDAF7880F9695879597F97B
+:10049000089585D080F09F3740F491110EF097C0F9
+:1004A00060E070E080E89FEB089526F41B16611D64
+:1004B000711D811D07C021C097F99F6780E870E01A
+:1004C00060E00895882371F4772321F09850872BFA
+:1004D000762F07C0662311F499270DC09051862B03
+:1004E00070E060E02AF09A95660F771F881FDAF7B0
+:1004F000880F9695879597F908959F3F31F0915011
+:1005000020F4879577956795B795880F911D9695F7
+:10051000879597F908959FEF80EC089500240A9439
+:100520001616170618060906089500240A941216CE
+:100530001306140605060895092E0394000C11F401
+:10054000882352F0BB0F40F4BF2B11F460FF04C0AE
+:100550006F5F7F4F8F4F9F4F089557FD9058440F07
+:10056000551F59F05F3F71F04795880F97FB991F12
+:1005700061F09F3F79F087950895121613061406CF
+:10058000551FF2CF4695F1DF08C01616170618065C
+:10059000991FF1CF86957105610508940895E5DFEF
+:1005A000A0F0BEE7B91788F4BB279F3860F4161691
+:1005B000B11D672F782F8827985FF7CF869577959D
+:1005C0006795B11D93959639C8F30895E894BB27B4
+:1005D00066277727CB0197F9089566D008F48FEF47
+:1005E00008950BD0A9CF9ADF28F09FDF18F095234C
+:1005F00009F062CF90CF1124EACFAFDFA0F3959F2F
+:10060000D1F3950F50E0551F629FF001729FBB27F9
+:10061000F00DB11D639FAA27F00DB11DAA1F649FA5
+:100620006627B00DA11D661F829F2227B00DA11D58
+:10063000621F739FB00DA11D621F839FA00D611DDE
+:10064000221F749F3327A00D611D231F849F600DFF
+:10065000211D822F762F6A2F11249F5750408AF038
+:10066000E1F088234AF0EE0FFF1FBB1F661F771FC4
+:10067000881F91505040A9F79E3F510570F01CCF44
+:10068000A6CF5F3FECF3983EDCF3869577956795B0
+:10069000B795F795E7959F5FC1F7FE2B880F911DE2
+:1006A0009695879597F90895990F0008550FAA0B0D
+:1006B000E0E8FEEF16161706E807F907C0F0121675
+:1006C0001306E407F50798F0621B730B840B950B78
+:1006D00039F40A2661F0232B242B252B21F40895CD
+:1006E0000A2609F4A140A6958FEF811D811D08956A
+:0406F000F894FFCFAC
+:1006F4000000000000006F12033B00000000000037
+:00000001FF
diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/led/led_blink.sh b/OpenModelica_Arduino_With_MDD/MDD_build/led/led_blink.sh new file mode 100644 index 0000000..cd9e818 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/led/led_blink.sh @@ -0,0 +1,61 @@ +#!/bin/bash +clear +if [ "$#" -ne 2 ]; then + echo "Usage: $0 port baudrate" >&2 + exit 1 +fi + +re='^[0-9]+$' +if ! [[ $1 =~ $re ]] ; then + echo "error: $1 -> Not a number" >&2; exit 1 +fi + +if ! [[ $2 =~ $re ]] ; then + echo "error: $2-> Not a number" >&2; exit 1 +fi + +b_rate=$2 + +present=`pwd` +unamestr=`uname` + +if [[ "$unamestr" == 'Linux' ]]; then + mdd_path=($(locate Modelica_DeviceDrivers/Modelica_DeviceDrivers/Resources/Include)) + om_path=($(locate /usr/include/omc/c)) + port="/dev/ttyACM$1" + omc --simCodeTarget=ExperimentalEmbeddedC runMDD_led_blink.mos + if [ $? -ne 0 ]; then + exit 1 + fi +else + cd c: + om_path=($(dir -d OpenModelica*/include/omc/c/)) + path_to_om="C:$om_path" + cd f: + mdd_path=($(dir -d */Modelica_DeviceDrivers/Modelica_DeviceDrivers/Resources/Include/)) + if [ $? -eq 0 ]; then + path_to_mdd="F:/$mdd_path" + else + exit 1 + fi + + port="COM$1" + cd $present + omc --simCodeTarget=ExperimentalEmbeddedC run_led_blink.mos + if [ $? -ne 0 ]; then + exit 1 + fi +fi + +avr-gcc -Os -std=c11 -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000UL -Wl,--gc-sections led_blink_main.c -o led_blink -I${mdd_path[0]} -I${path_to_om} -I${path_to_mdd} -I${om_path[0]} +if [ $? -ne 0 ]; then + exit 1 +fi +avr-objcopy -O ihex -R .eeprom led_blink led_blink.hex +if [ $? -ne 0 ]; then + exit 1 +fi +avrdude -F -V -c arduino -p ATMEGA328P -P $port -b $b_rate -U flash:w:led_blink.hex +if [ $? -ne 0 ]; then + exit 1 +fi
\ No newline at end of file diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/led/led_blink_main.c b/OpenModelica_Arduino_With_MDD/MDD_build/led/led_blink_main.c new file mode 100644 index 0000000..bcf2661 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/led/led_blink_main.c @@ -0,0 +1,212 @@ +#define fmi2TypesPlatform_h + +#define fmi2TypesPlatform "default" /* Compatible */ + +typedef struct led_blink_fmi2Component_s* fmi2Component; +typedef void* fmi2ComponentEnvironment; /* Pointer to FMU environment */ +typedef void* fmi2FMUstate; /* Pointer to internal FMU state */ +typedef unsigned int fmi2ValueReference; +typedef double fmi2Real; +typedef int fmi2Integer; +typedef int fmi2Boolean; +typedef char fmi2Char; +typedef const fmi2Char* fmi2String; +typedef char fmi2Byte; + +#define fmi2True 1 +#define fmi2False 0 + +#include "fmi2/fmi2Functions.h" + +#include <stdint.h> +#include <stdio.h> + +void ModelicaFormatMessage(const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + vprintf(fmt, args); + va_end(args); +} + +typedef struct led_blink_fmi2Component_s { + fmi2Real currentTime; + fmi2Boolean fmi2BooleanVars[1]; + fmi2Real fmi2RealParameter[1]; + void* extObjs[3]; +} led_blink_fmi2Component; + +led_blink_fmi2Component led_blink_component = { + .fmi2BooleanVars = { + fmi2False /*booleanExpression1._y*/, + }, + .fmi2RealParameter = { + 0.002 /*synchronizeRealtime1._actualInterval*/, + }, +}; + +#include <math.h> +/* TODO: Generate used builtin functions before SimCode */ +static inline double om_mod(double x, double y) +{ + return x-floor(x/y)*y; +} + +#include "MDDAVRTimer.h" +#include "MDDAVRRealTime.h" +#include "MDDAVRDigital.h" + +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(fmi2Component comp, void* om_port, fmi2Integer om_pin, fmi2Boolean om_value); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_destructor(fmi2Component comp, void* om_digital); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer); + +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(fmi2Component comp, void* om_port, fmi2Integer om_pin, fmi2Boolean om_value) +{ + MDD_avr_digital_pin_write(om_port, om_pin, om_value); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin) +{ + void* om_dig; + om_dig = MDD_avr_digital_pin_init(om_port, om_pin, fmi2True); + return om_dig; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_destructor(fmi2Component comp, void* om_digital) +{ + MDD_avr_digital_pin_close(om_digital); +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt) +{ + MDD_avr_rt_wait(om_rt); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle) +{ + void* om_rt; + om_rt = MDD_avr_rt_init(om_timer, om_timerValue, om_numTimerInterruptsPerCycle); + return om_rt; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt) +{ + MDD_avr_rt_close(om_rt); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch) +{ + void* om_timer; + om_timer = MDD_avr_timer_init(om_timerSelect, om_clockSelect, om_clearTimerOnMatch); + return om_timer; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer) +{ + MDD_avr_timer_close(om_timer); +} + +fmi2Component led_blink_fmi2Instantiate(fmi2String name, fmi2Type ty, fmi2String GUID, fmi2String resources, const fmi2CallbackFunctions* functions, fmi2Boolean visible, fmi2Boolean loggingOn) +{ + static int initDone=0; + if (initDone) { + return NULL; + } + return &led_blink_component; +} + +fmi2Status led_blink_fmi2SetupExperiment(fmi2Component comp, fmi2Boolean toleranceDefined, fmi2Real tolerance, fmi2Real startTime, fmi2Boolean stopTimeDefined, fmi2Real stopTime) +{ + return fmi2OK; +} + +fmi2Status led_blink_fmi2EnterInitializationMode(fmi2Component comp) +{ + comp->extObjs[1] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(comp, 1, 4, fmi2False); + comp->extObjs[2] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(comp, comp->extObjs[1] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */, 249, 2); + comp->extObjs[0] /* digitalWriteBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(comp, 2, 6); + return fmi2OK; +} + +fmi2Status led_blink_fmi2ExitInitializationMode(fmi2Component comp) +{ + return fmi2OK; +} + +static fmi2Status led_blink_functionODE(fmi2Component comp) +{ +} + +static fmi2Status led_blink_functionOutputs(fmi2Component comp) +{ + comp->fmi2BooleanVars[0] /* booleanExpression1._y DISCRETE */ = (om_mod(comp->currentTime,2.0))>=(1.0); /* equation 3 */Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(comp, comp->extObjs[2] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */);Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(comp, comp->extObjs[0] /* digitalWriteBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */, 6, comp->fmi2BooleanVars[0] /* booleanExpression1._y DISCRETE */); +} + +fmi2Status led_blink_fmi2DoStep(fmi2Component comp, fmi2Real currentCommunicationPoint, fmi2Real communicationStepSize, fmi2Boolean noSetFMUStatePriorToCurrentPoint) +{ + comp->currentTime = currentCommunicationPoint; + /* TODO: Calculate time/state-dependent variables here... */ + led_blink_functionOutputs(comp); + return fmi2OK; +} + +int main(int argc, char **argv) +{ + int terminateSimulation = 0; + fmi2Status status = fmi2OK; + fmi2CallbackFunctions cbf = { + .logger = NULL, + .allocateMemory = NULL /*calloc*/, + .freeMemory = NULL /*free*/, + .stepFinished = NULL, //synchronous execution + .componentEnvironment = NULL + }; + + fmi2Component comp = led_blink_fmi2Instantiate("", fmi2CoSimulation, "", "", &cbf, fmi2False, fmi2False); + if (comp==NULL) { + return 1; + } + led_blink_fmi2SetupExperiment(comp, fmi2False, 0.0, 0.0, fmi2False, 1.0); + led_blink_fmi2EnterInitializationMode(comp); + // Set start-values? Nah... + led_blink_fmi2ExitInitializationMode(comp); + + double currentTime = 0.0; + double h = 0.002; + uint32_t i = 0; + + while (status == fmi2OK) { + //retrieve outputs + // fmi2GetReal(m, ..., 1, &y1); + //set inputs + // fmi2SetReal(m, ..., 1, &y2); + + //call slave and check status + status = led_blink_fmi2DoStep(comp, currentTime, h, fmi2True); + switch (status) { + case fmi2Discard: + case fmi2Error: + case fmi2Fatal: + case fmi2Pending /* Cannot happen */: + terminateSimulation = 1; + break; + case fmi2OK: + case fmi2Warning: + break; + } + if (terminateSimulation) { + break; + } + i++; + /* increment master time */ + currentTime = 0.0 + h*i; + } + +#if 0 + if ((status != fmi2Error) && (status != fmi2Fatal)) { + fmi2Terminate(m); + } + if (status != fmi2Fatal) { + fmi2FreeInstance(m); + } +#endif +} + diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/led/led_blue b/OpenModelica_Arduino_With_MDD/MDD_build/led/led_blue Binary files differnew file mode 100755 index 0000000..f4d2d19 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/led/led_blue diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/led/led_blue.hex b/OpenModelica_Arduino_With_MDD/MDD_build/led/led_blue.hex new file mode 100644 index 0000000..f36052a --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/led/led_blue.hex @@ -0,0 +1,91 @@ +:100000000C9434000C9451000C9451000C94510049
+:100010000C9451000C9451000C9451000C94E50088
+:100020000C9451000C9451000C9451000C94B400A9
+:100030000C9451000C9451000C9483000C945100CA
+:100040000C9451000C9451000C9451000C945100EC
+:100050000C9451000C9451000C9451000C945100DC
+:100060000C9451000C94510011241FBECFEFD8E026
+:10007000DEBFCDBF11E0A0E0B1E0E6E8F5E002C0F0
+:1000800005900D92A031B107D9F711E0A0E1B1E0E0
+:1000900001C01D92A531B107E1F70E9433010C9414
+:1000A000C1020C9400008230910561F0833091050B
+:1000B00099F00197C9F416BC80916E00826080931C
+:1000C0006E0016C0109285001092840080916F001F
+:1000D000826080936F000CC01092B200809170001B
+:1000E00082608093700004C081E090E00E94C102B1
+:1000F00078949FB7F894809112019FBF8823C9F329
+:100100001092120108951F920F920FB60F921124B0
+:100110002F933F938F939F938091100190911101A2
+:10012000019690931101809310018091120181300A
+:1001300091F0209110013091110180911301909163
+:1001400014012817390738F081E0809312011092CA
+:100150001101109210019F918F913F912F910F905B
+:100160000FBE0F901F9018951F920F920FB60F920F
+:1001700011242F933F938F939F938091100190911F
+:100180001101019690931101809310018091120149
+:10019000813091F020911001309111018091130173
+:1001A000909114012817390738F081E080931201EB
+:1001B00010921101109210019F918F913F912F91F8
+:1001C0000F900FBE0F901F9018951F920F920FB6B1
+:1001D0000F9211242F933F938F939F93809110013F
+:1001E00090911101019690931101809310018091DB
+:1001F0001201813091F02091100130911101809114
+:100200001301909114012817390738F081E0809389
+:10021000120110921101109210019F918F913F9144
+:100220002F910F900FBE0F901F901895FC01219AEF
+:1002300085E290E09387828785B5836085BD81E004
+:1002400090E09587848722E030E03093140120937A
+:10025000130124B5226024BD29EF27BD9787868727
+:1002600080E090E00895CF92DF92EF92FF9280E0DD
+:1002700091E00E941601C12CD12C760160E070E063
+:10028000CB01609300017093010180930201909370
+:10029000030180910E0190910F010E945300E091A3
+:1002A0000A01F0910B018081826080838FEFC81A70
+:1002B000D80AE80AF80AC701B6010E94D0012FE661
+:1002C00032E143E05BE30E945E0220E030E0A901FE
+:1002D0000E946C01D6CF5058BB27AA270ED0B4C0BD
+:1002E000A5D030F0AAD020F031F49F3F11F41EF4D5
+:1002F0009AC00EF4E095E7FB90C0E92FB6D080F3EA
+:10030000BA17620773078407950718F071F49EF512
+:10031000CEC00EF4E0950B2EBA2FA02D0B01B90123
+:1003200090010C01CA01A0011124FF27591B99F06B
+:10033000593F50F4503E68F11A16F040A22F232F77
+:10034000342F4427585FF3CF469537952795A795C7
+:10035000F0405395C9F77EF41F16BA0B620B730B6E
+:10036000840BBAF09150A1F0FF0FBB1F661F771FDF
+:10037000881FC2F70EC0BA0F621F731F841F48F494
+:10038000879577956795B795F7959E3F08F0B3CF1A
+:100390009395880F08F09927EE0F97958795089504
+:1003A000E89409C097FB3EF490958095709561950F
+:1003B0007F4F8F4F9F4F9923A9F0F92F96E9BB27C5
+:1003C0009395F695879577956795B795F111F8CF41
+:1003D000FAF4BB0F11F460FF1BC06F5F7F4F8F4FAC
+:1003E0009F4F16C0882311F096E911C0772321F0A2
+:1003F0009EE8872F762F05C0662371F096E8862F3A
+:1004000070E060E02AF09A95660F771F881FDAF790
+:10041000880F9695879597F9089597F99F6780E8D3
+:1004200070E060E008959FEF80EC089500240A9446
+:100430001616170618060906089500240A941216BF
+:100440001306140605060895092E0394000C11F4F2
+:10045000882352F0BB0F40F4BF2B11F460FF04C09F
+:100460006F5F7F4F8F4F9F4F089557FD9058440FF8
+:10047000551F59F05F3F71F04795880F97FB991F03
+:1004800061F09F3F79F087950895121613061406C0
+:10049000551FF2CF4695F1DF08C01616170618064D
+:1004A000991FF1CF86957105610508940895E89428
+:1004B000BB2766277727CB0197F908950BD0C4CFC8
+:1004C000B5DF28F0BADF18F0952309F0A6CFABCF3F
+:1004D0001124EECFCADFA0F3959FD1F3950F50E022
+:1004E000551F629FF001729FBB27F00DB11D639FE6
+:1004F000AA27F00DB11DAA1F649F6627B00DA11D8C
+:10050000661F829F2227B00DA11D621F739FB00D31
+:10051000A11D621F839FA00D611D221F749F3327A1
+:10052000A00D611D231F849F600D211D822F762F3A
+:100530006A2F11249F5750408AF0E1F088234AF037
+:10054000EE0FFF1FBB1F661F771F881F9150504083
+:10055000A9F79E3F510570F060CFAACF5F3FECF343
+:10056000983EDCF3869577956795B795F795E7956F
+:100570009F5FC1F7FE2B880F911D9695879597F980
+:060580000895F894FFCF7E
+:100586000000000000006F12033B000000000000A6
+:00000001FF
diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/led/led_blue.sh b/OpenModelica_Arduino_With_MDD/MDD_build/led/led_blue.sh new file mode 100644 index 0000000..b2a9b7d --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/led/led_blue.sh @@ -0,0 +1,61 @@ +#!/bin/bash +clear +if [ "$#" -ne 2 ]; then + echo "Usage: $0 port baudrate" >&2 + exit 1 +fi + +re='^[0-9]+$' +if ! [[ $1 =~ $re ]] ; then + echo "error: $1 -> Not a number" >&2; exit 1 +fi + +if ! [[ $2 =~ $re ]] ; then + echo "error: $2-> Not a number" >&2; exit 1 +fi + +b_rate=$2 + +present=`pwd` +unamestr=`uname` + +if [[ "$unamestr" == 'Linux' ]]; then + mdd_path=($(locate Modelica_DeviceDrivers/Modelica_DeviceDrivers/Resources/Include)) + om_path=($(locate /usr/include/omc/c)) + port="/dev/ttyACM$1" + omc --simCodeTarget=ExperimentalEmbeddedC runMDD_led_blue.mos + if [ $? -ne 0 ]; then + exit 1 + fi +else + cd c: + om_path=($(dir -d OpenModelica*/include/omc/c/)) + path_to_om="C:$om_path" + cd f: + mdd_path=($(dir -d */Modelica_DeviceDrivers/Modelica_DeviceDrivers/Resources/Include/)) + if [ $? -eq 0 ]; then + path_to_mdd="F:/$mdd_path" + else + exit 1 + fi + + port="COM$1" + cd $present + omc --simCodeTarget=ExperimentalEmbeddedC run_led_blue.mos + if [ $? -ne 0 ]; then + exit 1 + fi +fi + +avr-gcc -Os -std=c11 -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000UL -Wl,--gc-sections led_blue_main.c -o led_blue -I${mdd_path[0]} -I${path_to_om} -I${path_to_mdd} -I${om_path[0]} +if [ $? -ne 0 ]; then + exit 1 +fi +avr-objcopy -O ihex -R .eeprom led_blue led_blue.hex +if [ $? -ne 0 ]; then + exit 1 +fi +avrdude -F -V -c arduino -p ATMEGA328P -P $port -b $b_rate -U flash:w:led_blue.hex +if [ $? -ne 0 ]; then + exit 1 +fi
\ No newline at end of file diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/led/led_blue_delay b/OpenModelica_Arduino_With_MDD/MDD_build/led/led_blue_delay Binary files differnew file mode 100644 index 0000000..154b3fe --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/led/led_blue_delay diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/led/led_blue_delay.hex b/OpenModelica_Arduino_With_MDD/MDD_build/led/led_blue_delay.hex new file mode 100644 index 0000000..eaa1eaa --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/led/led_blue_delay.hex @@ -0,0 +1,100 @@ +:100000000C9434000C9451000C9451000C94510049
+:100010000C9451000C9451000C9451000C940E015E
+:100020000C9451000C9451000C9451000C94DD0080
+:100030000C9451000C9451000C94AC000C945100A1
+:100040000C9451000C9451000C9451000C945100EC
+:100050000C9451000C9451000C9451000C945100DC
+:100060000C9451000C94510011241FBECFEFD8E026
+:10007000DEBFCDBF11E0A0E0B1E0E6E1F6E002C0F6
+:1000800005900D92A031B107D9F711E0A0E1B1E0E0
+:1000900001C01D92A531B107E1F70E945C010C94EB
+:1000A00009030C9400000F931F93CF93DF93EC018F
+:1000B00001E010E020E030E040EA50E4688179811E
+:1000C0008A819B810E94F00187FD02C000E010E060
+:1000D0001D830C838E859F858230910561F083306E
+:1000E000910599F00197C9F416BC80916E00826069
+:1000F00080936E0016C0109285001092840080914B
+:100100006F00826080936F000CC01092B2008091EB
+:10011000700082608093700004C081E090E00E94D3
+:10012000090378949FB7F894809112019FBF8823A8
+:10013000C9F310921201EA85FB858C819D81892B80
+:1001400019F08081826002C080818D7F8083DF9181
+:10015000CF911F910F9108951F920F920FB60F929A
+:1001600011242F933F938F939F938091100190912F
+:100170001101019690931101809310018091120159
+:10018000813091F020911001309111018091130183
+:10019000909114012817390738F081E080931201FB
+:1001A00010921101109210019F918F913F912F9108
+:1001B0000F900FBE0F901F9018951F920F920FB6C1
+:1001C0000F9211242F933F938F939F93809110014F
+:1001D00090911101019690931101809310018091EB
+:1001E0001201813091F02091100130911101809124
+:1001F0001301909114012817390738F081E080939A
+:10020000120110921101109210019F918F913F9154
+:100210002F910F900FBE0F901F9018951F920F9265
+:100220000FB60F9211242F933F938F939F9380913A
+:10023000100190911101019690931101809310018A
+:1002400080911201813091F02091100130911101C3
+:1002500080911301909114012817390738F081E03B
+:100260008093120110921101109210019F918F91B1
+:100270003F912F910F900FBE0F901F901895FC018A
+:10028000219A85E290E09387828785B5836085BD5A
+:1002900081E090E09587848722E030E0309314017C
+:1002A0002093130124B5226024BD29EF27BD978731
+:1002B000868780E090E00895CF92DF92EF92FF92E0
+:1002C00080E091E00E943F01C12CD12C760160E0DA
+:1002D00070E0CB01609300017093010180930201F3
+:1002E0009093030180E091E00E9453008FEFC81AC1
+:1002F000D80AE80AF80AC701B6010E94F4012FE6FD
+:1003000032E143E05BE30E94A60220E030E0A90175
+:100310000E948C01DFCF5058BB27AA270ED0DCC02B
+:10032000CDD030F0D2D020F031F49F3F11F41EF444
+:10033000C2C00EF4E095E7FBB8C0E92FDED080F331
+:10034000BA17620773078407950718F071F49EF5D2
+:10035000F6C00EF4E0950B2EBA2FA02D0B01B901BB
+:1003600090010C01CA01A0011124FF27591B99F02B
+:10037000593F50F4503E68F11A16F040A22F232F37
+:10038000342F4427585FF3CF469537952795A79587
+:10039000F0405395C9F77EF41F16BA0B620B730B2E
+:1003A000840BBAF09150A1F0FF0FBB1F661F771F9F
+:1003B000881FC2F70EC0BA0F621F731F841F48F454
+:1003C000879577956795B795F7959E3F08F0B3CFDA
+:1003D0009395880F08F09927EE0F979587950895C4
+:1003E00040D008F481E00895E89409C097FB3EF4FA
+:1003F00090958095709561957F4F8F4F9F4F992372
+:10040000A9F0F92F96E9BB279395F69587957795EF
+:100410006795B795F111F8CFFAF4BB0F11F460FFAF
+:100420001BC06F5F7F4F8F4F9F4F16C0882311F007
+:1004300096E911C0772321F09EE8872F762F05C01B
+:10044000662371F096E8862F70E060E02AF09A95B6
+:10045000660F771F881FDAF7880F9695879597F9AB
+:100460000895990F0008550FAA0BE0E8FEEF161645
+:100470001706E807F907C0F012161306E407F50798
+:1004800098F0621B730B840B950B39F40A2661F00C
+:10049000232B242B252B21F408950A2609F4A140AF
+:1004A000A6958FEF811D811D089597F99F6780E8BC
+:1004B00070E060E008959FEF80EC089500240A94B6
+:1004C0001616170618060906089500240A9412162F
+:1004D0001306140605060895092E0394000C11F462
+:1004E000882352F0BB0F40F4BF2B11F460FF04C00F
+:1004F0006F5F7F4F8F4F9F4F089557FD9058440F68
+:10050000551F59F05F3F71F04795880F97FB991F72
+:1005100061F09F3F79F0879508951216130614062F
+:10052000551FF2CF4695F1DF08C0161617061806BC
+:10053000991FF1CF86957105610508940895E89497
+:10054000BB2766277727CB0197F908950BD0C4CF37
+:10055000B5DF28F0BADF18F0952309F0A6CFABCFAE
+:100560001124EECFCADFA0F3959FD1F3950F50E091
+:10057000551F629FF001729FBB27F00DB11D639F55
+:10058000AA27F00DB11DAA1F649F6627B00DA11DFB
+:10059000661F829F2227B00DA11D621F739FB00DA1
+:1005A000A11D621F839FA00D611D221F749F332711
+:1005B000A00D611D231F849F600D211D822F762FAA
+:1005C0006A2F11249F5750408AF0E1F088234AF0A7
+:1005D000EE0FFF1FBB1F661F771F881F91505040F3
+:1005E000A9F79E3F510570F060CFAACF5F3FECF3B3
+:1005F000983EDCF3869577956795B795F795E795DF
+:100600009F5FC1F7FE2B880F911D9695879597F9EF
+:060610000895F894FFCFED
+:100616000000000001006F12033B00000000000014
+:00000001FF
diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/led/led_blue_delay.sh b/OpenModelica_Arduino_With_MDD/MDD_build/led/led_blue_delay.sh new file mode 100644 index 0000000..53c7838 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/led/led_blue_delay.sh @@ -0,0 +1,61 @@ +#!/bin/bash +clear +if [ "$#" -ne 2 ]; then + echo "Usage: $0 port baudrate" >&2 + exit 1 +fi + +re='^[0-9]+$' +if ! [[ $1 =~ $re ]] ; then + echo "error: $1 -> Not a number" >&2; exit 1 +fi + +if ! [[ $2 =~ $re ]] ; then + echo "error: $2-> Not a number" >&2; exit 1 +fi + +b_rate=$2 + +present=`pwd` +unamestr=`uname` + +if [[ "$unamestr" == 'Linux' ]]; then + mdd_path=($(locate Modelica_DeviceDrivers/Modelica_DeviceDrivers/Resources/Include)) + om_path=($(locate /usr/include/omc/c)) + port="/dev/ttyACM$1" + omc --simCodeTarget=ExperimentalEmbeddedC runMDD_led_blue_delay.mos + if [ $? -ne 0 ]; then + exit 1 + fi +else + cd c: + om_path=($(dir -d OpenModelica*/include/omc/c/)) + path_to_om="C:$om_path" + cd f: + mdd_path=($(dir -d */Modelica_DeviceDrivers/Modelica_DeviceDrivers/Resources/Include/)) + if [ $? -eq 0 ]; then + path_to_mdd="F:/$mdd_path" + else + exit 1 + fi + + port="COM$1" + cd $present + omc --simCodeTarget=ExperimentalEmbeddedC run_led_blue_delay.mos + if [ $? -ne 0 ]; then + exit 1 + fi +fi + +avr-gcc -Os -std=c11 -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000UL -Wl,--gc-sections led_blue_delay_main.c -o led_blue_delay -I${mdd_path[0]} -I${path_to_om} -I${path_to_mdd} -I${om_path[0]} +if [ $? -ne 0 ]; then + exit 1 +fi +avr-objcopy -O ihex -R .eeprom led_blue_delay led_blue_delay.hex +if [ $? -ne 0 ]; then + exit 1 +fi +avrdude -F -V -c arduino -p ATMEGA328P -P $port -b $b_rate -U flash:w:led_blue_delay.hex +if [ $? -ne 0 ]; then + exit 1 +fi
\ No newline at end of file diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/led/led_blue_delay_main.c b/OpenModelica_Arduino_With_MDD/MDD_build/led/led_blue_delay_main.c new file mode 100644 index 0000000..80930a6 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/led/led_blue_delay_main.c @@ -0,0 +1,212 @@ +#define fmi2TypesPlatform_h + +#define fmi2TypesPlatform "default" /* Compatible */ + +typedef struct led_blue_delay_fmi2Component_s* fmi2Component; +typedef void* fmi2ComponentEnvironment; /* Pointer to FMU environment */ +typedef void* fmi2FMUstate; /* Pointer to internal FMU state */ +typedef unsigned int fmi2ValueReference; +typedef double fmi2Real; +typedef int fmi2Integer; +typedef int fmi2Boolean; +typedef char fmi2Char; +typedef const fmi2Char* fmi2String; +typedef char fmi2Byte; + +#define fmi2True 1 +#define fmi2False 0 + +#include "fmi2/fmi2Functions.h" + +#include <stdint.h> +#include <stdio.h> + +void ModelicaFormatMessage(const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + vprintf(fmt, args); + va_end(args); +} + +typedef struct led_blue_delay_fmi2Component_s { + fmi2Real currentTime; + fmi2Boolean fmi2BooleanVars[1]; + fmi2Real fmi2RealParameter[1]; + void* extObjs[3]; +} led_blue_delay_fmi2Component; + +led_blue_delay_fmi2Component led_blue_delay_component = { + .fmi2BooleanVars = { + fmi2True /*booleanExpression1._y*/, + }, + .fmi2RealParameter = { + 0.002 /*synchronizeRealtime1._actualInterval*/, + }, +}; + +#include <math.h> +/* TODO: Generate used builtin functions before SimCode */ +static inline double om_mod(double x, double y) +{ + return x-floor(x/y)*y; +} + +#include "MDDAVRTimer.h" +#include "MDDAVRRealTime.h" +#include "MDDAVRDigital.h" + +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(fmi2Component comp, void* om_port, fmi2Integer om_pin, fmi2Boolean om_value); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_destructor(fmi2Component comp, void* om_digital); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer); + +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(fmi2Component comp, void* om_port, fmi2Integer om_pin, fmi2Boolean om_value) +{ + MDD_avr_digital_pin_write(om_port, om_pin, om_value); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin) +{ + void* om_dig; + om_dig = MDD_avr_digital_pin_init(om_port, om_pin, fmi2True); + return om_dig; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_destructor(fmi2Component comp, void* om_digital) +{ + MDD_avr_digital_pin_close(om_digital); +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt) +{ + MDD_avr_rt_wait(om_rt); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle) +{ + void* om_rt; + om_rt = MDD_avr_rt_init(om_timer, om_timerValue, om_numTimerInterruptsPerCycle); + return om_rt; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt) +{ + MDD_avr_rt_close(om_rt); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch) +{ + void* om_timer; + om_timer = MDD_avr_timer_init(om_timerSelect, om_clockSelect, om_clearTimerOnMatch); + return om_timer; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer) +{ + MDD_avr_timer_close(om_timer); +} + +fmi2Component led_blue_delay_fmi2Instantiate(fmi2String name, fmi2Type ty, fmi2String GUID, fmi2String resources, const fmi2CallbackFunctions* functions, fmi2Boolean visible, fmi2Boolean loggingOn) +{ + static int initDone=0; + if (initDone) { + return NULL; + } + return &led_blue_delay_component; +} + +fmi2Status led_blue_delay_fmi2SetupExperiment(fmi2Component comp, fmi2Boolean toleranceDefined, fmi2Real tolerance, fmi2Real startTime, fmi2Boolean stopTimeDefined, fmi2Real stopTime) +{ + return fmi2OK; +} + +fmi2Status led_blue_delay_fmi2EnterInitializationMode(fmi2Component comp) +{ + comp->extObjs[0] /* digitalWriteBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(comp, 2, 2); + comp->extObjs[1] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(comp, 1, 4, fmi2False); + comp->extObjs[2] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(comp, comp->extObjs[1] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */, 249, 2); + return fmi2OK; +} + +fmi2Status led_blue_delay_fmi2ExitInitializationMode(fmi2Component comp) +{ + return fmi2OK; +} + +static fmi2Status led_blue_delay_functionODE(fmi2Component comp) +{ +} + +static fmi2Status led_blue_delay_functionOutputs(fmi2Component comp) +{ + comp->fmi2BooleanVars[0] /* booleanExpression1._y DISCRETE */ = (comp->currentTime)<(5.0); /* equation 3 */Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(comp, comp->extObjs[2] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */);Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(comp, comp->extObjs[0] /* digitalWriteBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */, 2, comp->fmi2BooleanVars[0] /* booleanExpression1._y DISCRETE */); +} + +fmi2Status led_blue_delay_fmi2DoStep(fmi2Component comp, fmi2Real currentCommunicationPoint, fmi2Real communicationStepSize, fmi2Boolean noSetFMUStatePriorToCurrentPoint) +{ + comp->currentTime = currentCommunicationPoint; + /* TODO: Calculate time/state-dependent variables here... */ + led_blue_delay_functionOutputs(comp); + return fmi2OK; +} + +int main(int argc, char **argv) +{ + int terminateSimulation = 0; + fmi2Status status = fmi2OK; + fmi2CallbackFunctions cbf = { + .logger = NULL, + .allocateMemory = NULL /*calloc*/, + .freeMemory = NULL /*free*/, + .stepFinished = NULL, //synchronous execution + .componentEnvironment = NULL + }; + + fmi2Component comp = led_blue_delay_fmi2Instantiate("", fmi2CoSimulation, "", "", &cbf, fmi2False, fmi2False); + if (comp==NULL) { + return 1; + } + led_blue_delay_fmi2SetupExperiment(comp, fmi2False, 0.0, 0.0, fmi2False, 1.0); + led_blue_delay_fmi2EnterInitializationMode(comp); + // Set start-values? Nah... + led_blue_delay_fmi2ExitInitializationMode(comp); + + double currentTime = 0.0; + double h = 0.002; + uint32_t i = 0; + + while (status == fmi2OK) { + //retrieve outputs + // fmi2GetReal(m, ..., 1, &y1); + //set inputs + // fmi2SetReal(m, ..., 1, &y2); + + //call slave and check status + status = led_blue_delay_fmi2DoStep(comp, currentTime, h, fmi2True); + switch (status) { + case fmi2Discard: + case fmi2Error: + case fmi2Fatal: + case fmi2Pending /* Cannot happen */: + terminateSimulation = 1; + break; + case fmi2OK: + case fmi2Warning: + break; + } + if (terminateSimulation) { + break; + } + i++; + /* increment master time */ + currentTime = 0.0 + h*i; + } + +#if 0 + if ((status != fmi2Error) && (status != fmi2Fatal)) { + fmi2Terminate(m); + } + if (status != fmi2Fatal) { + fmi2FreeInstance(m); + } +#endif +} + diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/led/led_blue_main.c b/OpenModelica_Arduino_With_MDD/MDD_build/led/led_blue_main.c new file mode 100644 index 0000000..048f6c8 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/led/led_blue_main.c @@ -0,0 +1,212 @@ +#define fmi2TypesPlatform_h + +#define fmi2TypesPlatform "default" /* Compatible */ + +typedef struct led_blue_fmi2Component_s* fmi2Component; +typedef void* fmi2ComponentEnvironment; /* Pointer to FMU environment */ +typedef void* fmi2FMUstate; /* Pointer to internal FMU state */ +typedef unsigned int fmi2ValueReference; +typedef double fmi2Real; +typedef int fmi2Integer; +typedef int fmi2Boolean; +typedef char fmi2Char; +typedef const fmi2Char* fmi2String; +typedef char fmi2Byte; + +#define fmi2True 1 +#define fmi2False 0 + +#include "fmi2/fmi2Functions.h" + +#include <stdint.h> +#include <stdio.h> + +void ModelicaFormatMessage(const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + vprintf(fmt, args); + va_end(args); +} + +typedef struct led_blue_fmi2Component_s { + fmi2Real currentTime; + fmi2Boolean fmi2BooleanVars[1]; + fmi2Real fmi2RealParameter[1]; + void* extObjs[3]; +} led_blue_fmi2Component; + +led_blue_fmi2Component led_blue_component = { + .fmi2BooleanVars = { + fmi2False /*booleanExpression1._y*/, + }, + .fmi2RealParameter = { + 0.002 /*synchronizeRealtime1._actualInterval*/, + }, +}; + +#include <math.h> +/* TODO: Generate used builtin functions before SimCode */ +static inline double om_mod(double x, double y) +{ + return x-floor(x/y)*y; +} + +#include "MDDAVRTimer.h" +#include "MDDAVRRealTime.h" +#include "MDDAVRDigital.h" + +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(fmi2Component comp, void* om_port, fmi2Integer om_pin, fmi2Boolean om_value); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_destructor(fmi2Component comp, void* om_digital); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer); + +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(fmi2Component comp, void* om_port, fmi2Integer om_pin, fmi2Boolean om_value) +{ + MDD_avr_digital_pin_write(om_port, om_pin, om_value); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin) +{ + void* om_dig; + om_dig = MDD_avr_digital_pin_init(om_port, om_pin, fmi2True); + return om_dig; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_destructor(fmi2Component comp, void* om_digital) +{ + MDD_avr_digital_pin_close(om_digital); +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt) +{ + MDD_avr_rt_wait(om_rt); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle) +{ + void* om_rt; + om_rt = MDD_avr_rt_init(om_timer, om_timerValue, om_numTimerInterruptsPerCycle); + return om_rt; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt) +{ + MDD_avr_rt_close(om_rt); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch) +{ + void* om_timer; + om_timer = MDD_avr_timer_init(om_timerSelect, om_clockSelect, om_clearTimerOnMatch); + return om_timer; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer) +{ + MDD_avr_timer_close(om_timer); +} + +fmi2Component led_blue_fmi2Instantiate(fmi2String name, fmi2Type ty, fmi2String GUID, fmi2String resources, const fmi2CallbackFunctions* functions, fmi2Boolean visible, fmi2Boolean loggingOn) +{ + static int initDone=0; + if (initDone) { + return NULL; + } + return &led_blue_component; +} + +fmi2Status led_blue_fmi2SetupExperiment(fmi2Component comp, fmi2Boolean toleranceDefined, fmi2Real tolerance, fmi2Real startTime, fmi2Boolean stopTimeDefined, fmi2Real stopTime) +{ + return fmi2OK; +} + +fmi2Status led_blue_fmi2EnterInitializationMode(fmi2Component comp) +{ + comp->extObjs[0] /* digitalWriteBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(comp, 2, 2); + comp->extObjs[1] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(comp, 1, 4, fmi2False); + comp->extObjs[2] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(comp, comp->extObjs[1] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */, 249, 2); + return fmi2OK; +} + +fmi2Status led_blue_fmi2ExitInitializationMode(fmi2Component comp) +{ + return fmi2OK; +} + +static fmi2Status led_blue_functionODE(fmi2Component comp) +{ +} + +static fmi2Status led_blue_functionOutputs(fmi2Component comp) +{ + Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(comp, comp->extObjs[2] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */);Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(comp, comp->extObjs[0] /* digitalWriteBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */, 2, fmi2True); +} + +fmi2Status led_blue_fmi2DoStep(fmi2Component comp, fmi2Real currentCommunicationPoint, fmi2Real communicationStepSize, fmi2Boolean noSetFMUStatePriorToCurrentPoint) +{ + comp->currentTime = currentCommunicationPoint; + /* TODO: Calculate time/state-dependent variables here... */ + led_blue_functionOutputs(comp); + return fmi2OK; +} + +int main(int argc, char **argv) +{ + int terminateSimulation = 0; + fmi2Status status = fmi2OK; + fmi2CallbackFunctions cbf = { + .logger = NULL, + .allocateMemory = NULL /*calloc*/, + .freeMemory = NULL /*free*/, + .stepFinished = NULL, //synchronous execution + .componentEnvironment = NULL + }; + + fmi2Component comp = led_blue_fmi2Instantiate("", fmi2CoSimulation, "", "", &cbf, fmi2False, fmi2False); + if (comp==NULL) { + return 1; + } + led_blue_fmi2SetupExperiment(comp, fmi2False, 0.0, 0.0, fmi2False, 1.0); + led_blue_fmi2EnterInitializationMode(comp); + // Set start-values? Nah... + led_blue_fmi2ExitInitializationMode(comp); + + double currentTime = 0.0; + double h = 0.002; + uint32_t i = 0; + + while (status == fmi2OK) { + //retrieve outputs + // fmi2GetReal(m, ..., 1, &y1); + //set inputs + // fmi2SetReal(m, ..., 1, &y2); + + //call slave and check status + status = led_blue_fmi2DoStep(comp, currentTime, h, fmi2True); + switch (status) { + case fmi2Discard: + case fmi2Error: + case fmi2Fatal: + case fmi2Pending /* Cannot happen */: + terminateSimulation = 1; + break; + case fmi2OK: + case fmi2Warning: + break; + } + if (terminateSimulation) { + break; + } + i++; + /* increment master time */ + currentTime = 0.0 + h*i; + } + +#if 0 + if ((status != fmi2Error) && (status != fmi2Fatal)) { + fmi2Terminate(m); + } + if (status != fmi2Fatal) { + fmi2FreeInstance(m); + } +#endif +} + diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/led/led_blue_new.sh b/OpenModelica_Arduino_With_MDD/MDD_build/led/led_blue_new.sh new file mode 100644 index 0000000..96f97e2 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/led/led_blue_new.sh @@ -0,0 +1,61 @@ +#!/bin/bash +clear +if [ "$#" -ne 2 ]; then + echo "Usage: $0 port baudrate" >&2 + exit 1 +fi + +re='^[0-9]+$' +if ! [[ $1 =~ $re ]] ; then + echo "error: $1 -> Not a number" >&2; exit 1 +fi + +if ! [[ $2 =~ $re ]] ; then + echo "error: $2-> Not a number" >&2; exit 1 +fi + +b_rate=$2 + +present=`pwd` +unamestr=`uname` + +if [[ "$unamestr" == 'Linux' ]]; then + mdd_path=($(locate Modelica_DeviceDrivers/Resources/Include)) + om_path=($(locate /usr/include/omc/c)) + port="/dev/ttyACM$1" + omc --simCodeTarget=ExperimentalEmbeddedC runMDD_led_blue.mos + if [ $? -ne 0 ]; then + exit 1 + fi +else + cd c: + om_path=($(dir -d OpenModelica*/include/omc/c/)) + path_to_om="C:$om_path" + cd f: + mdd_path=($(dir -d */Modelica_DeviceDrivers/Modelica_DeviceDrivers/Resources/Include/)) + if [ $? -eq 0 ]; then + path_to_mdd="F:/$mdd_path" + else + exit 1 + fi + + port="COM$1" + cd $present + omc --simCodeTarget=ExperimentalEmbeddedC run_led_blue.mos + if [ $? -ne 0 ]; then + exit 1 + fi +fi + +avr-gcc -Os -std=c11 -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000UL -Wl,--gc-sections led_blue_main.c -o led_blue -I${mdd_path[0]} -I${path_to_om} -I${path_to_mdd} -I${om_path[0]} +if [ $? -ne 0 ]; then + exit 1 +fi +avr-objcopy -O ihex -R .eeprom led_blue led_blue.hex +if [ $? -ne 0 ]; then + exit 1 +fi +avrdude -F -V -c arduino -p ATMEGA328P -P $port -b $b_rate -U flash:w:led_blue.hex +if [ $? -ne 0 ]; then + exit 1 +fi diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/led/led_blue_new.sh~ b/OpenModelica_Arduino_With_MDD/MDD_build/led/led_blue_new.sh~ new file mode 100644 index 0000000..96f97e2 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/led/led_blue_new.sh~ @@ -0,0 +1,61 @@ +#!/bin/bash +clear +if [ "$#" -ne 2 ]; then + echo "Usage: $0 port baudrate" >&2 + exit 1 +fi + +re='^[0-9]+$' +if ! [[ $1 =~ $re ]] ; then + echo "error: $1 -> Not a number" >&2; exit 1 +fi + +if ! [[ $2 =~ $re ]] ; then + echo "error: $2-> Not a number" >&2; exit 1 +fi + +b_rate=$2 + +present=`pwd` +unamestr=`uname` + +if [[ "$unamestr" == 'Linux' ]]; then + mdd_path=($(locate Modelica_DeviceDrivers/Resources/Include)) + om_path=($(locate /usr/include/omc/c)) + port="/dev/ttyACM$1" + omc --simCodeTarget=ExperimentalEmbeddedC runMDD_led_blue.mos + if [ $? -ne 0 ]; then + exit 1 + fi +else + cd c: + om_path=($(dir -d OpenModelica*/include/omc/c/)) + path_to_om="C:$om_path" + cd f: + mdd_path=($(dir -d */Modelica_DeviceDrivers/Modelica_DeviceDrivers/Resources/Include/)) + if [ $? -eq 0 ]; then + path_to_mdd="F:/$mdd_path" + else + exit 1 + fi + + port="COM$1" + cd $present + omc --simCodeTarget=ExperimentalEmbeddedC run_led_blue.mos + if [ $? -ne 0 ]; then + exit 1 + fi +fi + +avr-gcc -Os -std=c11 -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000UL -Wl,--gc-sections led_blue_main.c -o led_blue -I${mdd_path[0]} -I${path_to_om} -I${path_to_mdd} -I${om_path[0]} +if [ $? -ne 0 ]; then + exit 1 +fi +avr-objcopy -O ihex -R .eeprom led_blue led_blue.hex +if [ $? -ne 0 ]; then + exit 1 +fi +avrdude -F -V -c arduino -p ATMEGA328P -P $port -b $b_rate -U flash:w:led_blue.hex +if [ $? -ne 0 ]; then + exit 1 +fi diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/led/led_blue_red b/OpenModelica_Arduino_With_MDD/MDD_build/led/led_blue_red Binary files differnew file mode 100644 index 0000000..a13b867 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/led/led_blue_red diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/led/led_blue_red.hex b/OpenModelica_Arduino_With_MDD/MDD_build/led/led_blue_red.hex new file mode 100644 index 0000000..2f6c931 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/led/led_blue_red.hex @@ -0,0 +1,106 @@ +:100000000C9434000C9451000C9451000C94510049
+:100010000C9451000C9451000C9451000C94340138
+:100020000C9451000C9451000C9451000C94030159
+:100030000C9451000C9451000C94D2000C9451007B
+:100040000C9451000C9451000C9451000C945100EC
+:100050000C9451000C9451000C9451000C945100DC
+:100060000C9451000C94510011241FBECFEFD8E026
+:10007000DEBFCDBF11E0A0E0B1E0E8E6F6E002C0EF
+:1000800005900D92A431B107D9F711E0A4E1B1E0D8
+:1000900001C01D92A931B107E1F70E9485010C94BE
+:1000A00032030C940000CF92DF92EF92FF920F93F5
+:1000B0001F93CF93DF93EC01C880D980EA80FB8047
+:1000C00001E010E020E030E040EA50E4C701B60172
+:1000D0000E94190287FD02C000E010E01D830C831E
+:1000E00001E010E020E030E040E051E4C701B6015B
+:1000F0000E94190287FD02C000E010E01F830E83FA
+:100100008A899B898230910561F08330910599F04D
+:100110000197C9F416BC80916E00826080936E00D6
+:1001200016C0109285001092840080916F0082604A
+:1001300080936F000CC01092B200809170008260BA
+:100140008093700004C081E090E00E9432037894B4
+:100150009FB7F894809116019FBF8823C9F310922E
+:100160001601EC85FD858C819D81892B19F080819C
+:10017000826002C080818D7F8083EE85FF858E81C5
+:100180009F81892B19F08081886002C08081877FE0
+:100190008083DF91CF911F910F91FF90EF90DF90BF
+:1001A000CF9008951F920F920FB60F9211242F93A4
+:1001B0003F938F939F938091140190911501019625
+:1001C000909315018093140180911601813091F074
+:1001D000209114013091150180911701909118011F
+:1001E0002817390738F081E0809316011092150125
+:1001F000109214019F918F913F912F910F900FBEFC
+:100200000F901F9018951F920F920FB60F92112406
+:100210002F933F938F939F93809114019091150199
+:1002200001969093150180931401809116018130FD
+:1002300091F0209114013091150180911701909156
+:1002400018012817390738F081E0809316011092C1
+:100250001501109214019F918F913F912F910F9052
+:100260000FBE0F901F9018951F920F920FB60F920E
+:1002700011242F933F938F939F938091140190911A
+:100280001501019690931501809314018091160138
+:10029000813091F020911401309115018091170166
+:1002A000909118012817390738F081E080931601E2
+:1002B00010921501109214019F918F913F912F91EF
+:1002C0000F900FBE0F901F901895FC01239A85E2A6
+:1002D00090E09787868725B5236025BD21E030E033
+:1002E000318B208B42E050E050931801409317016E
+:1002F00044B5426044BD49EF47BD338B228B219A00
+:100300009587848780E090E00895CF92DF92EF9206
+:10031000FF9280E091E00E946501C12CD12C760112
+:1003200060E070E0CB016093000170930101809365
+:1003300002019093030180E091E00E9453008FEF4F
+:10034000C81AD80AE80AF80AC701B6010E941D02B5
+:100350002FE632E143E05BE30E94CF0220E030E091
+:10036000A9010E94B501DFCF5058BB27AA270ED0A4
+:10037000DCC0CDD030F0D2D020F031F49F3F11F46A
+:100380001EF4C2C00EF4E095E7FBB8C0E92FDED042
+:1003900080F3BA17620773078407950718F071F4A2
+:1003A0009EF5F6C00EF4E0950B2EBA2FA02D0B0192
+:1003B000B90190010C01CA01A0011124FF27591BAA
+:1003C00099F0593F50F4503E68F11A16F040A22FB0
+:1003D000232F342F4427585FF3CF46953795279521
+:1003E000A795F0405395C9F77EF41F16BA0B620B20
+:1003F000730B840BBAF09150A1F0FF0FBB1F661F67
+:10040000771F881FC2F70EC0BA0F621F731F841FA9
+:1004100048F4879577956795B795F7959E3F08F0CF
+:10042000B3CF9395880F08F09927EE0F979587958E
+:10043000089540D008F481E00895E89409C097FB3E
+:100440003EF490958095709561957F4F8F4F9F4FAB
+:100450009923A9F0F92F96E9BB279395F6958795EF
+:1004600077956795B795F111F8CFFAF4BB0F11F4B2
+:1004700060FF1BC06F5F7F4F8F4F9F4F16C0882359
+:1004800011F096E911C0772321F09EE8872F762F8F
+:1004900005C0662371F096E8862F70E060E02AF0D0
+:1004A0009A95660F771F881FDAF7880F96958795BC
+:1004B00097F90895990F0008550FAA0BE0E8FEEF91
+:1004C00016161706E807F907C0F012161306E40718
+:1004D000F50798F0621B730B840B950B39F40A2611
+:1004E00061F0232B242B252B21F408950A2609F4EF
+:1004F000A140A6958FEF811D811D089597F99F67F3
+:1005000080E870E060E008959FEF80EC089500249B
+:100510000A941616170618060906089500240A9468
+:1005200012161306140605060895092E0394000CEE
+:1005300011F4882352F0BB0F40F4BF2B11F460FF7D
+:1005400004C06F5F7F4F8F4F9F4F089557FD9058A6
+:10055000440F551F59F05F3F71F04795880F97FB87
+:10056000991F61F09F3F79F0879508951216130641
+:100570001406551FF2CF4695F1DF08C01616170670
+:100580001806991FF1CF86957105610508940895A5
+:10059000E894BB2766277727CB0197F908950BD0FE
+:1005A000C4CFB5DF28F0BADF18F0952309F0A6CF45
+:1005B000ABCF1124EECFCADFA0F3959FD1F3950FF7
+:1005C00050E0551F629FF001729FBB27F00DB11DD7
+:1005D000639FAA27F00DB11DAA1F649F6627B00D67
+:1005E000A11D661F829F2227B00DA11D621F739F50
+:1005F000B00DA11D621F839FA00D611D221F749F5E
+:100600003327A00D611D231F849F600D211D822FA4
+:10061000762F6A2F11249F5750408AF0E1F08823EB
+:100620004AF0EE0FFF1FBB1F661F771F881F9150F8
+:100630005040A9F79E3F510570F060CFAACF5F3FB1
+:10064000ECF3983EDCF3869577956795B795F7952B
+:10065000E7959F5FC1F7FE2B880F911D96958795B3
+:0806600097F90895F894FFCF0B
+:1006680000000000010001006F12033B00000000C1
+:04067800000000007E
+:00000001FF
diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/led/led_blue_red.sh b/OpenModelica_Arduino_With_MDD/MDD_build/led/led_blue_red.sh new file mode 100644 index 0000000..7de1e2c --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/led/led_blue_red.sh @@ -0,0 +1,61 @@ +#!/bin/bash +clear +if [ "$#" -ne 2 ]; then + echo "Usage: $0 port baudrate" >&2 + exit 1 +fi + +re='^[0-9]+$' +if ! [[ $1 =~ $re ]] ; then + echo "error: $1 -> Not a number" >&2; exit 1 +fi + +if ! [[ $2 =~ $re ]] ; then + echo "error: $2-> Not a number" >&2; exit 1 +fi + +b_rate=$2 + +present=`pwd` +unamestr=`uname` + +if [[ "$unamestr" == 'Linux' ]]; then + mdd_path=($(locate Modelica_DeviceDrivers/Modelica_DeviceDrivers/Resources/Include)) + om_path=($(locate /usr/include/omc/c)) + port="/dev/ttyACM$1" + omc --simCodeTarget=ExperimentalEmbeddedC runMDD_led_blue_red.mos + if [ $? -ne 0 ]; then + exit 1 + fi +else + cd c: + om_path=($(dir -d OpenModelica*/include/omc/c/)) + path_to_om="C:$om_path" + cd f: + mdd_path=($(dir -d */Modelica_DeviceDrivers/Modelica_DeviceDrivers/Resources/Include/)) + if [ $? -eq 0 ]; then + path_to_mdd="F:/$mdd_path" + else + exit 1 + fi + + port="COM$1" + cd $present + omc --simCodeTarget=ExperimentalEmbeddedC run_led_blue_red.mos + if [ $? -ne 0 ]; then + exit 1 + fi +fi + +avr-gcc -Os -std=c11 -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000UL -Wl,--gc-sections led_blue_red_main.c -o led_blue_red -I${mdd_path[0]} -I${path_to_om} -I${path_to_mdd} -I${om_path[0]} +if [ $? -ne 0 ]; then + exit 1 +fi +avr-objcopy -O ihex -R .eeprom led_blue_red led_blue_red.hex +if [ $? -ne 0 ]; then + exit 1 +fi +avrdude -F -V -c arduino -p ATMEGA328P -P $port -b $b_rate -U flash:w:led_blue_red.hex +if [ $? -ne 0 ]; then + exit 1 +fi
\ No newline at end of file diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/led/led_blue_red_main.c b/OpenModelica_Arduino_With_MDD/MDD_build/led/led_blue_red_main.c new file mode 100644 index 0000000..c9668e8 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/led/led_blue_red_main.c @@ -0,0 +1,215 @@ +#define fmi2TypesPlatform_h + +#define fmi2TypesPlatform "default" /* Compatible */ + +typedef struct led_blue_red_fmi2Component_s* fmi2Component; +typedef void* fmi2ComponentEnvironment; /* Pointer to FMU environment */ +typedef void* fmi2FMUstate; /* Pointer to internal FMU state */ +typedef unsigned int fmi2ValueReference; +typedef double fmi2Real; +typedef int fmi2Integer; +typedef int fmi2Boolean; +typedef char fmi2Char; +typedef const fmi2Char* fmi2String; +typedef char fmi2Byte; + +#define fmi2True 1 +#define fmi2False 0 + +#include "fmi2/fmi2Functions.h" + +#include <stdint.h> +#include <stdio.h> + +void ModelicaFormatMessage(const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + vprintf(fmt, args); + va_end(args); +} + +typedef struct led_blue_red_fmi2Component_s { + fmi2Real currentTime; + fmi2Boolean fmi2BooleanVars[2]; + fmi2Real fmi2RealParameter[1]; + void* extObjs[4]; +} led_blue_red_fmi2Component; + +led_blue_red_fmi2Component led_blue_red_component = { + .fmi2BooleanVars = { + fmi2True /*booleanExpression1._y*/, + fmi2True /*booleanExpression2._y*/, + }, + .fmi2RealParameter = { + 0.002 /*synchronizeRealtime1._actualInterval*/, + }, +}; + +#include <math.h> +/* TODO: Generate used builtin functions before SimCode */ +static inline double om_mod(double x, double y) +{ + return x-floor(x/y)*y; +} + +#include "MDDAVRTimer.h" +#include "MDDAVRRealTime.h" +#include "MDDAVRDigital.h" + +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(fmi2Component comp, void* om_port, fmi2Integer om_pin, fmi2Boolean om_value); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_destructor(fmi2Component comp, void* om_digital); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer); + +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(fmi2Component comp, void* om_port, fmi2Integer om_pin, fmi2Boolean om_value) +{ + MDD_avr_digital_pin_write(om_port, om_pin, om_value); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin) +{ + void* om_dig; + om_dig = MDD_avr_digital_pin_init(om_port, om_pin, fmi2True); + return om_dig; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_destructor(fmi2Component comp, void* om_digital) +{ + MDD_avr_digital_pin_close(om_digital); +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt) +{ + MDD_avr_rt_wait(om_rt); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle) +{ + void* om_rt; + om_rt = MDD_avr_rt_init(om_timer, om_timerValue, om_numTimerInterruptsPerCycle); + return om_rt; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt) +{ + MDD_avr_rt_close(om_rt); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch) +{ + void* om_timer; + om_timer = MDD_avr_timer_init(om_timerSelect, om_clockSelect, om_clearTimerOnMatch); + return om_timer; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer) +{ + MDD_avr_timer_close(om_timer); +} + +fmi2Component led_blue_red_fmi2Instantiate(fmi2String name, fmi2Type ty, fmi2String GUID, fmi2String resources, const fmi2CallbackFunctions* functions, fmi2Boolean visible, fmi2Boolean loggingOn) +{ + static int initDone=0; + if (initDone) { + return NULL; + } + return &led_blue_red_component; +} + +fmi2Status led_blue_red_fmi2SetupExperiment(fmi2Component comp, fmi2Boolean toleranceDefined, fmi2Real tolerance, fmi2Real startTime, fmi2Boolean stopTimeDefined, fmi2Real stopTime) +{ + return fmi2OK; +} + +fmi2Status led_blue_red_fmi2EnterInitializationMode(fmi2Component comp) +{ + comp->extObjs[1] /* digitalWriteBoolean2._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(comp, 2, 4); + comp->extObjs[2] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(comp, 1, 4, fmi2False); + comp->extObjs[3] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(comp, comp->extObjs[2] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */, 249, 2); + comp->extObjs[0] /* digitalWriteBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(comp, 2, 2); + return fmi2OK; +} + +fmi2Status led_blue_red_fmi2ExitInitializationMode(fmi2Component comp) +{ + return fmi2OK; +} + +static fmi2Status led_blue_red_functionODE(fmi2Component comp) +{ +} + +static fmi2Status led_blue_red_functionOutputs(fmi2Component comp) +{ + comp->fmi2BooleanVars[0] /* booleanExpression1._y DISCRETE */ = (comp->currentTime)<(5.0); /* equation 4 */ + comp->fmi2BooleanVars[1] /* booleanExpression2._y DISCRETE */ = (comp->currentTime)<(8.0); /* equation 5 */Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(comp, comp->extObjs[3] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */);Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(comp, comp->extObjs[0] /* digitalWriteBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */, 2, comp->fmi2BooleanVars[0] /* booleanExpression1._y DISCRETE */);Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(comp, comp->extObjs[1] /* digitalWriteBoolean2._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */, 4, comp->fmi2BooleanVars[1] /* booleanExpression2._y DISCRETE */); +} + +fmi2Status led_blue_red_fmi2DoStep(fmi2Component comp, fmi2Real currentCommunicationPoint, fmi2Real communicationStepSize, fmi2Boolean noSetFMUStatePriorToCurrentPoint) +{ + comp->currentTime = currentCommunicationPoint; + /* TODO: Calculate time/state-dependent variables here... */ + led_blue_red_functionOutputs(comp); + return fmi2OK; +} + +int main(int argc, char **argv) +{ + int terminateSimulation = 0; + fmi2Status status = fmi2OK; + fmi2CallbackFunctions cbf = { + .logger = NULL, + .allocateMemory = NULL /*calloc*/, + .freeMemory = NULL /*free*/, + .stepFinished = NULL, //synchronous execution + .componentEnvironment = NULL + }; + + fmi2Component comp = led_blue_red_fmi2Instantiate("", fmi2CoSimulation, "", "", &cbf, fmi2False, fmi2False); + if (comp==NULL) { + return 1; + } + led_blue_red_fmi2SetupExperiment(comp, fmi2False, 0.0, 0.0, fmi2False, 1.0); + led_blue_red_fmi2EnterInitializationMode(comp); + // Set start-values? Nah... + led_blue_red_fmi2ExitInitializationMode(comp); + + double currentTime = 0.0; + double h = 0.002; + uint32_t i = 0; + + while (status == fmi2OK) { + //retrieve outputs + // fmi2GetReal(m, ..., 1, &y1); + //set inputs + // fmi2SetReal(m, ..., 1, &y2); + + //call slave and check status + status = led_blue_red_fmi2DoStep(comp, currentTime, h, fmi2True); + switch (status) { + case fmi2Discard: + case fmi2Error: + case fmi2Fatal: + case fmi2Pending /* Cannot happen */: + terminateSimulation = 1; + break; + case fmi2OK: + case fmi2Warning: + break; + } + if (terminateSimulation) { + break; + } + i++; + /* increment master time */ + currentTime = 0.0 + h*i; + } + +#if 0 + if ((status != fmi2Error) && (status != fmi2Fatal)) { + fmi2Terminate(m); + } + if (status != fmi2Fatal) { + fmi2FreeInstance(m); + } +#endif +} + diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/led/led_green_blink b/OpenModelica_Arduino_With_MDD/MDD_build/led/led_green_blink Binary files differnew file mode 100644 index 0000000..e71feb7 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/led/led_green_blink diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/led/led_green_blink.hex b/OpenModelica_Arduino_With_MDD/MDD_build/led/led_green_blink.hex new file mode 100644 index 0000000..1c34b59 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/led/led_green_blink.hex @@ -0,0 +1,127 @@ +:100000000C9434000C9451000C9451000C94510049
+:100010000C9451000C9451000C9451000C942C0140
+:100020000C9451000C9451000C9451000C94FB0062
+:100030000C9451000C9451000C94CA000C94510083
+:100040000C9451000C9451000C9451000C945100EC
+:100050000C9451000C9451000C9451000C945100DC
+:100060000C9451000C94510011241FBECFEFD8E026
+:10007000DEBFCDBF11E0A0E0B1E0E8ECF7E002C0E8
+:1000800005900D92A031B107D9F711E0A0E1B1E0E0
+:1000900001C01D92A531B107E1F70E947A010C94CD
+:1000A000E2030C940000CF92DF92EF92FF920F9345
+:1000B0001F93CF93DF93EC01C880D980EA80FB8047
+:1000C0002DEC3CEC4CE45EE3C701B6010E940E024D
+:1000D0000E94B3022DEC3CEC4CE45EE30E945B0317
+:1000E0009B01AC01C701B6010E94A90101E010E02B
+:1000F0002DEC3CEC4CEC5DE30E94570387FF02C003
+:1001000000E010E01D830C838E859F858230910571
+:1001100061F08330910599F00197C9F416BC809184
+:100120006E00826080936E0016C01092850010925F
+:10013000840080916F00826080936F000CC01092E9
+:10014000B2008091700082608093700004C081E0F2
+:1001500090E00E94E20378949FB7F8948091120196
+:100160009FBF8823C9F310921201EA85FB858C8119
+:100170009D81892B19F08081826002C080818D7FF2
+:100180008083DF91CF911F910F91FF90EF90DF90CF
+:10019000CF9008951F920F920FB60F9211242F93B4
+:1001A0003F938F939F93809110019091110101963D
+:1001B000909311018093100180911201813091F090
+:1001C000209110013091110180911301909114013F
+:1001D0002817390738F081E080931201109211013D
+:1001E000109210019F918F913F912F910F900FBE10
+:1001F0000F901F9018951F920F920FB60F92112417
+:100200002F933F938F939F938091100190911101B1
+:100210000196909311018093100180911201813019
+:1002200091F0209110013091110180911301909172
+:1002300014012817390738F081E0809312011092D9
+:100240001101109210019F918F913F912F910F906A
+:100250000FBE0F901F9018951F920F920FB60F921E
+:1002600011242F933F938F939F938091100190912E
+:100270001101019690931101809310018091120158
+:10028000813091F020911001309111018091130182
+:10029000909114012817390738F081E080931201FA
+:1002A00010921101109210019F918F913F912F9107
+:1002B0000F900FBE0F901F901895FC0185B58360BD
+:1002C00085BD81E090E09587848722E030E030931F
+:1002D00014012093130124B5226024BD29EF27BD0A
+:1002E00097878687219A85E290E09387828780E0CE
+:1002F00090E00895CF92DF92EF92FF9280E091E03C
+:100300000E945D01C12CD12C760160E070E0CB0130
+:1003100060930001709301018093020190930301A7
+:1003200080E091E00E9453008FEFC81AD80AE80AD3
+:10033000F80AC701B6010E9476022FE632E143E0D7
+:100340005BE30E945B0320E030E0A9010E94AA0168
+:10035000DFCF5058BB27AA270ED058C149D130F063
+:100360004ED120F031F49F3F11F41EF43EC10EF443
+:10037000E095E7FB0BC1E92F5AD180F3BA1762076A
+:1003800073078407950718F071F49EF589C10EF480
+:10039000E0950B2EBA2FA02D0B01B90190010C0195
+:1003A000CA01A0011124FF27591B99F0593F50F4AD
+:1003B000503E68F11A16F040A22F232F342F442705
+:1003C000585FF3CF469537952795A795F0405395FD
+:1003D000C9F77EF41F16BA0B620B730B840BBAF0CD
+:1003E0009150A1F0FF0FBB1F661F771F881FC2F738
+:1003F0000EC0BA0F621F731F841F48F4879577954C
+:100400006795B795F7959E3F08F0B3CF9395880F02
+:1004100008F09927EE0F9795879508950CD0F6C0B0
+:10042000EED040F0E5D030F021F45F3F19F0AEC0DF
+:10043000511137C1DAC0FBD098F39923C9F3552382
+:10044000B1F3951B550BBB27AA27621773078407C7
+:1004500038F09F5F5F4F220F331F441FAA1FA9F37D
+:1004600033D00E2E3AF0E0E830D091505040E6956F
+:10047000001CCAF729D0FE2F27D0660F771F881FD0
+:10048000BB1F261737074807AB07B0E809F0BB0BBF
+:10049000802DBF01FF2793585F4F2AF09E3F5105E3
+:1004A00068F074C0FEC05F3FECF3983EDCF38695C5
+:1004B00077956795B795F7959F5FC9F7880F911D59
+:1004C0009695879597F90895E1E0660F771F881F45
+:1004D000BB1F621773078407BA0720F0621B730BF8
+:1004E000840BBA0BEE1F88F7E0950895E89409C0D5
+:1004F00097FB3EF490958095709561957F4F8F4F57
+:100500009F4F9923A9F0F92F96E9BB279395F6956C
+:10051000879577956795B795F111F8CFFAF4BB0FEA
+:1005200011F460FF1BC06F5F7F4F8F4F9F4F16C04E
+:10053000882311F096E911C0772321F09EE8872FD8
+:10054000762F05C0662371F096E8862F70E060E094
+:100550002AF09A95660F771F881FDAF7880F96950D
+:10056000879597F9089585D080F09F3740F49111D1
+:100570000EF097C060E070E080E89FEB089526F4ED
+:100580001B16611D711D811D07C021C097F99F6752
+:1005900080E870E060E00895882371F4772321F00B
+:1005A0009850872B762F07C0662311F499270DC02A
+:1005B0009051862B70E060E02AF09A95660F771FC5
+:1005C000881FDAF7880F9695879597F908959F3FCA
+:1005D00031F0915020F4879577956795B795880FFE
+:1005E000911D9695879597F908959FEF80EC089552
+:1005F00000240A9416161706180609060895002402
+:100600000A9412161306140605060895092E03947B
+:10061000000C11F4882352F0BB0F40F4BF2B11F4EF
+:1006200060FF04C06F5F7F4F8F4F9F4F089557FD4E
+:100630009058440F551F59F05F3F71F04795880F50
+:1006400097FB991F61F09F3F79F0879508951216E7
+:1006500013061406551FF2CF4695F1DF08C0161693
+:1006600017061806991FF1CF869571056105089444
+:100670000895E5DFA0F0BEE7B91788F4BB279F38DF
+:1006800060F41616B11D672F782F8827985FF7CF73
+:10069000869577956795B11D93959639C8F308951A
+:1006A000E894BB2766277727CB0197F9089566D092
+:1006B00008F48FEF08950BD0A9CF9ADF28F09FDFC1
+:1006C00018F0952309F062CF90CF1124EACFAFDF65
+:1006D000A0F3959FD1F3950F50E0551F629FF00155
+:1006E000729FBB27F00DB11D639FAA27F00DB11DAE
+:1006F000AA1F649F6627B00DA11D661F829F222737
+:10070000B00DA11D621F739FB00DA11D621F839FBD
+:10071000A00D611D221F749F3327A00D611D231F93
+:10072000849F600D211D822F762F6A2F11249F57E1
+:1007300050408AF0E1F088234AF0EE0FFF1FBB1F04
+:10074000661F771F881F91505040A9F79E3F5105A3
+:1007500070F01CCFA6CF5F3FECF3983EDCF386959C
+:1007600077956795B795F795E7959F5FC1F7FE2B4E
+:10077000880F911D9695879597F90895990F000810
+:10078000550FAA0BE0E8FEEF16161706E807F90763
+:10079000C0F012161306E407F50798F0621B730BFE
+:1007A000840B950B39F40A2661F0232B242B252B7F
+:1007B00021F408950A2609F4A140A6958FEF811D22
+:0807C000811D0895F894FFCF9C
+:1007C8000000000000006F12033B00000000000062
+:00000001FF
diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/led/led_green_blink.sh b/OpenModelica_Arduino_With_MDD/MDD_build/led/led_green_blink.sh new file mode 100644 index 0000000..a30543c --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/led/led_green_blink.sh @@ -0,0 +1,61 @@ +#!/bin/bash +clear +if [ "$#" -ne 2 ]; then + echo "Usage: $0 port baudrate" >&2 + exit 1 +fi + +re='^[0-9]+$' +if ! [[ $1 =~ $re ]] ; then + echo "error: $1 -> Not a number" >&2; exit 1 +fi + +if ! [[ $2 =~ $re ]] ; then + echo "error: $2-> Not a number" >&2; exit 1 +fi + +b_rate=$2 + +present=`pwd` +unamestr=`uname` + +if [[ "$unamestr" == 'Linux' ]]; then + mdd_path=($(locate Modelica_DeviceDrivers/Modelica_DeviceDrivers/Resources/Include)) + om_path=($(locate /usr/include/omc/c)) + port="/dev/ttyACM$1" + omc --simCodeTarget=ExperimentalEmbeddedC runMDD_led_green_blink.mos + if [ $? -ne 0 ]; then + exit 1 + fi +else + cd c: + om_path=($(dir -d OpenModelica*/include/omc/c/)) + path_to_om="C:$om_path" + cd f: + mdd_path=($(dir -d */Modelica_DeviceDrivers/Modelica_DeviceDrivers/Resources/Include/)) + if [ $? -eq 0 ]; then + path_to_mdd="F:/$mdd_path" + else + exit 1 + fi + + port="COM$1" + cd $present + omc --simCodeTarget=ExperimentalEmbeddedC run_led_green_blink.mos + if [ $? -ne 0 ]; then + exit 1 + fi +fi + +avr-gcc -Os -std=c11 -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000UL -Wl,--gc-sections led_green_blink_main.c -o led_green_blink -I${mdd_path[0]} -I${path_to_om} -I${path_to_mdd} -I${om_path[0]} +if [ $? -ne 0 ]; then + exit 1 +fi +avr-objcopy -O ihex -R .eeprom led_green_blink led_green_blink.hex +if [ $? -ne 0 ]; then + exit 1 +fi +avrdude -F -V -c arduino -p ATMEGA328P -P $port -b $b_rate -U flash:w:led_green_blink.hex +if [ $? -ne 0 ]; then + exit 1 +fi
\ No newline at end of file diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/led/led_green_blink_main.c b/OpenModelica_Arduino_With_MDD/MDD_build/led/led_green_blink_main.c new file mode 100644 index 0000000..5999083 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/led/led_green_blink_main.c @@ -0,0 +1,212 @@ +#define fmi2TypesPlatform_h + +#define fmi2TypesPlatform "default" /* Compatible */ + +typedef struct led_green_blink_fmi2Component_s* fmi2Component; +typedef void* fmi2ComponentEnvironment; /* Pointer to FMU environment */ +typedef void* fmi2FMUstate; /* Pointer to internal FMU state */ +typedef unsigned int fmi2ValueReference; +typedef double fmi2Real; +typedef int fmi2Integer; +typedef int fmi2Boolean; +typedef char fmi2Char; +typedef const fmi2Char* fmi2String; +typedef char fmi2Byte; + +#define fmi2True 1 +#define fmi2False 0 + +#include "fmi2/fmi2Functions.h" + +#include <stdint.h> +#include <stdio.h> + +void ModelicaFormatMessage(const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + vprintf(fmt, args); + va_end(args); +} + +typedef struct led_green_blink_fmi2Component_s { + fmi2Real currentTime; + fmi2Boolean fmi2BooleanVars[1]; + fmi2Real fmi2RealParameter[1]; + void* extObjs[3]; +} led_green_blink_fmi2Component; + +led_green_blink_fmi2Component led_green_blink_component = { + .fmi2BooleanVars = { + fmi2False /*booleanExpression1._y*/, + }, + .fmi2RealParameter = { + 0.002 /*synchronizeRealtime1._actualInterval*/, + }, +}; + +#include <math.h> +/* TODO: Generate used builtin functions before SimCode */ +static inline double om_mod(double x, double y) +{ + return x-floor(x/y)*y; +} + +#include "MDDAVRTimer.h" +#include "MDDAVRRealTime.h" +#include "MDDAVRDigital.h" + +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(fmi2Component comp, void* om_port, fmi2Integer om_pin, fmi2Boolean om_value); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_destructor(fmi2Component comp, void* om_digital); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer); + +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(fmi2Component comp, void* om_port, fmi2Integer om_pin, fmi2Boolean om_value) +{ + MDD_avr_digital_pin_write(om_port, om_pin, om_value); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin) +{ + void* om_dig; + om_dig = MDD_avr_digital_pin_init(om_port, om_pin, fmi2True); + return om_dig; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_destructor(fmi2Component comp, void* om_digital) +{ + MDD_avr_digital_pin_close(om_digital); +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt) +{ + MDD_avr_rt_wait(om_rt); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle) +{ + void* om_rt; + om_rt = MDD_avr_rt_init(om_timer, om_timerValue, om_numTimerInterruptsPerCycle); + return om_rt; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt) +{ + MDD_avr_rt_close(om_rt); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch) +{ + void* om_timer; + om_timer = MDD_avr_timer_init(om_timerSelect, om_clockSelect, om_clearTimerOnMatch); + return om_timer; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer) +{ + MDD_avr_timer_close(om_timer); +} + +fmi2Component led_green_blink_fmi2Instantiate(fmi2String name, fmi2Type ty, fmi2String GUID, fmi2String resources, const fmi2CallbackFunctions* functions, fmi2Boolean visible, fmi2Boolean loggingOn) +{ + static int initDone=0; + if (initDone) { + return NULL; + } + return &led_green_blink_component; +} + +fmi2Status led_green_blink_fmi2SetupExperiment(fmi2Component comp, fmi2Boolean toleranceDefined, fmi2Real tolerance, fmi2Real startTime, fmi2Boolean stopTimeDefined, fmi2Real stopTime) +{ + return fmi2OK; +} + +fmi2Status led_green_blink_fmi2EnterInitializationMode(fmi2Component comp) +{ + comp->extObjs[1] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(comp, 1, 4, fmi2False); + comp->extObjs[2] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(comp, comp->extObjs[1] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */, 249, 2); + comp->extObjs[0] /* digitalWriteBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(comp, 2, 2); + return fmi2OK; +} + +fmi2Status led_green_blink_fmi2ExitInitializationMode(fmi2Component comp) +{ + return fmi2OK; +} + +static fmi2Status led_green_blink_functionODE(fmi2Component comp) +{ +} + +static fmi2Status led_green_blink_functionOutputs(fmi2Component comp) +{ + comp->fmi2BooleanVars[0] /* booleanExpression1._y DISCRETE */ = (om_mod(comp->currentTime,0.2))>=(0.1); /* equation 3 */Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(comp, comp->extObjs[2] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */);Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(comp, comp->extObjs[0] /* digitalWriteBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */, 2, comp->fmi2BooleanVars[0] /* booleanExpression1._y DISCRETE */); +} + +fmi2Status led_green_blink_fmi2DoStep(fmi2Component comp, fmi2Real currentCommunicationPoint, fmi2Real communicationStepSize, fmi2Boolean noSetFMUStatePriorToCurrentPoint) +{ + comp->currentTime = currentCommunicationPoint; + /* TODO: Calculate time/state-dependent variables here... */ + led_green_blink_functionOutputs(comp); + return fmi2OK; +} + +int main(int argc, char **argv) +{ + int terminateSimulation = 0; + fmi2Status status = fmi2OK; + fmi2CallbackFunctions cbf = { + .logger = NULL, + .allocateMemory = NULL /*calloc*/, + .freeMemory = NULL /*free*/, + .stepFinished = NULL, //synchronous execution + .componentEnvironment = NULL + }; + + fmi2Component comp = led_green_blink_fmi2Instantiate("", fmi2CoSimulation, "", "", &cbf, fmi2False, fmi2False); + if (comp==NULL) { + return 1; + } + led_green_blink_fmi2SetupExperiment(comp, fmi2False, 0.0, 0.0, fmi2False, 1.0); + led_green_blink_fmi2EnterInitializationMode(comp); + // Set start-values? Nah... + led_green_blink_fmi2ExitInitializationMode(comp); + + double currentTime = 0.0; + double h = 0.002; + uint32_t i = 0; + + while (status == fmi2OK) { + //retrieve outputs + // fmi2GetReal(m, ..., 1, &y1); + //set inputs + // fmi2SetReal(m, ..., 1, &y2); + + //call slave and check status + status = led_green_blink_fmi2DoStep(comp, currentTime, h, fmi2True); + switch (status) { + case fmi2Discard: + case fmi2Error: + case fmi2Fatal: + case fmi2Pending /* Cannot happen */: + terminateSimulation = 1; + break; + case fmi2OK: + case fmi2Warning: + break; + } + if (terminateSimulation) { + break; + } + i++; + /* increment master time */ + currentTime = 0.0 + h*i; + } + +#if 0 + if ((status != fmi2Error) && (status != fmi2Fatal)) { + fmi2Terminate(m); + } + if (status != fmi2Fatal) { + fmi2FreeInstance(m); + } +#endif +} + diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/led/runMDD_led_blink.mos b/OpenModelica_Arduino_With_MDD/MDD_build/led/runMDD_led_blink.mos new file mode 100644 index 0000000..53c008c --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/led/runMDD_led_blink.mos @@ -0,0 +1,11 @@ +loadModel(Modelica); +getErrorString(); + +loadFile("/home/sumeet/Modelica_DeviceDrivers/package.mo"); +getErrorString(); + +loadFile("/home/sumeet/MDD_Arduino/linux-version-4/OpenModelica-Arduino-MDD_Arduino_Revised/Arduino.mo"); +getErrorString(); + +translateModel(Arduino.SerialCommunication.MDD_Examples.MDD_led.MDD_led_blink, fileNamePrefix="led_blink"); +getErrorString(); diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/led/runMDD_led_blink.mos~ b/OpenModelica_Arduino_With_MDD/MDD_build/led/runMDD_led_blink.mos~ new file mode 100644 index 0000000..1e58f73 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/led/runMDD_led_blink.mos~ @@ -0,0 +1,11 @@ +loadModel(Modelica); +getErrorString(); + +loadFile("/home/souradip/Modelica_DeviceDrivers/Modelica_DeviceDrivers/package.mo"); +getErrorString(); + +loadFile("/home/sumeet/MDD_Arduino/linux-version-4/OpenModelica-Arduino-MDD_Arduino_Revised/Arduino.mo"); +getErrorString(); + +translateModel(Arduino.SerialCommunication.MDD_Examples.MDD_led.MDD_led_blink, fileNamePrefix="led_blink"); +getErrorString(); diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/led/runMDD_led_blue.mos b/OpenModelica_Arduino_With_MDD/MDD_build/led/runMDD_led_blue.mos new file mode 100644 index 0000000..b845042 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/led/runMDD_led_blue.mos @@ -0,0 +1,11 @@ +loadModel(Modelica); +getErrorString(); + +loadFile("/home/manas/Documents/OpenModelica-HIL/ModelPlugin-openmodelica/OpenModelicaEmbedded/Modelica_DeviceDrivers/package.mo"); +getErrorString(); + +loadFile("/home/manas/Documents/OpenModelica-HIL/ModelPlugin-openmodelica/OpenModelicaEmbedded/OpenModelica-Arduino-MDD_Arduino_Revised/Arduino.mo"); +getErrorString(); + +translateModel(Arduino.SerialCommunication.MDD_Examples.MDD_led.MDD_led_blue, fileNamePrefix="led_blue"); +getErrorString(); diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/led/runMDD_led_blue.mos~ b/OpenModelica_Arduino_With_MDD/MDD_build/led/runMDD_led_blue.mos~ new file mode 100644 index 0000000..d931832 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/led/runMDD_led_blue.mos~ @@ -0,0 +1,11 @@ +loadModel(Modelica); +getErrorString(); + +loadFile("/home/sumeet/Modelica_DeviceDrivers/package.mo"); +getErrorString(); + +loadFile("/home/sumeet/MDD_Arduino/linux-version-4/OpenModelica-Arduino-MDD_Arduino_Revised/Arduino.mo"); +getErrorString(); + +translateModel(Arduino.SerialCommunication.MDD_Examples.MDD_led.MDD_led_blue, fileNamePrefix="led_blue"); +getErrorString(); diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/led/runMDD_led_blue_delay.mos b/OpenModelica_Arduino_With_MDD/MDD_build/led/runMDD_led_blue_delay.mos new file mode 100644 index 0000000..62b9250 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/led/runMDD_led_blue_delay.mos @@ -0,0 +1,11 @@ +loadModel(Modelica); +getErrorString(); + +loadFile("/home/souradip/Modelica_DeviceDrivers/Modelica_DeviceDrivers/package.mo"); +getErrorString(); + +loadFile("/home/souradip/OpenModelica/Arduino.mo"); +getErrorString(); + +translateModel(Arduino.SerialCommunication.MDD_Examples.MDD_led.MDD_led_blue_delay, fileNamePrefix="led_blue_delay"); +getErrorString(); diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/led/runMDD_led_blue_red.mos b/OpenModelica_Arduino_With_MDD/MDD_build/led/runMDD_led_blue_red.mos new file mode 100644 index 0000000..f60dfc6 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/led/runMDD_led_blue_red.mos @@ -0,0 +1,11 @@ +loadModel(Modelica); +getErrorString(); + +loadFile("/home/souradip/Modelica_DeviceDrivers/Modelica_DeviceDrivers/package.mo"); +getErrorString(); + +loadFile("/home/souradip/OpenModelica/Arduino.mo"); +getErrorString(); + +translateModel(Arduino.SerialCommunication.MDD_Examples.MDD_led.MDD_led_blue_red, fileNamePrefix="led_blue_red"); +getErrorString(); diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/led/runMDD_led_green_blink.mos b/OpenModelica_Arduino_With_MDD/MDD_build/led/runMDD_led_green_blink.mos new file mode 100644 index 0000000..eeb79c1 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/led/runMDD_led_green_blink.mos @@ -0,0 +1,11 @@ +loadModel(Modelica); +getErrorString(); + +loadFile("/home/souradip/Modelica_DeviceDrivers/Modelica_DeviceDrivers/package.mo"); +getErrorString(); + +loadFile("/home/souradip/OpenModelica/Arduino.mo"); +getErrorString(); + +translateModel(Arduino.SerialCommunication.MDD_Examples.MDD_led.MDD_led_green_blink, fileNamePrefix="led_green_blink"); +getErrorString(); diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/led/runMDD_traffic_light.mos b/OpenModelica_Arduino_With_MDD/MDD_build/led/runMDD_traffic_light.mos new file mode 100644 index 0000000..a793656 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/led/runMDD_traffic_light.mos @@ -0,0 +1,13 @@ +loadModel(Modelica); +getErrorString(); + +loadFile("/home/manas/Documents/OpenModelica-HIL/ModelPlugin-openmodelica/OpenModelicaEmbedded/Modelica_DeviceDrivers/package.mo"); +getErrorString(); + +loadFile("/home/manas/Documents/OpenModelica-HIL/ModelPlugin-openmodelica/OpenModelicaEmbedded/OpenModelica-Arduino-MDD_Arduino_Revised/Arduino.mo"); + +getErrorString(); + +translateModel(Arduino.SerialCommunication.MDD_Examples.MDD_led.MDD_traffic_light, fileNamePrefix="traffic_light"); + +getErrorString(); diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/led/runMDD_traffic_light.mos~ b/OpenModelica_Arduino_With_MDD/MDD_build/led/runMDD_traffic_light.mos~ new file mode 100644 index 0000000..7c13575 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/led/runMDD_traffic_light.mos~ @@ -0,0 +1,13 @@ +loadModel(Modelica); +getErrorString(); + +loadFile("/home/manas/Documents/OpenModelica-HIL/ModelPlugin-openmodelica/OpenModelicaEmbedded/Modelica_DeviceDrivers/package.mo"); +getErrorString(); + +loadFile("/home/manas/Documents/OpenModelica-HIL/ModelPlugin-openmodelica/OpenModelicaEmbedded/OpenModelica-Arduino-MDD_Arduino_Revised/Arduino.mo"); + +getErrorString(); + +translateModel(Arduino.SerialCommunication.MDD_Examples.MDD_led.MDD_led_blue, fileNamePrefix="traffic_light"); + +getErrorString(); diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/led/traffic_light b/OpenModelica_Arduino_With_MDD/MDD_build/led/traffic_light Binary files differnew file mode 100755 index 0000000..9264466 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/led/traffic_light diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/led/traffic_light_main.c b/OpenModelica_Arduino_With_MDD/MDD_build/led/traffic_light_main.c new file mode 100644 index 0000000..9577e23 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/led/traffic_light_main.c @@ -0,0 +1,212 @@ +#define fmi2TypesPlatform_h + +#define fmi2TypesPlatform "default" /* Compatible */ + +typedef struct traffic_light_fmi2Component_s* fmi2Component; +typedef void* fmi2ComponentEnvironment; /* Pointer to FMU environment */ +typedef void* fmi2FMUstate; /* Pointer to internal FMU state */ +typedef unsigned int fmi2ValueReference; +typedef double fmi2Real; +typedef int fmi2Integer; +typedef int fmi2Boolean; +typedef char fmi2Char; +typedef const fmi2Char* fmi2String; +typedef char fmi2Byte; + +#define fmi2True 1 +#define fmi2False 0 + +#include "fmi2/fmi2Functions.h" + +#include <stdint.h> +#include <stdio.h> + +void ModelicaFormatMessage(const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + vprintf(fmt, args); + va_end(args); +} + +typedef struct traffic_light_fmi2Component_s { + fmi2Real currentTime; + fmi2Boolean fmi2BooleanVars[1]; + fmi2Real fmi2RealParameter[1]; + void* extObjs[3]; +} traffic_light_fmi2Component; + +traffic_light_fmi2Component traffic_light_component = { + .fmi2BooleanVars = { + fmi2False /*booleanExpression1._y*/, + }, + .fmi2RealParameter = { + 0.002 /*synchronizeRealtime1._actualInterval*/, + }, +}; + +#include <math.h> +/* TODO: Generate used builtin functions before SimCode */ +static inline double om_mod(double x, double y) +{ + return x-floor(x/y)*y; +} + +#include "MDDAVRTimer.h" +#include "MDDAVRRealTime.h" +#include "MDDAVRDigital.h" + +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(fmi2Component comp, void* om_port, fmi2Integer om_pin, fmi2Boolean om_value); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_destructor(fmi2Component comp, void* om_digital); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer); + +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(fmi2Component comp, void* om_port, fmi2Integer om_pin, fmi2Boolean om_value) +{ + MDD_avr_digital_pin_write(om_port, om_pin, om_value); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin) +{ + void* om_dig; + om_dig = MDD_avr_digital_pin_init(om_port, om_pin, fmi2True); + return om_dig; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_destructor(fmi2Component comp, void* om_digital) +{ + MDD_avr_digital_pin_close(om_digital); +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt) +{ + MDD_avr_rt_wait(om_rt); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle) +{ + void* om_rt; + om_rt = MDD_avr_rt_init(om_timer, om_timerValue, om_numTimerInterruptsPerCycle); + return om_rt; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt) +{ + MDD_avr_rt_close(om_rt); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch) +{ + void* om_timer; + om_timer = MDD_avr_timer_init(om_timerSelect, om_clockSelect, om_clearTimerOnMatch); + return om_timer; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer) +{ + MDD_avr_timer_close(om_timer); +} + +fmi2Component traffic_light_fmi2Instantiate(fmi2String name, fmi2Type ty, fmi2String GUID, fmi2String resources, const fmi2CallbackFunctions* functions, fmi2Boolean visible, fmi2Boolean loggingOn) +{ + static int initDone=0; + if (initDone) { + return NULL; + } + return &traffic_light_component; +} + +fmi2Status traffic_light_fmi2SetupExperiment(fmi2Component comp, fmi2Boolean toleranceDefined, fmi2Real tolerance, fmi2Real startTime, fmi2Boolean stopTimeDefined, fmi2Real stopTime) +{ + return fmi2OK; +} + +fmi2Status traffic_light_fmi2EnterInitializationMode(fmi2Component comp) +{ + comp->extObjs[0] /* digitalWriteBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(comp, 1, 5); + comp->extObjs[1] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(comp, 2, 4, fmi2False); + comp->extObjs[2] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(comp, comp->extObjs[1] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */, 249, 1); + return fmi2OK; +} + +fmi2Status traffic_light_fmi2ExitInitializationMode(fmi2Component comp) +{ + return fmi2OK; +} + +static fmi2Status traffic_light_functionODE(fmi2Component comp) +{ +} + +static fmi2Status traffic_light_functionOutputs(fmi2Component comp) +{ + Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(comp, comp->extObjs[2] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */);Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(comp, comp->extObjs[0] /* digitalWriteBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */, 5, fmi2True); +} + +fmi2Status traffic_light_fmi2DoStep(fmi2Component comp, fmi2Real currentCommunicationPoint, fmi2Real communicationStepSize, fmi2Boolean noSetFMUStatePriorToCurrentPoint) +{ + comp->currentTime = currentCommunicationPoint; + /* TODO: Calculate time/state-dependent variables here... */ + traffic_light_functionOutputs(comp); + return fmi2OK; +} + +int main(int argc, char **argv) +{ + int terminateSimulation = 0; + fmi2Status status = fmi2OK; + fmi2CallbackFunctions cbf = { + .logger = NULL, + .allocateMemory = NULL /*calloc*/, + .freeMemory = NULL /*free*/, + .stepFinished = NULL, //synchronous execution + .componentEnvironment = NULL + }; + + fmi2Component comp = traffic_light_fmi2Instantiate("", fmi2CoSimulation, "", "", &cbf, fmi2False, fmi2False); + if (comp==NULL) { + return 1; + } + traffic_light_fmi2SetupExperiment(comp, fmi2False, 0.0, 0.0, fmi2False, 1.0); + traffic_light_fmi2EnterInitializationMode(comp); + // Set start-values? Nah... + traffic_light_fmi2ExitInitializationMode(comp); + + double currentTime = 0.0; + double h = 0.002; + uint32_t i = 0; + + while (status == fmi2OK) { + //retrieve outputs + // fmi2GetReal(m, ..., 1, &y1); + //set inputs + // fmi2SetReal(m, ..., 1, &y2); + + //call slave and check status + status = traffic_light_fmi2DoStep(comp, currentTime, h, fmi2True); + switch (status) { + case fmi2Discard: + case fmi2Error: + case fmi2Fatal: + case fmi2Pending /* Cannot happen */: + terminateSimulation = 1; + break; + case fmi2OK: + case fmi2Warning: + break; + } + if (terminateSimulation) { + break; + } + i++; + /* increment master time */ + currentTime = 0.0 + h*i; + } + +#if 0 + if ((status != fmi2Error) && (status != fmi2Fatal)) { + fmi2Terminate(m); + } + if (status != fmi2Fatal) { + fmi2FreeInstance(m); + } +#endif +} + diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/pot/pot_threshold b/OpenModelica_Arduino_With_MDD/MDD_build/pot/pot_threshold Binary files differnew file mode 100644 index 0000000..3a53c95 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/pot/pot_threshold diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/pot/pot_threshold.hex b/OpenModelica_Arduino_With_MDD/MDD_build/pot/pot_threshold.hex new file mode 100644 index 0000000..4c24433 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/pot/pot_threshold.hex @@ -0,0 +1,157 @@ +:100000000C9434000C9451000C9451000C94510049
+:100010000C9451000C9451000C9451000C94170254
+:100020000C9451000C9451000C9451000C94E60176
+:100030000C9451000C9451000C94B5010C94510097
+:100040000C9451000C9451000C9451000C945100EC
+:100050000C9451000C9451000C9451000C945100DC
+:100060000C9451000C94510011241FBECFEFD8E026
+:10007000DEBFCDBF11E0A0E0B1E0EAE5F9E002C0EB
+:1000800005900D92A235B107D9F711E0A2E5B1E0D4
+:1000900001C01D92A735B107E1F70E9488020C94B8
+:1000A000AB040C94000080917C00857E826080937C
+:1000B0007C0080917A00806480937A0080917A003D
+:1000C00086FDFCCF809178009091790008954F9241
+:1000D0005F926F927F928F929F92AF92BF92CF92D8
+:1000E000DF92EF92FF920F931F93CF93DF938C01D8
+:1000F0000E94530060E080E090E00E949D040E9416
+:100100005300BC0180E090E00E94840320E030E0D6
+:1001100040E854E40E94160420E030EC4FE754E439
+:100120000E941C034B015C01D80114966D937D93D2
+:100130008D939C931797C1E0D0E0D4962D913D917B
+:100140004D915C91D7970E94120487FF02C0C0E0D6
+:10015000D0E0F801D3A7C2A7CD2B39F0412C512C08
+:1001600090E8692E9FE3792E03C0412C512C320177
+:10017000D8011C964D925D926D927C921F97C1E0C2
+:10018000D0E0D8962D913D914D915C91DB97C301C4
+:10019000B2010E94120487FF02C0C0E0D0E0F80163
+:1001A000D5A3C4A3C1E0D0E020A931A942A953A995
+:1001B000C501B4010E94120487FF02C0C0E0D0E074
+:1001C000D8019996DC93CE939897CD2B39F0C12C1A
+:1001D000D12C80E8E82E8FE3F82E03C0C12CD12C5F
+:1001E0007601F801C086D186E286F386C1E0D0E0D0
+:1001F000A3019201C701B6010E941204181614F05F
+:10020000C0E0D0E0D8019396DC93CE939297C1E002
+:10021000D0E09C962D913D914D915C919F97C501A9
+:10022000B4010E94120487FF02C0C0E0D0E0F801D0
+:10023000D7A3C6A3CD2B29F060E070E080E89FE350
+:1002400003C060E070E0CB01D80150966D937D93C0
+:100250008D939C935397C1E0D0E0A70196010E9433
+:100260001204181614F0C0E0D0E0F801D1A3C0A326
+:10027000E05BFF4F808191818230910561F0833096
+:10028000910599F00197C9F416BC80916E008260C7
+:1002900080936E0016C010928500109284008091A9
+:1002A0006F00826080936F000CC01092B20080914A
+:1002B000700082608093700004C081E090E00E9432
+:1002C000AB0478949FB7F894809154019FBF882322
+:1002D000C9F310925401F801E85BFF4F0190F081DF
+:1002E000E02DD80190968D919C919197892B19F0D2
+:1002F0008081826002C080818D7F8083F801E65B0F
+:10030000FF4F0190F081E02DD80192968D919C9144
+:100310009397892B19F08081846002C080818B7F44
+:100320008083F801E45BFF4F0190F081E02DD8015C
+:1003300094968D919C919597892B19F08081886076
+:1003400002C08081877F8083DF91CF911F910F91C1
+:10035000FF90EF90DF90CF90BF90AF909F908F90E5
+:100360007F906F905F904F9008951F920F920FB6FD
+:100370000F9211242F933F938F939F93809152015B
+:100380009091530101969093530180935201809173
+:100390005401813091F020915201309153018091AC
+:1003A0005501909156012817390738F081E0809364
+:1003B000540110925301109252019F918F913F91DD
+:1003C0002F910F900FBE0F901F9018951F920F92B4
+:1003D0000FB60F9211242F933F938F939F93809189
+:1003E00052019091530101969093530180935201D1
+:1003F00080915401813091F020915201309153014C
+:1004000080915501909156012817390738F081E005
+:100410008093540110925301109252019F918F9139
+:100420003F912F910F900FBE0F901F9018951F9224
+:100430000F920FB60F9211242F933F938F939F9398
+:1004400080915201909153010196909353018093B2
+:10045000520180915401813091F0209152013091EC
+:10046000530180915501909156012817390738F0B2
+:1004700081E08093540110925301109252019F9198
+:100480008F913F912F910F900FBE0F901F90189555
+:10049000ECE7F0E02081206C2083EAE7F0E02081A7
+:1004A00027682083FC01EA5BFF4F11821082239AA8
+:1004B000FC01E45BFF4F25E230E031832083229A88
+:1004C000FC01E65BFF4F31832083219AFC01E85B4E
+:1004D000FF4F3183208325B5236025BDFC01E25BFE
+:1004E000FF4F21E030E03183208342E050E0509321
+:1004F00056014093550144B5426044BD49EF47BDA4
+:10050000FC01E05BFF4F3183208380E090E00895A1
+:10051000CF92DF92EF92FF9280E091E00E9448023A
+:10052000C12CD12C760160E070E0CB01609300011A
+:1005300070930101809302019093030180E091E0A8
+:100540000E9467008FEFC81AD80AE80AF80AC701A4
+:10055000B6010E9484032FE632E143E05BE30E9490
+:10056000160420E030E0A9010E94B802DFCF505805
+:10057000BB27AA270ED01CC10DD130F012D120F01C
+:1005800031F49F3F11F41EF402C10EF4E095E7FB35
+:10059000F8C0E92F1ED180F3BA17620773078407EA
+:1005A000950718F071F49EF536C10EF4E0950B2E08
+:1005B000BA2FA02D0B01B90190010C01CA01A001B5
+:1005C0001124FF27591B99F0593F50F4503E68F110
+:1005D0001A16F040A22F232F342F4427585FF3CF51
+:1005E000469537952795A795F0405395C9F77EF422
+:1005F0001F16BA0B620B730B840BBAF09150A1F06B
+:10060000FF0FBB1F661F771F881FC2F70EC0BA0FF0
+:10061000621F731F841F48F4879577956795B79578
+:10062000F7959E3F08F0B3CF9395880F08F0992770
+:10063000EE0F9795879508950CD0BAC0B2D040F0D0
+:10064000A9D030F021F45F3F19F09BC05111E4C0F4
+:100650009EC0BFD098F39923C9F35523B1F3951BDE
+:10066000550BBB27AA2762177307840738F09F5FD3
+:100670005F4F220F331F441FAA1FA9F333D00E2E42
+:100680003AF0E0E830D091505040E695001CCAF7AF
+:1006900029D0FE2F27D0660F771F881FBB1F261774
+:1006A00037074807AB07B0E809F0BB0B802DBF0147
+:1006B000FF2793585F4F2AF09E3F510568F061C0B5
+:1006C000ABC05F3FECF3983EDCF38695779567957A
+:1006D000B795F7959F5FC9F7880F911D96958795F8
+:1006E00097F90895E1E0660F771F881FBB1F621717
+:1006F00073078407BA0720F0621B730B840BBA0BD5
+:10070000EE1F88F7E0950895E89409C097FB3EF442
+:1007100090958095709561957F4F8F4F9F4F99234E
+:10072000A9F0F92F96E9BB279395F69587957795CC
+:100730006795B795F111F8CFFAF4BB0F11F460FF8C
+:100740001BC06F5F7F4F8F4F9F4F16C0882311F0E4
+:1007500096E911C0772321F09EE8872F762F05C0F8
+:10076000662371F096E8862F70E060E02AF09A9593
+:10077000660F771F881FDAF7880F9695879597F988
+:10078000089597F99F6780E870E060E008959FEF13
+:1007900080EC089500240A94161617061806090618
+:1007A000089500240A9412161306140605060895E7
+:1007B000092E0394000C11F4882352F0BB0F40F46F
+:1007C000BF2B11F460FF04C06F5F7F4F8F4F9F4FAF
+:1007D000089557FD9058440F551F59F05F3F71F031
+:1007E0004795880F97FB991F61F09F3F79F0879598
+:1007F0000895121613061406551FF2CF4695F1DF21
+:1008000008C0161617061806991FF1CF86957105B0
+:10081000610508940895E894BB2766277727CB01E4
+:1008200097F9089566D008F48FEF08950BD0C0CFE4
+:10083000B1DF28F0B6DF18F0952309F0A2CFA7CFDB
+:100840001124EACFC6DFA0F3959FD1F3950F50E0B6
+:10085000551F629FF001729FBB27F00DB11D639F72
+:10086000AA27F00DB11DAA1F649F6627B00DA11D18
+:10087000661F829F2227B00DA11D621F739FB00DBE
+:10088000A11D621F839FA00D611D221F749F33272E
+:10089000A00D611D231F849F600D211D822F762FC7
+:1008A0006A2F11249F5750408AF0E1F088234AF0C4
+:1008B000EE0FFF1FBB1F661F771F881F9150504010
+:1008C000A9F79E3F510570F05CCFA6CF5F3FECF3D8
+:1008D000983EDCF3869577956795B795F795E795FC
+:1008E0009F5FC1F7FE2B880F911D9695879597F90D
+:1008F0000895990F0008550FAA0BE0E8FEEF1616B1
+:100900001706E807F907C0F012161306E407F50703
+:1009100098F0621B730B840B950B39F40A2661F077
+:10092000232B242B252B21F408950A2609F4A1401A
+:10093000A6958FEF811D811D0895262FF999FECF71
+:100940001FBA92BD81BD20BD0FB6F894FA9AF99AEC
+:0A0950000FBE01960895F894FFCF42
+:10095A00000000000000000000000000000000008D
+:10096A00000000000000000000000000000000007D
+:10097A00000000000000000000000000000000006D
+:10098A000000A043000061440000003F6F12033BD7
+:10099A000500010000000000000000000000000047
+:0209AA0000004B
+:00000001FF
diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/pot/pot_threshold.sh b/OpenModelica_Arduino_With_MDD/MDD_build/pot/pot_threshold.sh new file mode 100644 index 0000000..515d97e --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/pot/pot_threshold.sh @@ -0,0 +1,61 @@ +#!/bin/bash +clear +if [ "$#" -ne 2 ]; then + echo "Usage: $0 port baudrate" >&2 + exit 1 +fi + +re='^[0-9]+$' +if ! [[ $1 =~ $re ]] ; then + echo "error: $1 -> Not a number" >&2; exit 1 +fi + +if ! [[ $2 =~ $re ]] ; then + echo "error: $2-> Not a number" >&2; exit 1 +fi + +b_rate=$2 + +present=`pwd` +unamestr=`uname` + +if [[ "$unamestr" == 'Linux' ]]; then + mdd_path=($(locate Modelica_DeviceDrivers/Resources/Include)) + om_path=($(locate /usr/include/omc/c)) + port="/dev/ttyACM$1" + omc --simCodeTarget=ExperimentalEmbeddedC runMDD_pot_threshold.mos + if [ $? -ne 0 ]; then + exit 1 + fi +else + cd c: + om_path=($(dir -d OpenModelica*/include/omc/c/)) + path_to_om="C:$om_path" + cd f: + mdd_path=($(dir -d */Modelica_DeviceDrivers/Modelica_DeviceDrivers/Resources/Include/)) + if [ $? -eq 0 ]; then + path_to_mdd="F:/$mdd_path" + else + exit 1 + fi + + port="COM$1" + cd $present + omc --simCodeTarget=ExperimentalEmbeddedC run_pot_threshold.mos + if [ $? -ne 0 ]; then + exit 1 + fi +fi + +avr-gcc -Os -std=c11 -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000UL -Wl,--gc-sections pot_threshold_main.c -o pot_threshold -I${mdd_path[0]} -I${path_to_om} -I${path_to_mdd} -I${om_path[0]} +if [ $? -ne 0 ]; then + exit 1 +fi +avr-objcopy -O ihex -R .eeprom pot_threshold pot_threshold.hex +if [ $? -ne 0 ]; then + exit 1 +fi +avrdude -F -V -c arduino -p ATMEGA328P -P $port -b $b_rate -U flash:w:pot_threshold.hex +if [ $? -ne 0 ]; then + exit 1 +fi diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/pot/pot_threshold.sh~ b/OpenModelica_Arduino_With_MDD/MDD_build/pot/pot_threshold.sh~ new file mode 100644 index 0000000..f669595 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/pot/pot_threshold.sh~ @@ -0,0 +1,63 @@ +#!/bin/bash +clear +if [ "$#" -ne 2 ]; then + echo "Usage: $0 port baudrate" >&2 + exit 1 +fi + +re='^[0-9]+$' +if ! [[ $1 =~ $re ]] ; then + echo "error: $1 -> Not a number" >&2; exit 1 +fi + +if ! [[ $2 =~ $re ]] ; then + echo "error: $2-> Not a number" >&2; exit 1 +fi + +b_rate=$2 + +present=`pwd` +unamestr=`uname` + +if [[ "$unamestr" == 'Linux' ]]; then + mdd_path=($(locate Modelica_DeviceDrivers/Resources/Include)) + om_path=($(locate /usr/include/omc/c)) + port="/dev/ttyACM$1" + omc --simCodeTarget=ExperimentalEmbeddedC runMDD_pot_threshold.mos + if [ $? -ne 0 ]; then + exit 1 + fi +else + cd c: + om_path=($(dir -d OpenModelica*/include/omc/c/)) + path_to_om="C:$om_path" + cd f: + mdd_path=($(dir -d */Modelica_DeviceDrivers/Modelica_DeviceDrivers/Resources/Include/)) + if [ $? -eq 0 ]; then + path_to_mdd="F:/$mdd_path" + else + exit 1 + fi + + port="COM$1" + cd $present + omc --simCodeTarget=ExperimentalEmbeddedC run_pot_threshold.mos + if [ $? -ne 0 ]; then + exit 1 + fi +fi + +avr-gcc -Os -std=c11 -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000UL -Wl,--gc-sections pot_threshold_main.c -o pot_threshold -I${mdd_path[0]} -I${path_to_om} -I${path_to_mdd} -I${om_path[0]} +if [ $? -ne 0 ]; then + exit 1 +fi +avr-objcopy -O ihex -R .eeprom pot_threshold pot_threshold.hex +if [ $? -ne 0 ]; then + exit 1 +fi +avrdude -F -V -c arduino -p ATMEGA328P -P $port -b $b_rate -U flash:w:pot_threshold.hex +if [ $? -ne 0 ]; then + exit 1 +fi + +plot(y) diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/pot/pot_threshold_main.c b/OpenModelica_Arduino_With_MDD/MDD_build/pot/pot_threshold_main.c new file mode 100644 index 0000000..2e867ec --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/pot/pot_threshold_main.c @@ -0,0 +1,274 @@ +#define fmi2TypesPlatform_h + +#define fmi2TypesPlatform "default" /* Compatible */ + +typedef struct pot_threshold_fmi2Component_s* fmi2Component; +typedef void* fmi2ComponentEnvironment; /* Pointer to FMU environment */ +typedef void* fmi2FMUstate; /* Pointer to internal FMU state */ +typedef unsigned int fmi2ValueReference; +typedef double fmi2Real; +typedef int fmi2Integer; +typedef int fmi2Boolean; +typedef char fmi2Char; +typedef const fmi2Char* fmi2String; +typedef char fmi2Byte; + +#define fmi2True 1 +#define fmi2False 0 + +#include "fmi2/fmi2Functions.h" + +#include <stdint.h> +#include <stdio.h> + +void ModelicaFormatMessage(const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + vprintf(fmt, args); + va_end(args); +} + +typedef struct pot_threshold_fmi2Component_s { + fmi2Real currentTime; + fmi2Real fmi2RealVars[7]; + fmi2Boolean fmi2BooleanVars[6]; + fmi2Real fmi2RealParameter[5]; + fmi2Integer fmi2IntegerParameter[1]; + fmi2Boolean fmi2BooleanParameter[1]; + fmi2String fmi2StringParameter[1]; + void* extObjs[6]; +} pot_threshold_fmi2Component; + +pot_threshold_fmi2Component pot_threshold_component = { + .fmi2RealVars = { + 0.0 /*adc._y*/, + 0.0 /*greater1._u1*/, + 0.0 /*greater1._u2*/, + 0.0 /*greater2._u1*/, + 0.0 /*realExpression1._y*/, + 0.0 /*realExpression2._y*/, + 0.0 /*realValue1._number*/, + }, + .fmi2BooleanVars = { + fmi2False /*digitalWriteBoolean1._u*/, + fmi2False /*digitalWriteBoolean2._u*/, + fmi2False /*digitalWriteBoolean3._u*/, + fmi2False /*greaterEqualThreshold1._y*/, + fmi2False /*greaterEqualThreshold2._y*/, + fmi2False /*greaterEqualThreshold3._y*/, + }, + .fmi2RealParameter = { + 0.0 /*greaterEqualThreshold1._threshold*/, + 320.0 /*greaterEqualThreshold2._threshold*/, + 900.0 /*greaterEqualThreshold3._threshold*/, + 0.5 /*realToBoolean1._threshold*/, + 0.002 /*synchronizeRealtime1._actualInterval*/, + }, + .fmi2IntegerParameter = { + 5 /*realValue1._significantDigits*/, + }, + .fmi2BooleanParameter = { + fmi2True /*realValue1._use_numberPort*/, + }, +}; + +#include <math.h> +/* TODO: Generate used builtin functions before SimCode */ +static inline double om_mod(double x, double y) +{ + return x-floor(x/y)*y; +} + +static const char * const OMCLIT0 = "ElectricPotential"; +static const char * const OMCLIT1 = "V"; +#include "MDDAVRTimer.h" +#include "MDDAVRRealTime.h" +#include "MDDAVRDigital.h" +#include "MDDAVRAnalog.h" + +static inline fmi2Real Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_read__voltage(fmi2Component comp, fmi2Integer om_analogPort, fmi2Real om_vref, fmi2Integer om_voltageResolution); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_constructor(fmi2Component comp, fmi2Integer om_divisionFactor, fmi2Integer om_referenceVoltage); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_destructor(fmi2Component comp, void* om_avr); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(fmi2Component comp, void* om_port, fmi2Integer om_pin, fmi2Boolean om_value); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_destructor(fmi2Component comp, void* om_digital); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer); + +static inline fmi2Real Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_read__voltage(fmi2Component comp, fmi2Integer om_analogPort, fmi2Real om_vref, fmi2Integer om_voltageResolution) +{ + fmi2Real om_value; + om_value = MDD_avr_analog_read(om_analogPort, om_vref, om_voltageResolution); + return om_value; +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_constructor(fmi2Component comp, fmi2Integer om_divisionFactor, fmi2Integer om_referenceVoltage) +{ + void* om_avr; + om_avr = MDD_avr_analog_init(om_divisionFactor, om_referenceVoltage); + return om_avr; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_destructor(fmi2Component comp, void* om_avr) +{ + MDD_avr_analog_close(om_avr); +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(fmi2Component comp, void* om_port, fmi2Integer om_pin, fmi2Boolean om_value) +{ + MDD_avr_digital_pin_write(om_port, om_pin, om_value); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin) +{ + void* om_dig; + om_dig = MDD_avr_digital_pin_init(om_port, om_pin, fmi2True); + return om_dig; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_destructor(fmi2Component comp, void* om_digital) +{ + MDD_avr_digital_pin_close(om_digital); +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt) +{ + MDD_avr_rt_wait(om_rt); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle) +{ + void* om_rt; + om_rt = MDD_avr_rt_init(om_timer, om_timerValue, om_numTimerInterruptsPerCycle); + return om_rt; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt) +{ + MDD_avr_rt_close(om_rt); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch) +{ + void* om_timer; + om_timer = MDD_avr_timer_init(om_timerSelect, om_clockSelect, om_clearTimerOnMatch); + return om_timer; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer) +{ + MDD_avr_timer_close(om_timer); +} + +fmi2Component pot_threshold_fmi2Instantiate(fmi2String name, fmi2Type ty, fmi2String GUID, fmi2String resources, const fmi2CallbackFunctions* functions, fmi2Boolean visible, fmi2Boolean loggingOn) +{ + static int initDone=0; + if (initDone) { + return NULL; + } + return &pot_threshold_component; +} + +fmi2Status pot_threshold_fmi2SetupExperiment(fmi2Component comp, fmi2Boolean toleranceDefined, fmi2Real tolerance, fmi2Real startTime, fmi2Boolean stopTimeDefined, fmi2Real stopTime) +{ + return fmi2OK; +} + +fmi2Status pot_threshold_fmi2EnterInitializationMode(fmi2Component comp) +{ + comp->extObjs[0] /* adc._analog EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Analog.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_constructor(comp, 7, 4); + comp->extObjs[3] /* digitalWriteBoolean3._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(comp, 2, 4); + comp->extObjs[2] /* digitalWriteBoolean2._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(comp, 2, 3); + comp->extObjs[1] /* digitalWriteBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(comp, 2, 2); + comp->extObjs[4] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(comp, 1, 4, fmi2False); + comp->extObjs[5] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(comp, comp->extObjs[4] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */, 249, 2); + return fmi2OK; +} + +fmi2Status pot_threshold_fmi2ExitInitializationMode(fmi2Component comp) +{ + return fmi2OK; +} + +static fmi2Status pot_threshold_functionODE(fmi2Component comp) +{ +} + +static fmi2Status pot_threshold_functionOutputs(fmi2Component comp) +{ + comp->fmi2RealVars[0] /* adc._y variable */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_read__voltage(comp, 3, 1024.0, 10); /* equation 15 */ + comp->fmi2BooleanVars[5] /* greaterEqualThreshold3._y DISCRETE */ = (comp->fmi2RealVars[0] /* adc._y variable */)>=(comp->fmi2RealParameter[2] /* greaterEqualThreshold3._threshold PARAM */); /* equation 16 */ + comp->fmi2RealVars[2] /* greater1._u2 variable */ = (comp->fmi2BooleanVars[5] /* greaterEqualThreshold3._y DISCRETE */) ? (1.0) : (0.0); /* equation 17 */ + comp->fmi2BooleanVars[2] /* digitalWriteBoolean3._u DISCRETE */ = (comp->fmi2RealVars[2] /* greater1._u2 variable */)>=(comp->fmi2RealParameter[3] /* realToBoolean1._threshold PARAM */); /* equation 18 */ + comp->fmi2BooleanVars[4] /* greaterEqualThreshold2._y DISCRETE */ = (comp->fmi2RealVars[0] /* adc._y variable */)>=(comp->fmi2RealParameter[1] /* greaterEqualThreshold2._threshold PARAM */); /* equation 19 */ + comp->fmi2RealVars[1] /* greater1._u1 variable */ = (comp->fmi2BooleanVars[4] /* greaterEqualThreshold2._y DISCRETE */) ? (1.0) : (0.0); /* equation 20 */ + comp->fmi2BooleanVars[1] /* digitalWriteBoolean2._u DISCRETE */ = (comp->fmi2RealVars[1] /* greater1._u1 variable */)>(comp->fmi2RealVars[2] /* greater1._u2 variable */); /* equation 21 */ + comp->fmi2BooleanVars[3] /* greaterEqualThreshold1._y DISCRETE */ = (comp->fmi2RealVars[0] /* adc._y variable */)>=(comp->fmi2RealParameter[0] /* greaterEqualThreshold1._threshold PARAM */); /* equation 22 */ + comp->fmi2RealVars[3] /* greater2._u1 variable */ = (comp->fmi2BooleanVars[3] /* greaterEqualThreshold1._y DISCRETE */) ? (1.0) : (0.0); /* equation 23 */ + comp->fmi2BooleanVars[0] /* digitalWriteBoolean1._u DISCRETE */ = (comp->fmi2RealVars[3] /* greater2._u1 variable */)>(comp->fmi2RealVars[1] /* greater1._u1 variable */); /* equation 24 */Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(comp, comp->extObjs[5] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */);Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(comp, comp->extObjs[1] /* digitalWriteBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */, 2, comp->fmi2BooleanVars[0] /* digitalWriteBoolean1._u DISCRETE */);Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(comp, comp->extObjs[2] /* digitalWriteBoolean2._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */, 3, comp->fmi2BooleanVars[1] /* digitalWriteBoolean2._u DISCRETE */);Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(comp, comp->extObjs[3] /* digitalWriteBoolean3._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */, 4, comp->fmi2BooleanVars[2] /* digitalWriteBoolean3._u DISCRETE */); +} + +fmi2Status pot_threshold_fmi2DoStep(fmi2Component comp, fmi2Real currentCommunicationPoint, fmi2Real communicationStepSize, fmi2Boolean noSetFMUStatePriorToCurrentPoint) +{ + comp->currentTime = currentCommunicationPoint; + /* TODO: Calculate time/state-dependent variables here... */ + pot_threshold_functionOutputs(comp); + return fmi2OK; +} + +int main(int argc, char **argv) +{ + int terminateSimulation = 0; + fmi2Status status = fmi2OK; + fmi2CallbackFunctions cbf = { + .logger = NULL, + .allocateMemory = NULL /*calloc*/, + .freeMemory = NULL /*free*/, + .stepFinished = NULL, //synchronous execution + .componentEnvironment = NULL + }; + + fmi2Component comp = pot_threshold_fmi2Instantiate("", fmi2CoSimulation, "", "", &cbf, fmi2False, fmi2False); + if (comp==NULL) { + return 1; + } + pot_threshold_fmi2SetupExperiment(comp, fmi2False, 0.0, 0.0, fmi2False, 1.0); + pot_threshold_fmi2EnterInitializationMode(comp); + // Set start-values? Nah... + pot_threshold_fmi2ExitInitializationMode(comp); + + double currentTime = 0.0; + double h = 0.002; + uint32_t i = 0; + + while (status == fmi2OK) { + //retrieve outputs + // fmi2GetReal(m, ..., 1, &y1); + //set inputs + // fmi2SetReal(m, ..., 1, &y2); + + //call slave and check status + status = pot_threshold_fmi2DoStep(comp, currentTime, h, fmi2True); + switch (status) { + case fmi2Discard: + case fmi2Error: + case fmi2Fatal: + case fmi2Pending /* Cannot happen */: + terminateSimulation = 1; + break; + case fmi2OK: + case fmi2Warning: + break; + } + if (terminateSimulation) { + break; + } + i++; + /* increment master time */ + currentTime = 0.0 + h*i; + } + +#if 0 + if ((status != fmi2Error) && (status != fmi2Fatal)) { + fmi2Terminate(m); + } + if (status != fmi2Fatal) { + fmi2FreeInstance(m); + } +#endif +} + diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/pot/runMDD_pot_threshold.mos b/OpenModelica_Arduino_With_MDD/MDD_build/pot/runMDD_pot_threshold.mos new file mode 100644 index 0000000..f347b0c --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/pot/runMDD_pot_threshold.mos @@ -0,0 +1,11 @@ +loadModel(Modelica); +getErrorString(); + +loadFile("/home/sumeet/Modelica_DeviceDrivers/package.mo"); +getErrorString(); + +loadFile("/home/sumeet/MDD_Arduino/linux-version-4/OpenModelica-Arduino-MDD_Arduino_Revised/Arduino.mo"); +getErrorString(); + +translateModel(Arduino.SerialCommunication.MDD_Examples.MDD_pot.MDD_pot_threshold, fileNamePrefix="pot_threshold"); +getErrorString(); diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/pot/runMDD_pot_threshold.mos~ b/OpenModelica_Arduino_With_MDD/MDD_build/pot/runMDD_pot_threshold.mos~ new file mode 100644 index 0000000..98cc2cc --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/pot/runMDD_pot_threshold.mos~ @@ -0,0 +1,14 @@ +loadModel(Modelica); +getErrorString(); + +loadFile("/home/sumeet/Modelica_DeviceDrivers/package.mo"); +getErrorString(); + +loadFile("/home/sumeet/MDD_Arduino/linux-version-4/OpenModelica-Arduino-MDD_Arduino_Revised/Arduino.mo"); +getErrorString(); + +translateModel(Arduino.SerialCommunication.MDD_Examples.MDD_pot.MDD_pot_threshold, fileNamePrefix="pot_threshold"); +getErrorString(); + +simulate(pot_threshold, outputFormat="csv", startTime=0, stopTime=4, numberOfIntervals=5) +plot(y) diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/push/led_push_button b/OpenModelica_Arduino_With_MDD/MDD_build/push/led_push_button Binary files differnew file mode 100644 index 0000000..976f017 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/push/led_push_button diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/push/led_push_button.hex b/OpenModelica_Arduino_With_MDD/MDD_build/push/led_push_button.hex new file mode 100644 index 0000000..a35b0ab --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/push/led_push_button.hex @@ -0,0 +1,94 @@ +:100000000C9434000C9451000C9451000C94510049
+:100010000C9451000C9451000C9451000C94FC0071
+:100020000C9451000C9451000C9451000C94CB0092
+:100030000C9451000C9451000C949A000C945100B3
+:100040000C9451000C9451000C9451000C945100EC
+:100050000C9451000C9451000C9451000C945100DC
+:100060000C9451000C94510011241FBECFEFD8E026
+:10007000DEBFCDBF11E0A0E0B1E0ECEAF5E002C0E8
+:1000800005900D92A631B107D9F711E0A6E1B1E0D4
+:1000900001C01D92AB31B107E1F70E944F010C94F2
+:1000A000D4020C940000FC01A685B7858C91829542
+:1000B000817080871186848995898230910561F0ED
+:1000C0008330910599F00197C9F416BC80916E00B8
+:1000D000826080936E0016C010928500109284009A
+:1000E00080916F00826080936F000CC01092B2000C
+:1000F0008091700082608093700004C081E090E085
+:100100000E94D40278949FB7F894809118019FBF01
+:100110008823C9F310921801A089B189808591853F
+:10012000009721F08C9182608C9308958C918D7F43
+:100130008C9308951F920F920FB60F9211242F9354
+:100140003F938F939F938091160190911701019691
+:10015000909317018093160180911801813091F0DE
+:1001600020911601309117018091190190911A0187
+:100170002817390738F081E0809318011092170191
+:10018000109216019F918F913F912F910F900FBE6A
+:100190000F901F9018951F920F920FB60F92112477
+:1001A0002F933F938F939F93809116019091170106
+:1001B0000196909317018093160180911801813068
+:1001C00091F02091160130911701809119019091C1
+:1001D0001A012817390738F081E08093180110922E
+:1001E0001701109216019F918F913F912F910F90BF
+:1001F0000FBE0F901F9018951F920F920FB60F927F
+:1002000011242F933F938F939F9380911601909188
+:1002100017010196909317018093160180911801A0
+:10022000813091F0209116013091170180911901D0
+:1002300090911A012817390738F081E0809318014E
+:1002400010921701109216019F918F913F912F915B
+:100250000F900FBE0F901F901895FC01219A85E218
+:1002600090E0918B808B249883E290E0978786873B
+:1002700085B5836085BD81E090E0938B828B22E021
+:1002800030E030931A012093190124B5226024BD77
+:1002900029EF27BD958B848B80E090E00895CF9265
+:1002A000DF92EF92FF9280E091E00E942D01C12C3D
+:1002B000D12C760160E070E0CB0160930001709377
+:1002C0000101809302019093030180E091E00E947C
+:1002D00053008FEFC81AD80AE80AF80AC701B60116
+:1002E0000E94E3012FE632E143E05BE30E947102EA
+:1002F00020E030E0A9010E947F01DFCF5058BB27EA
+:10030000AA270ED0B4C0A5D030F0AAD020F031F486
+:100310009F3F11F41EF49AC00EF4E095E7FB90C0E5
+:10032000E92FB6D080F3BA176207730784079507E1
+:1003300018F071F49EF5CEC00EF4E0950B2EBA2F96
+:10034000A02D0B01B90190010C01CA01A0011124DB
+:10035000FF27591B99F0593F50F4503E68F11A1687
+:10036000F040A22F232F342F4427585FF3CF469518
+:1003700037952795A795F0405395C9F77EF41F163A
+:10038000BA0B620B730B840BBAF09150A1F0FF0F04
+:10039000BB1F661F771F881FC2F70EC0BA0F621FF0
+:1003A000731F841F48F4879577956795B795F795E0
+:1003B0009E3F08F0B3CF9395880F08F09927EE0F72
+:1003C000979587950895E89409C097FB3EF490951A
+:1003D0008095709561957F4F8F4F9F4F9923A9F01E
+:1003E000F92F96E9BB279395F695879577956795AD
+:1003F000B795F111F8CFFAF4BB0F11F460FF1BC0F1
+:100400006F5F7F4F8F4F9F4F16C0882311F096E983
+:1004100011C0772321F09EE8872F762F05C0662331
+:1004200071F096E8862F70E060E02AF09A95660FEA
+:10043000771F881FDAF7880F9695879597F90895A3
+:1004400097F99F6780E870E060E008959FEF80EC87
+:10045000089500240A94161617061806090608952A
+:1004600000240A9412161306140605060895092E90
+:100470000394000C11F4882352F0BB0F40F4BF2BFF
+:1004800011F460FF04C06F5F7F4F8F4F9F4F08953F
+:1004900057FD9058440F551F59F05F3F71F0479535
+:1004A000880F97FB991F61F09F3F79F0879508951A
+:1004B000121613061406551FF2CF4695F1DF08C039
+:1004C000161617061806991FF1CF86957105610556
+:1004D00008940895E894BB2766277727CB0197F9FE
+:1004E00008950BD0C4CFB5DF28F0BADF18F09523FC
+:1004F00009F0A6CFABCF1124EECFCADFA0F3959FB2
+:10050000D1F3950F50E0551F629FF001729FBB27FA
+:10051000F00DB11D639FAA27F00DB11DAA1F649FA6
+:100520006627B00DA11D661F829F2227B00DA11D59
+:10053000621F739FB00DA11D621F839FA00D611DDF
+:10054000221F749F3327A00D611D231F849F600D00
+:10055000211D822F762F6A2F11249F5750408AF039
+:10056000E1F088234AF0EE0FFF1FBB1F661F771FC5
+:10057000881F91505040A9F79E3F510570F060CF01
+:10058000AACF5F3FECF3983EDCF3869577956795AD
+:10059000B795F795E7959F5FC1F7FE2B880F911DE3
+:0C05A0009695879597F90895F894FFCF81
+:1005AC00000000000000000000006F12033B000080
+:0605BC0000000000000039
+:00000001FF
diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/push/led_push_button.sh b/OpenModelica_Arduino_With_MDD/MDD_build/push/led_push_button.sh new file mode 100644 index 0000000..2676f10 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/push/led_push_button.sh @@ -0,0 +1,61 @@ +#!/bin/bash +clear +if [ "$#" -ne 2 ]; then + echo "Usage: $0 port baudrate" >&2 + exit 1 +fi + +re='^[0-9]+$' +if ! [[ $1 =~ $re ]] ; then + echo "error: $1 -> Not a number" >&2; exit 1 +fi + +if ! [[ $2 =~ $re ]] ; then + echo "error: $2-> Not a number" >&2; exit 1 +fi + +b_rate=$2 + +present=`pwd` +unamestr=`uname` + +if [[ "$unamestr" == 'Linux' ]]; then + mdd_path=($(locate Modelica_DeviceDrivers/Resources/Include)) + om_path=($(locate /usr/include/omc/c)) + port="/dev/ttyACM$1" + omc --simCodeTarget=ExperimentalEmbeddedC runMDD_led_push_button.mos + if [ $? -ne 0 ]; then + exit 1 + fi +else + cd c: + om_path=($(dir -d OpenModelica*/include/omc/c/)) + path_to_om="C:$om_path" + cd f: + mdd_path=($(dir -d */Modelica_DeviceDrivers/Modelica_DeviceDrivers/Resources/Include/)) + if [ $? -eq 0 ]; then + path_to_mdd="F:/$mdd_path" + else + exit 1 + fi + + port="COM$1" + cd $present + omc --simCodeTarget=ExperimentalEmbeddedC run_led_push_button.mos + if [ $? -ne 0 ]; then + exit 1 + fi +fi + +avr-gcc -Os -std=c11 -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000UL -Wl,--gc-sections led_push_button_main.c -o led_push_button -I${mdd_path[0]} -I${path_to_om} -I${path_to_mdd} -I${om_path[0]} +if [ $? -ne 0 ]; then + exit 1 +fi +avr-objcopy -O ihex -R .eeprom led_push_button led_push_button.hex +if [ $? -ne 0 ]; then + exit 1 +fi +avrdude -F -V -c arduino -p ATMEGA328P -P $port -b $b_rate -U flash:w:led_push_button.hex +if [ $? -ne 0 ]; then + exit 1 +fi diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/push/led_push_button.sh~ b/OpenModelica_Arduino_With_MDD/MDD_build/push/led_push_button.sh~ new file mode 100644 index 0000000..1428171 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/push/led_push_button.sh~ @@ -0,0 +1,61 @@ +#!/bin/bash +clear +if [ "$#" -ne 2 ]; then + echo "Usage: $0 port baudrate" >&2 + exit 1 +fi + +re='^[0-9]+$' +if ! [[ $1 =~ $re ]] ; then + echo "error: $1 -> Not a number" >&2; exit 1 +fi + +if ! [[ $2 =~ $re ]] ; then + echo "error: $2-> Not a number" >&2; exit 1 +fi + +b_rate=$2 + +present=`pwd` +unamestr=`uname` + +if [[ "$unamestr" == 'Linux' ]]; then + mdd_path=($(locate Modelica_DeviceDrivers/Modelica_DeviceDrivers/Resources/Include)) + om_path=($(locate /usr/include/omc/c)) + port="/dev/ttyACM$1" + omc --simCodeTarget=ExperimentalEmbeddedC runMDD_led_push_button.mos + if [ $? -ne 0 ]; then + exit 1 + fi +else + cd c: + om_path=($(dir -d OpenModelica*/include/omc/c/)) + path_to_om="C:$om_path" + cd f: + mdd_path=($(dir -d */Modelica_DeviceDrivers/Modelica_DeviceDrivers/Resources/Include/)) + if [ $? -eq 0 ]; then + path_to_mdd="F:/$mdd_path" + else + exit 1 + fi + + port="COM$1" + cd $present + omc --simCodeTarget=ExperimentalEmbeddedC run_led_push_button.mos + if [ $? -ne 0 ]; then + exit 1 + fi +fi + +avr-gcc -Os -std=c11 -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000UL -Wl,--gc-sections led_push_button_main.c -o led_push_button -I${mdd_path[0]} -I${path_to_om} -I${path_to_mdd} -I${om_path[0]} +if [ $? -ne 0 ]; then + exit 1 +fi +avr-objcopy -O ihex -R .eeprom led_push_button led_push_button.hex +if [ $? -ne 0 ]; then + exit 1 +fi +avrdude -F -V -c arduino -p ATMEGA328P -P $port -b $b_rate -U flash:w:led_push_button.hex +if [ $? -ne 0 ]; then + exit 1 +fi
\ No newline at end of file diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/push/led_push_button_main.c b/OpenModelica_Arduino_With_MDD/MDD_build/push/led_push_button_main.c new file mode 100644 index 0000000..0a380fc --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/push/led_push_button_main.c @@ -0,0 +1,235 @@ +#define fmi2TypesPlatform_h + +#define fmi2TypesPlatform "default" /* Compatible */ + +typedef struct led_push_button_fmi2Component_s* fmi2Component; +typedef void* fmi2ComponentEnvironment; /* Pointer to FMU environment */ +typedef void* fmi2FMUstate; /* Pointer to internal FMU state */ +typedef unsigned int fmi2ValueReference; +typedef double fmi2Real; +typedef int fmi2Integer; +typedef int fmi2Boolean; +typedef char fmi2Char; +typedef const fmi2Char* fmi2String; +typedef char fmi2Byte; + +#define fmi2True 1 +#define fmi2False 0 + +#include "fmi2/fmi2Functions.h" + +#include <stdint.h> +#include <stdio.h> + +void ModelicaFormatMessage(const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + vprintf(fmt, args); + va_end(args); +} + +typedef struct led_push_button_fmi2Component_s { + fmi2Real currentTime; + fmi2Boolean fmi2BooleanVars[3]; + fmi2Real fmi2RealParameter[1]; + void* extObjs[4]; +} led_push_button_fmi2Component; + +led_push_button_fmi2Component led_push_button_component = { + .fmi2BooleanVars = { + fmi2False /*booleanExpression1._y*/, + fmi2False /*booleanExpression2._y*/, + fmi2False /*digitalReadBoolean1._y*/, + }, + .fmi2RealParameter = { + 0.002 /*synchronizeRealtime1._actualInterval*/, + }, +}; + +#include <math.h> +/* TODO: Generate used builtin functions before SimCode */ +static inline double om_mod(double x, double y) +{ + return x-floor(x/y)*y; +} + +#include "MDDAVRTimer.h" +#include "MDDAVRRealTime.h" +#include "MDDAVRDigital.h" + +static inline fmi2Boolean Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_read(fmi2Component comp, void* om_port, fmi2Integer om_pin); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(fmi2Component comp, void* om_port, fmi2Integer om_pin, fmi2Boolean om_value); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitRead_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitRead_destructor(fmi2Component comp, void* om_digital); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_destructor(fmi2Component comp, void* om_digital); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer); + +static inline fmi2Boolean Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_read(fmi2Component comp, void* om_port, fmi2Integer om_pin) +{ + fmi2Boolean om_b; + om_b = MDD_avr_digital_pin_read(om_port, om_pin); + return om_b; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(fmi2Component comp, void* om_port, fmi2Integer om_pin, fmi2Boolean om_value) +{ + MDD_avr_digital_pin_write(om_port, om_pin, om_value); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitRead_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin) +{ + void* om_dig; + om_dig = MDD_avr_digital_pin_init(om_port, om_pin, fmi2False); + return om_dig; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitRead_destructor(fmi2Component comp, void* om_digital) +{ + MDD_avr_digital_pin_close(om_digital); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin) +{ + void* om_dig; + om_dig = MDD_avr_digital_pin_init(om_port, om_pin, fmi2True); + return om_dig; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_destructor(fmi2Component comp, void* om_digital) +{ + MDD_avr_digital_pin_close(om_digital); +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt) +{ + MDD_avr_rt_wait(om_rt); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle) +{ + void* om_rt; + om_rt = MDD_avr_rt_init(om_timer, om_timerValue, om_numTimerInterruptsPerCycle); + return om_rt; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt) +{ + MDD_avr_rt_close(om_rt); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch) +{ + void* om_timer; + om_timer = MDD_avr_timer_init(om_timerSelect, om_clockSelect, om_clearTimerOnMatch); + return om_timer; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer) +{ + MDD_avr_timer_close(om_timer); +} + +fmi2Component led_push_button_fmi2Instantiate(fmi2String name, fmi2Type ty, fmi2String GUID, fmi2String resources, const fmi2CallbackFunctions* functions, fmi2Boolean visible, fmi2Boolean loggingOn) +{ + static int initDone=0; + if (initDone) { + return NULL; + } + return &led_push_button_component; +} + +fmi2Status led_push_button_fmi2SetupExperiment(fmi2Component comp, fmi2Boolean toleranceDefined, fmi2Real tolerance, fmi2Real startTime, fmi2Boolean stopTimeDefined, fmi2Real stopTime) +{ + return fmi2OK; +} + +fmi2Status led_push_button_fmi2EnterInitializationMode(fmi2Component comp) +{ + comp->extObjs[1] /* digitalWriteBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(comp, 2, 2); + comp->extObjs[0] /* digitalReadBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitRead */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitRead_constructor(comp, 2, 5); + comp->extObjs[2] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(comp, 1, 4, fmi2False); + comp->extObjs[3] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(comp, comp->extObjs[2] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */, 249, 2); + return fmi2OK; +} + +fmi2Status led_push_button_fmi2ExitInitializationMode(fmi2Component comp) +{ + return fmi2OK; +} + +static fmi2Status led_push_button_functionODE(fmi2Component comp) +{ +} + +static fmi2Status led_push_button_functionOutputs(fmi2Component comp) +{ + comp->fmi2BooleanVars[2] /* digitalReadBoolean1._y DISCRETE */ = comp->fmi2BooleanVars[2] /* digitalReadBoolean1._y DISCRETE */; + comp->fmi2BooleanVars[2] /* digitalReadBoolean1._y DISCRETE */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_read(comp, comp->extObjs[0] /* digitalReadBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitRead */, 5);Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(comp, comp->extObjs[3] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */);Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(comp, comp->extObjs[1] /* digitalWriteBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */, 2, comp->fmi2BooleanVars[2] /* digitalReadBoolean1._y DISCRETE */); +} + +fmi2Status led_push_button_fmi2DoStep(fmi2Component comp, fmi2Real currentCommunicationPoint, fmi2Real communicationStepSize, fmi2Boolean noSetFMUStatePriorToCurrentPoint) +{ + comp->currentTime = currentCommunicationPoint; + /* TODO: Calculate time/state-dependent variables here... */ + led_push_button_functionOutputs(comp); + return fmi2OK; +} + +int main(int argc, char **argv) +{ + int terminateSimulation = 0; + fmi2Status status = fmi2OK; + fmi2CallbackFunctions cbf = { + .logger = NULL, + .allocateMemory = NULL /*calloc*/, + .freeMemory = NULL /*free*/, + .stepFinished = NULL, //synchronous execution + .componentEnvironment = NULL + }; + + fmi2Component comp = led_push_button_fmi2Instantiate("", fmi2CoSimulation, "", "", &cbf, fmi2False, fmi2False); + if (comp==NULL) { + return 1; + } + led_push_button_fmi2SetupExperiment(comp, fmi2False, 0.0, 0.0, fmi2False, 1.0); + led_push_button_fmi2EnterInitializationMode(comp); + // Set start-values? Nah... + led_push_button_fmi2ExitInitializationMode(comp); + + double currentTime = 0.0; + double h = 0.002; + uint32_t i = 0; + + while (status == fmi2OK) { + //retrieve outputs + // fmi2GetReal(m, ..., 1, &y1); + //set inputs + // fmi2SetReal(m, ..., 1, &y2); + + //call slave and check status + status = led_push_button_fmi2DoStep(comp, currentTime, h, fmi2True); + switch (status) { + case fmi2Discard: + case fmi2Error: + case fmi2Fatal: + case fmi2Pending /* Cannot happen */: + terminateSimulation = 1; + break; + case fmi2OK: + case fmi2Warning: + break; + } + if (terminateSimulation) { + break; + } + i++; + /* increment master time */ + currentTime = 0.0 + h*i; + } + +#if 0 + if ((status != fmi2Error) && (status != fmi2Fatal)) { + fmi2Terminate(m); + } + if (status != fmi2Fatal) { + fmi2FreeInstance(m); + } +#endif +} + diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/push/led_push_test.hex b/OpenModelica_Arduino_With_MDD/MDD_build/push/led_push_test.hex new file mode 100644 index 0000000..ef6d000 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/push/led_push_test.hex @@ -0,0 +1,64 @@ +:100000000C9434000C9446000C9446000C9446006A
+:100010000C9446000C9446000C9446000C94460048
+:100020000C9446000C9446000C9446000C94460038
+:100030000C9446000C9446000C9446000C94460028
+:100040000C9446000C9446000C9446000C94460018
+:100050000C9446000C9446000C9446000C94460008
+:100060000C9446000C94460011241FBECFEFD8E03C
+:10007000DEBFCDBF11E0A0E0B1E001C01D92AE3007
+:10008000B107E1F70E946C000C94F1010C940000A0
+:10009000FC01A285B3858C9184FB222720F930E0F6
+:1000A000318720870484F585E02D8081232B19F08A
+:1000B0008460808308958B7F80830895229A25E24F
+:1000C00030E0FC0135872487249823E230E0338731
+:1000D000228780E090E00895CF92DF92EF92FF9226
+:1000E00080E091E00E945E00C12CD12C760160E09E
+:1000F00070E0CB01609300017093010180930201D5
+:100100009093030180E091E00E9448008FEFC81AAD
+:10011000D80AE80AF80AC701B6010E9400012FE6D2
+:1001200032E143E05BE30E948E0120E030E0A90170
+:100130000E949C00DFCF5058BB27AA270ED0B4C026
+:10014000A5D030F0AAD020F031F49F3F11F41EF476
+:100150009AC00EF4E095E7FB90C0E92FB6D080F38B
+:10016000BA17620773078407950718F071F49EF5B4
+:10017000CEC00EF4E0950B2EBA2FA02D0B01B901C5
+:1001800090010C01CA01A0011124FF27591B99F00D
+:10019000593F50F4503E68F11A16F040A22F232F19
+:1001A000342F4427585FF3CF469537952795A79569
+:1001B000F0405395C9F77EF41F16BA0B620B730B10
+:1001C000840BBAF09150A1F0FF0FBB1F661F771F81
+:1001D000881FC2F70EC0BA0F621F731F841F48F436
+:1001E000879577956795B795F7959E3F08F0B3CFBC
+:1001F0009395880F08F09927EE0F979587950895A6
+:10020000E89409C097FB3EF49095809570956195B0
+:100210007F4F8F4F9F4F9923A9F0F92F96E9BB2766
+:100220009395F695879577956795B795F111F8CFE2
+:10023000FAF4BB0F11F460FF1BC06F5F7F4F8F4F4D
+:100240009F4F16C0882311F096E911C0772321F043
+:100250009EE8872F762F05C0662371F096E8862FDB
+:1002600070E060E02AF09A95660F771F881FDAF732
+:10027000880F9695879597F9089597F99F6780E875
+:1002800070E060E008959FEF80EC089500240A94E8
+:100290001616170618060906089500240A94121661
+:1002A0001306140605060895092E0394000C11F494
+:1002B000882352F0BB0F40F4BF2B11F460FF04C041
+:1002C0006F5F7F4F8F4F9F4F089557FD9058440F9A
+:1002D000551F59F05F3F71F04795880F97FB991FA5
+:1002E00061F09F3F79F08795089512161306140662
+:1002F000551FF2CF4695F1DF08C0161617061806EF
+:10030000991FF1CF86957105610508940895E894C9
+:10031000BB2766277727CB0197F908950BD0C4CF69
+:10032000B5DF28F0BADF18F0952309F0A6CFABCFE0
+:100330001124EECFCADFA0F3959FD1F3950F50E0C3
+:10034000551F629FF001729FBB27F00DB11D639F87
+:10035000AA27F00DB11DAA1F649F6627B00DA11D2D
+:10036000661F829F2227B00DA11D621F739FB00DD3
+:10037000A11D621F839FA00D611D221F749F332743
+:10038000A00D611D231F849F600D211D822F762FDC
+:100390006A2F11249F5750408AF0E1F088234AF0D9
+:1003A000EE0FFF1FBB1F661F771F881F9150504025
+:1003B000A9F79E3F510570F060CFAACF5F3FECF3E5
+:1003C000983EDCF3869577956795B795F795E79511
+:1003D0009F5FC1F7FE2B880F911D9695879597F922
+:0603E0000895F894FFCF20
+:00000001FF
diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/push/led_push_test_main.c b/OpenModelica_Arduino_With_MDD/MDD_build/push/led_push_test_main.c new file mode 100644 index 0000000..1bef90d --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/push/led_push_test_main.c @@ -0,0 +1,198 @@ +#define fmi2TypesPlatform_h + +#define fmi2TypesPlatform "default" /* Compatible */ + +typedef struct led_push_test_fmi2Component_s* fmi2Component; +typedef void* fmi2ComponentEnvironment; /* Pointer to FMU environment */ +typedef void* fmi2FMUstate; /* Pointer to internal FMU state */ +typedef unsigned int fmi2ValueReference; +typedef double fmi2Real; +typedef int fmi2Integer; +typedef int fmi2Boolean; +typedef char fmi2Char; +typedef const fmi2Char* fmi2String; +typedef char fmi2Byte; + +#define fmi2True 1 +#define fmi2False 0 + +#include "fmi2/fmi2Functions.h" + +#include <stdint.h> +#include <stdio.h> + +void ModelicaFormatMessage(const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + vprintf(fmt, args); + va_end(args); +} + +typedef struct led_push_test_fmi2Component_s { + fmi2Real currentTime; + fmi2Boolean fmi2BooleanVars[3]; + void* extObjs[2]; +} led_push_test_fmi2Component; + +led_push_test_fmi2Component led_push_test_component = { + .fmi2BooleanVars = { + fmi2False /*booleanExpression1._y*/, + fmi2False /*booleanExpression2._y*/, + fmi2False /*digitalReadBoolean1._y*/, + }, +}; + +#include <math.h> +/* TODO: Generate used builtin functions before SimCode */ +static inline double om_mod(double x, double y) +{ + return x-floor(x/y)*y; +} + +#include "MDDAVRDigital.h" + +static inline fmi2Boolean Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_read(fmi2Component comp, void* om_port, fmi2Integer om_pin); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(fmi2Component comp, void* om_port, fmi2Integer om_pin, fmi2Boolean om_value); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitRead_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitRead_destructor(fmi2Component comp, void* om_digital); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_destructor(fmi2Component comp, void* om_digital); + +static inline fmi2Boolean Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_read(fmi2Component comp, void* om_port, fmi2Integer om_pin) +{ + fmi2Boolean om_b; + om_b = MDD_avr_digital_pin_read(om_port, om_pin); + return om_b; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(fmi2Component comp, void* om_port, fmi2Integer om_pin, fmi2Boolean om_value) +{ + MDD_avr_digital_pin_write(om_port, om_pin, om_value); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitRead_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin) +{ + void* om_dig; + om_dig = MDD_avr_digital_pin_init(om_port, om_pin, fmi2False); + return om_dig; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitRead_destructor(fmi2Component comp, void* om_digital) +{ + MDD_avr_digital_pin_close(om_digital); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin) +{ + void* om_dig; + om_dig = MDD_avr_digital_pin_init(om_port, om_pin, fmi2True); + return om_dig; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_destructor(fmi2Component comp, void* om_digital) +{ + MDD_avr_digital_pin_close(om_digital); +} + +fmi2Component led_push_test_fmi2Instantiate(fmi2String name, fmi2Type ty, fmi2String GUID, fmi2String resources, const fmi2CallbackFunctions* functions, fmi2Boolean visible, fmi2Boolean loggingOn) +{ + static int initDone=0; + if (initDone) { + return NULL; + } + return &led_push_test_component; +} + +fmi2Status led_push_test_fmi2SetupExperiment(fmi2Component comp, fmi2Boolean toleranceDefined, fmi2Real tolerance, fmi2Real startTime, fmi2Boolean stopTimeDefined, fmi2Real stopTime) +{ + return fmi2OK; +} + +fmi2Status led_push_test_fmi2EnterInitializationMode(fmi2Component comp) +{ + comp->extObjs[1] /* digitalWriteBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(comp, 2, 3); + comp->extObjs[0] /* digitalReadBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitRead */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitRead_constructor(comp, 2, 5); + return fmi2OK; +} + +fmi2Status led_push_test_fmi2ExitInitializationMode(fmi2Component comp) +{ + return fmi2OK; +} + +static fmi2Status led_push_test_functionODE(fmi2Component comp) +{ +} + +static fmi2Status led_push_test_functionOutputs(fmi2Component comp) +{ + comp->fmi2BooleanVars[2] /* digitalReadBoolean1._y DISCRETE */ = comp->fmi2BooleanVars[2] /* digitalReadBoolean1._y DISCRETE */; + comp->fmi2BooleanVars[2] /* digitalReadBoolean1._y DISCRETE */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_read(comp, comp->extObjs[0] /* digitalReadBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitRead */, 5);Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(comp, comp->extObjs[1] /* digitalWriteBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */, 3, comp->fmi2BooleanVars[2] /* digitalReadBoolean1._y DISCRETE */); +} + +fmi2Status led_push_test_fmi2DoStep(fmi2Component comp, fmi2Real currentCommunicationPoint, fmi2Real communicationStepSize, fmi2Boolean noSetFMUStatePriorToCurrentPoint) +{ + comp->currentTime = currentCommunicationPoint; + /* TODO: Calculate time/state-dependent variables here... */ + led_push_test_functionOutputs(comp); + return fmi2OK; +} + +int main(int argc, char **argv) +{ + int terminateSimulation = 0; + fmi2Status status = fmi2OK; + fmi2CallbackFunctions cbf = { + .logger = NULL, + .allocateMemory = NULL /*calloc*/, + .freeMemory = NULL /*free*/, + .stepFinished = NULL, //synchronous execution + .componentEnvironment = NULL + }; + + fmi2Component comp = led_push_test_fmi2Instantiate("", fmi2CoSimulation, "", "", &cbf, fmi2False, fmi2False); + if (comp==NULL) { + return 1; + } + led_push_test_fmi2SetupExperiment(comp, fmi2False, 0.0, 0.0, fmi2False, 1.0); + led_push_test_fmi2EnterInitializationMode(comp); + // Set start-values? Nah... + led_push_test_fmi2ExitInitializationMode(comp); + + double currentTime = 0.0; + double h = 0.002; + uint32_t i = 0; + + while (status == fmi2OK) { + //retrieve outputs + // fmi2GetReal(m, ..., 1, &y1); + //set inputs + // fmi2SetReal(m, ..., 1, &y2); + + //call slave and check status + status = led_push_test_fmi2DoStep(comp, currentTime, h, fmi2True); + switch (status) { + case fmi2Discard: + case fmi2Error: + case fmi2Fatal: + case fmi2Pending /* Cannot happen */: + terminateSimulation = 1; + break; + case fmi2OK: + case fmi2Warning: + break; + } + if (terminateSimulation) { + break; + } + i++; + /* increment master time */ + currentTime = 0.0 + h*i; + } + +#if 0 + if ((status != fmi2Error) && (status != fmi2Fatal)) { + fmi2Terminate(m); + } + if (status != fmi2Fatal) { + fmi2FreeInstance(m); + } +#endif +} + diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/push/led_test b/OpenModelica_Arduino_With_MDD/MDD_build/push/led_test Binary files differnew file mode 100644 index 0000000..3a7ea87 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/push/led_test diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/push/output.txt b/OpenModelica_Arduino_With_MDD/MDD_build/push/output.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/push/output.txt diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/push/pushTest1.mo b/OpenModelica_Arduino_With_MDD/MDD_build/push/pushTest1.mo new file mode 100644 index 0000000..6f0e207 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/push/pushTest1.mo @@ -0,0 +1,26 @@ +model pushTest1 + extends Modelica.Icons.Example; + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.DigitalReadBoolean digitalReadBoolean1(pin = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Pin.'4', port = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Port.B) annotation( + Placement(visible = true, transformation(origin = {-60, -2}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.DigitalWriteBoolean digitalWriteBoolean1(pin = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Pin.'2', port = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Port.B) annotation( + Placement(visible = true, transformation(origin = {60, -2}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Logical.LogicalSwitch logicalSwitch1 annotation( + Placement(visible = true, transformation(origin = {-2, -2}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Sources.BooleanExpression booleanExpression1(y = true) annotation( + Placement(visible = true, transformation(origin = {-44, 48}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + Modelica.Blocks.Sources.BooleanExpression booleanExpression2(y = false) annotation( + Placement(visible = true, transformation(origin = {-46, -58}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); + inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation( + Placement(visible = true, transformation(origin = {-70, 78}, extent = {{-10, -10}, {10, 10}}, rotation = 0))); +equation + connect(booleanExpression1.y, logicalSwitch1.u1) annotation( + Line(points = {{-33, 48}, {-28, 48}, {-28, 6}, {-14, 6}}, color = {255, 0, 255})); + connect(logicalSwitch1.y, digitalWriteBoolean1.u) annotation( + Line(points = {{10, -2}, {48, -2}, {48, -2}, {48, -2}}, color = {255, 0, 255})); + connect(digitalReadBoolean1.y, logicalSwitch1.u2) annotation( + Line(points = {{-48, -2}, {-14, -2}, {-14, -2}, {-14, -2}}, color = {255, 0, 255})); + connect(booleanExpression2.y, logicalSwitch1.u3) annotation( + Line(points = {{-34, -58}, {-24, -58}, {-24, -10}, {-14, -10}, {-14, -10}}, color = {255, 0, 255})); + annotation( + uses(Modelica_DeviceDrivers(version = "1.5.0"), Modelica(version = "3.2.2"))); +end pushTest1;
\ No newline at end of file diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/push/pushTest1.sh b/OpenModelica_Arduino_With_MDD/MDD_build/push/pushTest1.sh new file mode 100644 index 0000000..2676f10 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/push/pushTest1.sh @@ -0,0 +1,61 @@ +#!/bin/bash +clear +if [ "$#" -ne 2 ]; then + echo "Usage: $0 port baudrate" >&2 + exit 1 +fi + +re='^[0-9]+$' +if ! [[ $1 =~ $re ]] ; then + echo "error: $1 -> Not a number" >&2; exit 1 +fi + +if ! [[ $2 =~ $re ]] ; then + echo "error: $2-> Not a number" >&2; exit 1 +fi + +b_rate=$2 + +present=`pwd` +unamestr=`uname` + +if [[ "$unamestr" == 'Linux' ]]; then + mdd_path=($(locate Modelica_DeviceDrivers/Resources/Include)) + om_path=($(locate /usr/include/omc/c)) + port="/dev/ttyACM$1" + omc --simCodeTarget=ExperimentalEmbeddedC runMDD_led_push_button.mos + if [ $? -ne 0 ]; then + exit 1 + fi +else + cd c: + om_path=($(dir -d OpenModelica*/include/omc/c/)) + path_to_om="C:$om_path" + cd f: + mdd_path=($(dir -d */Modelica_DeviceDrivers/Modelica_DeviceDrivers/Resources/Include/)) + if [ $? -eq 0 ]; then + path_to_mdd="F:/$mdd_path" + else + exit 1 + fi + + port="COM$1" + cd $present + omc --simCodeTarget=ExperimentalEmbeddedC run_led_push_button.mos + if [ $? -ne 0 ]; then + exit 1 + fi +fi + +avr-gcc -Os -std=c11 -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000UL -Wl,--gc-sections led_push_button_main.c -o led_push_button -I${mdd_path[0]} -I${path_to_om} -I${path_to_mdd} -I${om_path[0]} +if [ $? -ne 0 ]; then + exit 1 +fi +avr-objcopy -O ihex -R .eeprom led_push_button led_push_button.hex +if [ $? -ne 0 ]; then + exit 1 +fi +avrdude -F -V -c arduino -p ATMEGA328P -P $port -b $b_rate -U flash:w:led_push_button.hex +if [ $? -ne 0 ]; then + exit 1 +fi diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/push/pushTest1.sh~ b/OpenModelica_Arduino_With_MDD/MDD_build/push/pushTest1.sh~ new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/push/pushTest1.sh~ diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/push/push_button_status b/OpenModelica_Arduino_With_MDD/MDD_build/push/push_button_status Binary files differnew file mode 100644 index 0000000..5b91980 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/push/push_button_status diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/push/push_button_status.hex b/OpenModelica_Arduino_With_MDD/MDD_build/push/push_button_status.hex new file mode 100644 index 0000000..ab8dde5 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/push/push_button_status.hex @@ -0,0 +1,91 @@ +:100000000C9434000C9451000C9451000C94510049
+:100010000C9451000C9451000C9451000C94E50088
+:100020000C9451000C9451000C9451000C94B400A9
+:100030000C9451000C9451000C9483000C945100CA
+:100040000C9451000C9451000C9451000C945100EC
+:100050000C9451000C9451000C9451000C945100DC
+:100060000C9451000C94510011241FBECFEFD8E026
+:10007000DEBFCDBF11E0A0E0B1E0E8E7F5E002C0EF
+:1000800005900D92A431B107D9F711E0A4E1B1E0D8
+:1000900001C01D92A931B107E1F70E9433010C9410
+:1000A000BA020C9400008230910561F08330910512
+:1000B00099F00197C9F416BC80916E00826080931C
+:1000C0006E0016C0109285001092840080916F001F
+:1000D000826080936F000CC01092B200809170001B
+:1000E00082608093700004C081E090E00E94BA02B8
+:1000F00078949FB7F894809116019FBF8823C9F325
+:100100001092160108951F920F920FB60F921124AC
+:100110002F933F938F939F9380911401909115019A
+:1001200001969093150180931401809116018130FE
+:1001300091F0209114013091150180911701909157
+:1001400018012817390738F081E0809316011092C2
+:100150001501109214019F918F913F912F910F9053
+:100160000FBE0F901F9018951F920F920FB60F920F
+:1001700011242F933F938F939F938091140190911B
+:100180001501019690931501809314018091160139
+:10019000813091F020911401309115018091170167
+:1001A000909118012817390738F081E080931601E3
+:1001B00010921501109214019F918F913F912F91F0
+:1001C0000F900FBE0F901F9018951F920F920FB6B1
+:1001D0000F9211242F933F938F939F93809114013B
+:1001E00090911501019690931501809314018091CF
+:1001F0001601813091F02091140130911501809108
+:100200001701909118012817390738F081E0809381
+:10021000160110921501109214019F918F913F9138
+:100220002F910F900FBE0F901F901895FC012498EE
+:1002300083E290E09787868785B5836085BD81E0FE
+:1002400090E0918B808B22E030E030931801209376
+:10025000170124B5226024BD29EF27BD938B828B23
+:1002600080E090E00895CF92DF92EF92FF9280E0DD
+:1002700091E00E941601C12CD12C760160E070E063
+:10028000CB01609300017093010180930201909370
+:10029000030180911201909113010E9453008FEF8E
+:1002A000C81AD80AE80AF80AC701B6010E94C901AB
+:1002B0002FE632E143E05BE30E94570220E030E0AA
+:1002C000A9010E946501DDCF5058BB27AA270ED097
+:1002D000B4C0A5D030F0AAD020F031F49F3F11F483
+:1002E0001EF49AC00EF4E095E7FB90C0E92FB6D05B
+:1002F00080F3BA17620773078407950718F071F443
+:100300009EF5CEC00EF4E0950B2EBA2FA02D0B015A
+:10031000B90190010C01CA01A0011124FF27591B4A
+:1003200099F0593F50F4503E68F11A16F040A22F50
+:10033000232F342F4427585FF3CF469537952795C1
+:10034000A795F0405395C9F77EF41F16BA0B620BC0
+:10035000730B840BBAF09150A1F0FF0FBB1F661F07
+:10036000771F881FC2F70EC0BA0F621F731F841F4A
+:1003700048F4879577956795B795F7959E3F08F070
+:10038000B3CF9395880F08F09927EE0F979587952F
+:100390000895E89409C097FB3EF490958095709578
+:1003A00061957F4F8F4F9F4F9923A9F0F92F96E9C1
+:1003B000BB279395F695879577956795B795F11136
+:1003C000F8CFFAF4BB0F11F460FF1BC06F5F7F4FD3
+:1003D0008F4F9F4F16C0882311F096E911C07723E5
+:1003E00021F09EE8872F762F05C0662371F096E8EE
+:1003F000862F70E060E02AF09A95660F771F881FBD
+:10040000DAF7880F9695879597F9089597F99F677A
+:1004100080E870E060E008959FEF80EC089500248C
+:100420000A941616170618060906089500240A9459
+:1004300012161306140605060895092E0394000CDF
+:1004400011F4882352F0BB0F40F4BF2B11F460FF6E
+:1004500004C06F5F7F4F8F4F9F4F089557FD905897
+:10046000440F551F59F05F3F71F04795880F97FB78
+:10047000991F61F09F3F79F0879508951216130632
+:100480001406551FF2CF4695F1DF08C01616170661
+:100490001806991FF1CF8695710561050894089596
+:1004A000E894BB2766277727CB0197F908950BD0EF
+:1004B000C4CFB5DF28F0BADF18F0952309F0A6CF36
+:1004C000ABCF1124EECFCADFA0F3959FD1F3950FE8
+:1004D00050E0551F629FF001729FBB27F00DB11DC8
+:1004E000639FAA27F00DB11DAA1F649F6627B00D58
+:1004F000A11D661F829F2227B00DA11D621F739F41
+:10050000B00DA11D621F839FA00D611D221F749F4E
+:100510003327A00D611D231F849F600D211D822F95
+:10052000762F6A2F11249F5750408AF0E1F08823DC
+:100530004AF0EE0FFF1FBB1F661F771F881F9150E9
+:100540005040A9F79E3F510570F060CFAACF5F3FA2
+:10055000ECF3983EDCF3869577956795B795F7951C
+:10056000E7959F5FC1F7FE2B880F911D96958795A4
+:0805700097F90895F894FFCFFC
+:1005780000000000000000006F12033B01000000B3
+:04058800000000006F
+:00000001FF
diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/push/push_button_status.sh b/OpenModelica_Arduino_With_MDD/MDD_build/push/push_button_status.sh new file mode 100644 index 0000000..404eced --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/push/push_button_status.sh @@ -0,0 +1,61 @@ +#!/bin/bash +clear +if [ "$#" -ne 2 ]; then + echo "Usage: $0 port baudrate" >&2 + exit 1 +fi + +re='^[0-9]+$' +if ! [[ $1 =~ $re ]] ; then + echo "error: $1 -> Not a number" >&2; exit 1 +fi + +if ! [[ $2 =~ $re ]] ; then + echo "error: $2-> Not a number" >&2; exit 1 +fi + +b_rate=$2 + +present=`pwd` +unamestr=`uname` + +if [[ "$unamestr" == 'Linux' ]]; then + mdd_path=($(locate Modelica_DeviceDrivers/Modelica_DeviceDrivers/Resources/Include)) + om_path=($(locate /usr/include/omc/c)) + port="/dev/ttyACM$1" + omc --simCodeTarget=ExperimentalEmbeddedC runMDD_push_button_status.mos + if [ $? -ne 0 ]; then + exit 1 + fi +else + cd c: + om_path=($(dir -d OpenModelica*/include/omc/c/)) + path_to_om="C:$om_path" + cd f: + mdd_path=($(dir -d */Modelica_DeviceDrivers/Modelica_DeviceDrivers/Resources/Include/)) + if [ $? -eq 0 ]; then + path_to_mdd="F:/$mdd_path" + else + exit 1 + fi + + port="COM$1" + cd $present + omc --simCodeTarget=ExperimentalEmbeddedC run_push_button_status.mos + if [ $? -ne 0 ]; then + exit 1 + fi +fi + +avr-gcc -Os -std=c11 -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000UL -Wl,--gc-sections push_button_status_main.c -o push_button_status -I${mdd_path[0]} -I${path_to_om} -I${path_to_mdd} -I${om_path[0]} +if [ $? -ne 0 ]; then + exit 1 +fi +avr-objcopy -O ihex -R .eeprom push_button_status push_button_status.hex +if [ $? -ne 0 ]; then + exit 1 +fi +avrdude -F -V -c arduino -p ATMEGA328P -P $port -b $b_rate -U flash:w:push_button_status.hex +if [ $? -ne 0 ]; then + exit 1 +fi
\ No newline at end of file diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/push/push_button_status_main.c b/OpenModelica_Arduino_With_MDD/MDD_build/push/push_button_status_main.c new file mode 100644 index 0000000..f732e8a --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/push/push_button_status_main.c @@ -0,0 +1,219 @@ +#define fmi2TypesPlatform_h + +#define fmi2TypesPlatform "default" /* Compatible */ + +typedef struct push_button_status_fmi2Component_s* fmi2Component; +typedef void* fmi2ComponentEnvironment; /* Pointer to FMU environment */ +typedef void* fmi2FMUstate; /* Pointer to internal FMU state */ +typedef unsigned int fmi2ValueReference; +typedef double fmi2Real; +typedef int fmi2Integer; +typedef int fmi2Boolean; +typedef char fmi2Char; +typedef const fmi2Char* fmi2String; +typedef char fmi2Byte; + +#define fmi2True 1 +#define fmi2False 0 + +#include "fmi2/fmi2Functions.h" + +#include <stdint.h> +#include <stdio.h> + +void ModelicaFormatMessage(const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + vprintf(fmt, args); + va_end(args); +} + +typedef struct push_button_status_fmi2Component_s { + fmi2Real currentTime; + fmi2Boolean fmi2BooleanVars[2]; + fmi2Real fmi2RealParameter[1]; + fmi2Boolean fmi2BooleanParameter[1]; + void* extObjs[3]; +} push_button_status_fmi2Component; + +push_button_status_fmi2Component push_button_status_component = { + .fmi2BooleanVars = { + fmi2False /*booleanValue1._active*/, + fmi2False /*digitalReadBoolean1._y*/, + }, + .fmi2RealParameter = { + 0.002 /*synchronizeRealtime1._actualInterval*/, + }, + .fmi2BooleanParameter = { + fmi2True /*booleanValue1._use_activePort*/, + }, +}; + +#include <math.h> +/* TODO: Generate used builtin functions before SimCode */ +static inline double om_mod(double x, double y) +{ + return x-floor(x/y)*y; +} + +#include "MDDAVRTimer.h" +#include "MDDAVRRealTime.h" +#include "MDDAVRDigital.h" + +static inline fmi2Boolean Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_read(fmi2Component comp, void* om_port, fmi2Integer om_pin); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitRead_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitRead_destructor(fmi2Component comp, void* om_digital); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer); + +static inline fmi2Boolean Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_read(fmi2Component comp, void* om_port, fmi2Integer om_pin) +{ + fmi2Boolean om_b; + om_b = MDD_avr_digital_pin_read(om_port, om_pin); + return om_b; +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitRead_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin) +{ + void* om_dig; + om_dig = MDD_avr_digital_pin_init(om_port, om_pin, fmi2False); + return om_dig; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitRead_destructor(fmi2Component comp, void* om_digital) +{ + MDD_avr_digital_pin_close(om_digital); +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt) +{ + MDD_avr_rt_wait(om_rt); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle) +{ + void* om_rt; + om_rt = MDD_avr_rt_init(om_timer, om_timerValue, om_numTimerInterruptsPerCycle); + return om_rt; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt) +{ + MDD_avr_rt_close(om_rt); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch) +{ + void* om_timer; + om_timer = MDD_avr_timer_init(om_timerSelect, om_clockSelect, om_clearTimerOnMatch); + return om_timer; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer) +{ + MDD_avr_timer_close(om_timer); +} + +fmi2Component push_button_status_fmi2Instantiate(fmi2String name, fmi2Type ty, fmi2String GUID, fmi2String resources, const fmi2CallbackFunctions* functions, fmi2Boolean visible, fmi2Boolean loggingOn) +{ + static int initDone=0; + if (initDone) { + return NULL; + } + return &push_button_status_component; +} + +fmi2Status push_button_status_fmi2SetupExperiment(fmi2Component comp, fmi2Boolean toleranceDefined, fmi2Real tolerance, fmi2Real startTime, fmi2Boolean stopTimeDefined, fmi2Real stopTime) +{ + return fmi2OK; +} + +fmi2Status push_button_status_fmi2EnterInitializationMode(fmi2Component comp) +{ + comp->extObjs[0] /* digitalReadBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitRead */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitRead_constructor(comp, 2, 5); + comp->extObjs[1] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(comp, 1, 4, fmi2False); + comp->extObjs[2] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(comp, comp->extObjs[1] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */, 249, 2); + return fmi2OK; +} + +fmi2Status push_button_status_fmi2ExitInitializationMode(fmi2Component comp) +{ + return fmi2OK; +} + +static fmi2Status push_button_status_functionODE(fmi2Component comp) +{ +} + +static fmi2Status push_button_status_functionOutputs(fmi2Component comp) +{ + Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(comp, comp->extObjs[2] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */); +} + +fmi2Status push_button_status_fmi2DoStep(fmi2Component comp, fmi2Real currentCommunicationPoint, fmi2Real communicationStepSize, fmi2Boolean noSetFMUStatePriorToCurrentPoint) +{ + comp->currentTime = currentCommunicationPoint; + /* TODO: Calculate time/state-dependent variables here... */ + push_button_status_functionOutputs(comp); + return fmi2OK; +} + +int main(int argc, char **argv) +{ + int terminateSimulation = 0; + fmi2Status status = fmi2OK; + fmi2CallbackFunctions cbf = { + .logger = NULL, + .allocateMemory = NULL /*calloc*/, + .freeMemory = NULL /*free*/, + .stepFinished = NULL, //synchronous execution + .componentEnvironment = NULL + }; + + fmi2Component comp = push_button_status_fmi2Instantiate("", fmi2CoSimulation, "", "", &cbf, fmi2False, fmi2False); + if (comp==NULL) { + return 1; + } + push_button_status_fmi2SetupExperiment(comp, fmi2False, 0.0, 0.0, fmi2False, 1.0); + push_button_status_fmi2EnterInitializationMode(comp); + // Set start-values? Nah... + push_button_status_fmi2ExitInitializationMode(comp); + + double currentTime = 0.0; + double h = 0.002; + uint32_t i = 0; + + while (status == fmi2OK) { + //retrieve outputs + // fmi2GetReal(m, ..., 1, &y1); + //set inputs + // fmi2SetReal(m, ..., 1, &y2); + + //call slave and check status + status = push_button_status_fmi2DoStep(comp, currentTime, h, fmi2True); + switch (status) { + case fmi2Discard: + case fmi2Error: + case fmi2Fatal: + case fmi2Pending /* Cannot happen */: + terminateSimulation = 1; + break; + case fmi2OK: + case fmi2Warning: + break; + } + if (terminateSimulation) { + break; + } + i++; + /* increment master time */ + currentTime = 0.0 + h*i; + } + +#if 0 + if ((status != fmi2Error) && (status != fmi2Fatal)) { + fmi2Terminate(m); + } + if (status != fmi2Fatal) { + fmi2FreeInstance(m); + } +#endif +} + diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/push/runMDD_led_push_button.mos b/OpenModelica_Arduino_With_MDD/MDD_build/push/runMDD_led_push_button.mos new file mode 100644 index 0000000..f396c9b --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/push/runMDD_led_push_button.mos @@ -0,0 +1,11 @@ +loadModel(Modelica); +getErrorString(); + +loadFile("/home/sumeet/Modelica_DeviceDrivers/package.mo"); +getErrorString(); + +loadFile("/home/sumeet/MDD_Arduino/linux-version-4/OpenModelica-Arduino-MDD_Arduino_Revised/Arduino.mo"); +getErrorString(); + +translateModel(Arduino.SerialCommunication.MDD_Examples.MDD_push.pushTest1, fileNamePrefix="led_push_test"); +getErrorString(); diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/push/runMDD_led_push_button.mos~ b/OpenModelica_Arduino_With_MDD/MDD_build/push/runMDD_led_push_button.mos~ new file mode 100644 index 0000000..f396c9b --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/push/runMDD_led_push_button.mos~ @@ -0,0 +1,11 @@ +loadModel(Modelica); +getErrorString(); + +loadFile("/home/sumeet/Modelica_DeviceDrivers/package.mo"); +getErrorString(); + +loadFile("/home/sumeet/MDD_Arduino/linux-version-4/OpenModelica-Arduino-MDD_Arduino_Revised/Arduino.mo"); +getErrorString(); + +translateModel(Arduino.SerialCommunication.MDD_Examples.MDD_push.pushTest1, fileNamePrefix="led_push_test"); +getErrorString(); diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/push/runMDD_push_button_status.mos b/OpenModelica_Arduino_With_MDD/MDD_build/push/runMDD_push_button_status.mos new file mode 100644 index 0000000..ab3a87e --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/push/runMDD_push_button_status.mos @@ -0,0 +1,11 @@ +loadModel(Modelica); +getErrorString(); + +loadFile("/home/souradip/Modelica_DeviceDrivers/Modelica_DeviceDrivers/package.mo"); +getErrorString(); + +loadFile("/home/souradip/OpenModelica/Arduino.mo"); +getErrorString(); + +translateModel(Arduino.SerialCommunication.MDD_Examples.MDD_push.pushTest1, fileNamePrefix="push_button_test"); +getErrorString(); diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/push/runMDD_push_button_status.mos~ b/OpenModelica_Arduino_With_MDD/MDD_build/push/runMDD_push_button_status.mos~ new file mode 100644 index 0000000..ab3a87e --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/push/runMDD_push_button_status.mos~ @@ -0,0 +1,11 @@ +loadModel(Modelica); +getErrorString(); + +loadFile("/home/souradip/Modelica_DeviceDrivers/Modelica_DeviceDrivers/package.mo"); +getErrorString(); + +loadFile("/home/souradip/OpenModelica/Arduino.mo"); +getErrorString(); + +translateModel(Arduino.SerialCommunication.MDD_Examples.MDD_push.pushTest1, fileNamePrefix="push_button_test"); +getErrorString(); diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/servo/runMDD_servo_init.mos b/OpenModelica_Arduino_With_MDD/MDD_build/servo/runMDD_servo_init.mos new file mode 100644 index 0000000..be5ff81 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/servo/runMDD_servo_init.mos @@ -0,0 +1,11 @@ +loadModel(Modelica); +getErrorString(); + +loadFile("/home/souradip/Modelica_DeviceDrivers/Modelica_DeviceDrivers/package.mo"); +getErrorString(); + +loadFile("/home/souradip/OpenModelica/Arduino.mo"); +getErrorString(); + +translateModel(Arduino.SerialCommunication.MDD_Examples.MDD_servo.MDD_servo_init, fileNamePrefix="servo_init"); +getErrorString(); diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/servo/runMDD_servo_loop.mos b/OpenModelica_Arduino_With_MDD/MDD_build/servo/runMDD_servo_loop.mos new file mode 100644 index 0000000..23b035f --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/servo/runMDD_servo_loop.mos @@ -0,0 +1,11 @@ +loadModel(Modelica); +getErrorString(); + +loadFile("/home/souradip/Modelica_DeviceDrivers/Modelica_DeviceDrivers/package.mo"); +getErrorString(); + +loadFile("/home/souradip/OpenModelica/Arduino.mo"); +getErrorString(); + +translateModel(Arduino.SerialCommunication.MDD_Examples.MDD_servo.MDD_servo_loop, fileNamePrefix="servo_loop"); +getErrorString(); diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/servo/runMDD_servo_pot.mos b/OpenModelica_Arduino_With_MDD/MDD_build/servo/runMDD_servo_pot.mos new file mode 100644 index 0000000..a7e6ac1 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/servo/runMDD_servo_pot.mos @@ -0,0 +1,11 @@ +loadModel(Modelica); +getErrorString(); + +loadFile("/home/souradip/Modelica_DeviceDrivers/Modelica_DeviceDrivers/package.mo"); +getErrorString(); + +loadFile("/home/souradip/OpenModelica/Arduino.mo"); +getErrorString(); + +translateModel(Arduino.SerialCommunication.MDD_Examples.MDD_servo.MDD_servo_pot, fileNamePrefix="servo_pot"); +getErrorString(); diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/servo/runMDD_servo_reverse.mos b/OpenModelica_Arduino_With_MDD/MDD_build/servo/runMDD_servo_reverse.mos new file mode 100644 index 0000000..4d6b950 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/servo/runMDD_servo_reverse.mos @@ -0,0 +1,11 @@ +loadModel(Modelica); +getErrorString(); + +loadFile("/home/souradip/Modelica_DeviceDrivers/Modelica_DeviceDrivers/package.mo"); +getErrorString(); + +loadFile("/home/souradip/OpenModelica/Arduino.mo"); +getErrorString(); + +translateModel(Arduino.SerialCommunication.MDD_Examples.MDD_servo.MDD_servo_reverse, fileNamePrefix="servo_reverse"); +getErrorString(); diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/servo/servo_init b/OpenModelica_Arduino_With_MDD/MDD_build/servo/servo_init Binary files differnew file mode 100644 index 0000000..ba1b63b --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/servo/servo_init diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/servo/servo_init.hex b/OpenModelica_Arduino_With_MDD/MDD_build/servo/servo_init.hex new file mode 100644 index 0000000..667f2cc --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/servo/servo_init.hex @@ -0,0 +1,94 @@ +:100000000C9434000C9451000C9451000C94510049
+:100010000C9451000C9451000C9451000C94E50088
+:100020000C9451000C9451000C9451000C94B400A9
+:100030000C9451000C9451000C9483000C945100CA
+:100040000C9451000C9451000C9451000C945100EC
+:100050000C9451000C9451000C9451000C945100DC
+:100060000C9451000C94510011241FBECFEFD8E026
+:10007000DEBFCDBF11E0A0E0B1E0E6EAF5E002C0EE
+:1000800005900D92A231B107D9F711E0A2E1B1E0DC
+:1000900001C01D92A731B107E1F70E9443010C9402
+:1000A000D1020C9400008230910561F083309105FB
+:1000B00099F00197C9F416BC80916E00826080931C
+:1000C0006E0016C0109285001092840080916F001F
+:1000D000826080936F000CC01092B200809170001B
+:1000E00082608093700004C081E090E00E94D102A1
+:1000F00078949FB7F894809114019FBF8823C9F327
+:100100001092140108951F920F920FB60F921124AE
+:100110002F933F938F939F9380911201909113019E
+:100120000196909313018093120180911401813004
+:1001300091F020911201309113018091150190915D
+:1001400016012817390738F081E0809314011092C6
+:100150001301109212019F918F913F912F910F9057
+:100160000FBE0F901F9018951F920F920FB60F920F
+:1001700011242F933F938F939F938091120190911D
+:100180001301019690931301809312018091140141
+:10019000813091F02091120130911301809115016D
+:1001A000909116012817390738F081E080931401E7
+:1001B00010921301109212019F918F913F912F91F4
+:1001C0000F900FBE0F901F9018951F920F920FB6B1
+:1001D0000F9211242F933F938F939F93809112013D
+:1001E00090911301019690931301809312018091D5
+:1001F0001401813091F0209112013091130180910E
+:100200001501909116012817390738F081E0809385
+:10021000140110921301109212019F918F913F913E
+:100220002F910F900FBE0F901F901895FC01A1E821
+:10023000B0E08C918D608C9322E030E03387228790
+:10024000219AA0E8B0E08C9181688C93A8E8B0E096
+:1002500011961C921E921C92B587A48785B5836067
+:1002600085BD81E090E097878687309316012093C3
+:10027000150124B5226024BD29EF27BD918B808B09
+:1002800080E090E00895CF92DF92EF92FF92CF93BB
+:1002900080E091E00E941601C12CD12C760160E033
+:1002A00070E0CB01CEE16093000170930101809377
+:1002B00002019093030180911001909111010E941D
+:1002C0005300E0910C01F0910D01C0838FEFC81A2B
+:1002D000D80AE80AF80AC701B6010E94E0012FE631
+:1002E00032E143E05BE30E946E0220E030E0A901CE
+:1002F0000E947C01D8CF5058BB27AA270ED0B4C08B
+:10030000A5D030F0AAD020F031F49F3F11F41EF4B4
+:100310009AC00EF4E095E7FB90C0E92FB6D080F3C9
+:10032000BA17620773078407950718F071F49EF5F2
+:10033000CEC00EF4E0950B2EBA2FA02D0B01B90103
+:1003400090010C01CA01A0011124FF27591B99F04B
+:10035000593F50F4503E68F11A16F040A22F232F57
+:10036000342F4427585FF3CF469537952795A795A7
+:10037000F0405395C9F77EF41F16BA0B620B730B4E
+:10038000840BBAF09150A1F0FF0FBB1F661F771FBF
+:10039000881FC2F70EC0BA0F621F731F841F48F474
+:1003A000879577956795B795F7959E3F08F0B3CFFA
+:1003B0009395880F08F09927EE0F979587950895E4
+:1003C000E89409C097FB3EF49095809570956195EF
+:1003D0007F4F8F4F9F4F9923A9F0F92F96E9BB27A5
+:1003E0009395F695879577956795B795F111F8CF21
+:1003F000FAF4BB0F11F460FF1BC06F5F7F4F8F4F8C
+:100400009F4F16C0882311F096E911C0772321F081
+:100410009EE8872F762F05C0662371F096E8862F19
+:1004200070E060E02AF09A95660F771F881FDAF770
+:10043000880F9695879597F9089597F99F6780E8B3
+:1004400070E060E008959FEF80EC089500240A9426
+:100450001616170618060906089500240A9412169F
+:100460001306140605060895092E0394000C11F4D2
+:10047000882352F0BB0F40F4BF2B11F460FF04C07F
+:100480006F5F7F4F8F4F9F4F089557FD9058440FD8
+:10049000551F59F05F3F71F04795880F97FB991FE3
+:1004A00061F09F3F79F087950895121613061406A0
+:1004B000551FF2CF4695F1DF08C01616170618062D
+:1004C000991FF1CF86957105610508940895E89408
+:1004D000BB2766277727CB0197F908950BD0C4CFA8
+:1004E000B5DF28F0BADF18F0952309F0A6CFABCF1F
+:1004F0001124EECFCADFA0F3959FD1F3950F50E002
+:10050000551F629FF001729FBB27F00DB11D639FC5
+:10051000AA27F00DB11DAA1F649F6627B00DA11D6B
+:10052000661F829F2227B00DA11D621F739FB00D11
+:10053000A11D621F839FA00D611D221F749F332781
+:10054000A00D611D231F849F600D211D822F762F1A
+:100550006A2F11249F5750408AF0E1F088234AF017
+:10056000EE0FFF1FBB1F661F771F881F9150504063
+:10057000A9F79E3F510570F060CFAACF5F3FECF323
+:10058000983EDCF3869577956795B795F795E7954F
+:100590009F5FC1F7FE2B880F911D9695879597F960
+:0605A0000895F894FFCF5E
+:1005A6000000000000006F12033B00000000000086
+:0205B600000043
+:00000001FF
diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/servo/servo_init.sh b/OpenModelica_Arduino_With_MDD/MDD_build/servo/servo_init.sh new file mode 100644 index 0000000..a8c1413 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/servo/servo_init.sh @@ -0,0 +1,61 @@ +#!/bin/bash +clear +if [ "$#" -ne 2 ]; then + echo "Usage: $0 port baudrate" >&2 + exit 1 +fi + +re='^[0-9]+$' +if ! [[ $1 =~ $re ]] ; then + echo "error: $1 -> Not a number" >&2; exit 1 +fi + +if ! [[ $2 =~ $re ]] ; then + echo "error: $2-> Not a number" >&2; exit 1 +fi + +b_rate=$2 + +present=`pwd` +unamestr=`uname` + +if [[ "$unamestr" == 'Linux' ]]; then + mdd_path=($(locate Modelica_DeviceDrivers/Modelica_DeviceDrivers/Resources/Include)) + om_path=($(locate /usr/include/omc/c)) + port="/dev/ttyACM$1" + omc --simCodeTarget=ExperimentalEmbeddedC runMDD_servo_init.mos + if [ $? -ne 0 ]; then + exit 1 + fi +else + cd c: + om_path=($(dir -d OpenModelica*/include/omc/c/)) + path_to_om="C:$om_path" + cd f: + mdd_path=($(dir -d */Modelica_DeviceDrivers/Modelica_DeviceDrivers/Resources/Include/)) + if [ $? -eq 0 ]; then + path_to_mdd="F:/$mdd_path" + else + exit 1 + fi + + port="COM$1" + cd $present + omc --simCodeTarget=ExperimentalEmbeddedC run_servo_init.mos + if [ $? -ne 0 ]; then + exit 1 + fi +fi + +avr-gcc -Os -std=c11 -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000UL -Wl,--gc-sections servo_init_main.c -o servo_init -I${mdd_path[0]} -I${path_to_om} -I${path_to_mdd} -I${om_path[0]} +if [ $? -ne 0 ]; then + exit 1 +fi +avr-objcopy -O ihex -R .eeprom servo_init servo_init.hex +if [ $? -ne 0 ]; then + exit 1 +fi +avrdude -F -V -c arduino -p ATMEGA328P -P $port -b $b_rate -U flash:w:servo_init.hex +if [ $? -ne 0 ]; then + exit 1 +fi
\ No newline at end of file diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/servo/servo_init_main.c b/OpenModelica_Arduino_With_MDD/MDD_build/servo/servo_init_main.c new file mode 100644 index 0000000..b10d9af --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/servo/servo_init_main.c @@ -0,0 +1,213 @@ +#define fmi2TypesPlatform_h + +#define fmi2TypesPlatform "default" /* Compatible */ + +typedef struct servo_init_fmi2Component_s* fmi2Component; +typedef void* fmi2ComponentEnvironment; /* Pointer to FMU environment */ +typedef void* fmi2FMUstate; /* Pointer to internal FMU state */ +typedef unsigned int fmi2ValueReference; +typedef double fmi2Real; +typedef int fmi2Integer; +typedef int fmi2Boolean; +typedef char fmi2Char; +typedef const fmi2Char* fmi2String; +typedef char fmi2Byte; + +#define fmi2True 1 +#define fmi2False 0 + +#include "fmi2/fmi2Functions.h" + +#include <stdint.h> +#include <stdio.h> + +void ModelicaFormatMessage(const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + vprintf(fmt, args); + va_end(args); +} + +typedef struct servo_init_fmi2Component_s { + fmi2Real currentTime; + fmi2Integer fmi2IntegerVars[1]; + fmi2Real fmi2RealParameter[1]; + void* extObjs[4]; +} servo_init_fmi2Component; + +servo_init_fmi2Component servo_init_component = { + .fmi2IntegerVars = { + 0 /*integerExpression1._y*/, + }, + .fmi2RealParameter = { + 0.002 /*synchronizeRealtime1._actualInterval*/, + }, +}; + +#include <math.h> +/* TODO: Generate used builtin functions before SimCode */ +static inline double om_mod(double x, double y) +{ + return x-floor(x/y)*y; +} + +#include "MDDAVRTimer.h" +#include "MDDAVRRealTime.h" +#include "MDDAVRAnalog.h" + +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_set(fmi2Component comp, void* om_pwm, fmi2Integer om_value); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_pin, fmi2Integer om_initialValue, fmi2Boolean om_inverted); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_Init_destructor(fmi2Component comp, void* om_pwm); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer); + +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_set(fmi2Component comp, void* om_pwm, fmi2Integer om_value) +{ + MDD_avr_pwm_set(om_pwm, om_value); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_pin, fmi2Integer om_initialValue, fmi2Boolean om_inverted) +{ + void* om_pwm; + om_pwm = MDD_avr_pwm_init(om_timer, om_pin, om_initialValue, om_inverted); + return om_pwm; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_Init_destructor(fmi2Component comp, void* om_pwm) +{ + MDD_avr_pwm_close(om_pwm); +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt) +{ + MDD_avr_rt_wait(om_rt); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle) +{ + void* om_rt; + om_rt = MDD_avr_rt_init(om_timer, om_timerValue, om_numTimerInterruptsPerCycle); + return om_rt; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt) +{ + MDD_avr_rt_close(om_rt); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch) +{ + void* om_timer; + om_timer = MDD_avr_timer_init(om_timerSelect, om_clockSelect, om_clearTimerOnMatch); + return om_timer; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer) +{ + MDD_avr_timer_close(om_timer); +} + +fmi2Component servo_init_fmi2Instantiate(fmi2String name, fmi2Type ty, fmi2String GUID, fmi2String resources, const fmi2CallbackFunctions* functions, fmi2Boolean visible, fmi2Boolean loggingOn) +{ + static int initDone=0; + if (initDone) { + return NULL; + } + return &servo_init_component; +} + +fmi2Status servo_init_fmi2SetupExperiment(fmi2Component comp, fmi2Boolean toleranceDefined, fmi2Real tolerance, fmi2Real startTime, fmi2Boolean stopTimeDefined, fmi2Real stopTime) +{ + return fmi2OK; +} + +fmi2Status servo_init_fmi2EnterInitializationMode(fmi2Component comp) +{ + comp->extObjs[0] /* pwm._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(comp, 2, 7, fmi2True); + comp->extObjs[1] /* pwm._pwm[1] EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.PWM.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_Init_constructor(comp, comp->extObjs[0] /* pwm._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */, 1, 0, fmi2False); + comp->extObjs[2] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(comp, 1, 4, fmi2False); + comp->extObjs[3] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(comp, comp->extObjs[2] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */, 249, 2); + return fmi2OK; +} + +fmi2Status servo_init_fmi2ExitInitializationMode(fmi2Component comp) +{ + return fmi2OK; +} + +static fmi2Status servo_init_functionODE(fmi2Component comp) +{ +} + +static fmi2Status servo_init_functionOutputs(fmi2Component comp) +{ + Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(comp, comp->extObjs[3] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */);Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_set(comp, comp->extObjs[1] /* pwm._pwm[1] EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.PWM.Init */, 30); +} + +fmi2Status servo_init_fmi2DoStep(fmi2Component comp, fmi2Real currentCommunicationPoint, fmi2Real communicationStepSize, fmi2Boolean noSetFMUStatePriorToCurrentPoint) +{ + comp->currentTime = currentCommunicationPoint; + /* TODO: Calculate time/state-dependent variables here... */ + servo_init_functionOutputs(comp); + return fmi2OK; +} + +int main(int argc, char **argv) +{ + int terminateSimulation = 0; + fmi2Status status = fmi2OK; + fmi2CallbackFunctions cbf = { + .logger = NULL, + .allocateMemory = NULL /*calloc*/, + .freeMemory = NULL /*free*/, + .stepFinished = NULL, //synchronous execution + .componentEnvironment = NULL + }; + + fmi2Component comp = servo_init_fmi2Instantiate("", fmi2CoSimulation, "", "", &cbf, fmi2False, fmi2False); + if (comp==NULL) { + return 1; + } + servo_init_fmi2SetupExperiment(comp, fmi2False, 0.0, 0.0, fmi2False, 1.0); + servo_init_fmi2EnterInitializationMode(comp); + // Set start-values? Nah... + servo_init_fmi2ExitInitializationMode(comp); + + double currentTime = 0.0; + double h = 0.002; + uint32_t i = 0; + + while (status == fmi2OK) { + //retrieve outputs + // fmi2GetReal(m, ..., 1, &y1); + //set inputs + // fmi2SetReal(m, ..., 1, &y2); + + //call slave and check status + status = servo_init_fmi2DoStep(comp, currentTime, h, fmi2True); + switch (status) { + case fmi2Discard: + case fmi2Error: + case fmi2Fatal: + case fmi2Pending /* Cannot happen */: + terminateSimulation = 1; + break; + case fmi2OK: + case fmi2Warning: + break; + } + if (terminateSimulation) { + break; + } + i++; + /* increment master time */ + currentTime = 0.0 + h*i; + } + +#if 0 + if ((status != fmi2Error) && (status != fmi2Fatal)) { + fmi2Terminate(m); + } + if (status != fmi2Fatal) { + fmi2FreeInstance(m); + } +#endif +} + diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/servo/servo_loop.sh b/OpenModelica_Arduino_With_MDD/MDD_build/servo/servo_loop.sh new file mode 100644 index 0000000..4be3b84 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/servo/servo_loop.sh @@ -0,0 +1,61 @@ +#!/bin/bash +clear +if [ "$#" -ne 2 ]; then + echo "Usage: $0 port baudrate" >&2 + exit 1 +fi + +re='^[0-9]+$' +if ! [[ $1 =~ $re ]] ; then + echo "error: $1 -> Not a number" >&2; exit 1 +fi + +if ! [[ $2 =~ $re ]] ; then + echo "error: $2-> Not a number" >&2; exit 1 +fi + +b_rate=$2 + +present=`pwd` +unamestr=`uname` + +if [[ "$unamestr" == 'Linux' ]]; then + mdd_path=($(locate Modelica_DeviceDrivers/Modelica_DeviceDrivers/Resources/Include)) + om_path=($(locate /usr/include/omc/c)) + port="/dev/ttyACM$1" + omc --simCodeTarget=ExperimentalEmbeddedC runMDD_servo_loop.mos + if [ $? -ne 0 ]; then + exit 1 + fi +else + cd c: + om_path=($(dir -d OpenModelica*/include/omc/c/)) + path_to_om="C:$om_path" + cd f: + mdd_path=($(dir -d */Modelica_DeviceDrivers/Modelica_DeviceDrivers/Resources/Include/)) + if [ $? -eq 0 ]; then + path_to_mdd="F:/$mdd_path" + else + exit 1 + fi + + port="COM$1" + cd $present + omc --simCodeTarget=ExperimentalEmbeddedC run_servo_loop.mos + if [ $? -ne 0 ]; then + exit 1 + fi +fi + +avr-gcc -Os -std=c11 -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000UL -Wl,--gc-sections servo_loop_main.c -o servo_loop -I${mdd_path[0]} -I${path_to_om} -I${path_to_mdd} -I${om_path[0]} +if [ $? -ne 0 ]; then + exit 1 +fi +avr-objcopy -O ihex -R .eeprom servo_loop servo_loop.hex +if [ $? -ne 0 ]; then + exit 1 +fi +avrdude -F -V -c arduino -p ATMEGA328P -P $port -b $b_rate -U flash:w:servo_loop.hex +if [ $? -ne 0 ]; then + exit 1 +fi
\ No newline at end of file diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/servo/servo_loop_main.c b/OpenModelica_Arduino_With_MDD/MDD_build/servo/servo_loop_main.c new file mode 100644 index 0000000..2eb1630 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/servo/servo_loop_main.c @@ -0,0 +1,235 @@ +#define fmi2TypesPlatform_h + +#define fmi2TypesPlatform "default" /* Compatible */ + +typedef struct servo_loop_fmi2Component_s* fmi2Component; +typedef void* fmi2ComponentEnvironment; /* Pointer to FMU environment */ +typedef void* fmi2FMUstate; /* Pointer to internal FMU state */ +typedef unsigned int fmi2ValueReference; +typedef double fmi2Real; +typedef int fmi2Integer; +typedef int fmi2Boolean; +typedef char fmi2Char; +typedef const fmi2Char* fmi2String; +typedef char fmi2Byte; + +#define fmi2True 1 +#define fmi2False 0 + +#include "fmi2/fmi2Functions.h" + +#include <stdint.h> +#include <stdio.h> + +void ModelicaFormatMessage(const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + vprintf(fmt, args); + va_end(args); +} + +typedef struct servo_loop_fmi2Component_s { + fmi2Real currentTime; + fmi2Integer fmi2IntegerVars[3]; + fmi2Boolean fmi2BooleanVars[3]; + fmi2Real fmi2RealParameter[1]; + fmi2Integer fmi2IntegerParameter[1]; + fmi2Boolean fmi2BooleanParameter[2]; + fmi2String fmi2StringParameter[1]; + void* extObjs[4]; +} servo_loop_fmi2Component; + +servo_loop_fmi2Component servo_loop_component = { + .fmi2IntegerVars = { + 0 /*integerExpression1._y*/, + 0 /*triggeredAdd1._local_set*/, + 0 /*triggeredAdd1._y*/, + }, + .fmi2BooleanVars = { + fmi2False /*$whenCondition1*/, + fmi2False /*booleanExpression1._y*/, + fmi2False /*triggeredAdd1._local_reset*/, + }, + .fmi2RealParameter = { + 0.002 /*synchronizeRealtime1._actualInterval*/, + }, + .fmi2IntegerParameter = { + 0 /*triggeredAdd1._y_start*/, + }, + .fmi2BooleanParameter = { + fmi2False /*triggeredAdd1._use_reset*/, + fmi2False /*triggeredAdd1._use_set*/, + }, +}; + +#include <math.h> +/* TODO: Generate used builtin functions before SimCode */ +static inline double om_mod(double x, double y) +{ + return x-floor(x/y)*y; +} + +#include "MDDAVRTimer.h" +#include "MDDAVRRealTime.h" +#include "MDDAVRAnalog.h" + +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_set(fmi2Component comp, void* om_pwm, fmi2Integer om_value); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_pin, fmi2Integer om_initialValue, fmi2Boolean om_inverted); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_Init_destructor(fmi2Component comp, void* om_pwm); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer); + +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_set(fmi2Component comp, void* om_pwm, fmi2Integer om_value) +{ + MDD_avr_pwm_set(om_pwm, om_value); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_pin, fmi2Integer om_initialValue, fmi2Boolean om_inverted) +{ + void* om_pwm; + om_pwm = MDD_avr_pwm_init(om_timer, om_pin, om_initialValue, om_inverted); + return om_pwm; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_Init_destructor(fmi2Component comp, void* om_pwm) +{ + MDD_avr_pwm_close(om_pwm); +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt) +{ + MDD_avr_rt_wait(om_rt); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle) +{ + void* om_rt; + om_rt = MDD_avr_rt_init(om_timer, om_timerValue, om_numTimerInterruptsPerCycle); + return om_rt; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt) +{ + MDD_avr_rt_close(om_rt); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch) +{ + void* om_timer; + om_timer = MDD_avr_timer_init(om_timerSelect, om_clockSelect, om_clearTimerOnMatch); + return om_timer; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer) +{ + MDD_avr_timer_close(om_timer); +} + +fmi2Component servo_loop_fmi2Instantiate(fmi2String name, fmi2Type ty, fmi2String GUID, fmi2String resources, const fmi2CallbackFunctions* functions, fmi2Boolean visible, fmi2Boolean loggingOn) +{ + static int initDone=0; + if (initDone) { + return NULL; + } + return &servo_loop_component; +} + +fmi2Status servo_loop_fmi2SetupExperiment(fmi2Component comp, fmi2Boolean toleranceDefined, fmi2Real tolerance, fmi2Real startTime, fmi2Boolean stopTimeDefined, fmi2Real stopTime) +{ + return fmi2OK; +} + +fmi2Status servo_loop_fmi2EnterInitializationMode(fmi2Component comp) +{ + comp->extObjs[0] /* pwm._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(comp, 2, 7, fmi2True); + comp->extObjs[1] /* pwm._pwm[1] EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.PWM.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_Init_constructor(comp, comp->extObjs[0] /* pwm._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */, 1, 0, fmi2False); + comp->extObjs[2] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(comp, 1, 4, fmi2False); + comp->extObjs[3] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(comp, comp->extObjs[2] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */, 249, 2); + return fmi2OK; +} + +fmi2Status servo_loop_fmi2ExitInitializationMode(fmi2Component comp) +{ + return fmi2OK; +} + +static fmi2Status servo_loop_functionODE(fmi2Component comp) +{ +} + +static fmi2Status servo_loop_functionOutputs(fmi2Component comp) +{ + comp->fmi2BooleanVars[0] /* $whenCondition1 DISCRETE */ = (om_mod(comp->currentTime,0.2))>(0.1); /* equation 9 */ + + #error "[CodegenEmbeddedC.tpl:346:14-346:14] Unsupported equation: ..." + + comp->fmi2BooleanVars[1] /* booleanExpression1._y DISCRETE */ = comp->fmi2BooleanVars[0] /* $whenCondition1 DISCRETE */; /* equation 11 */Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(comp, comp->extObjs[3] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */);Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_set(comp, comp->extObjs[1] /* pwm._pwm[1] EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.PWM.Init */, comp->fmi2IntegerVars[2] /* triggeredAdd1._y DISCRETE */); +} + +fmi2Status servo_loop_fmi2DoStep(fmi2Component comp, fmi2Real currentCommunicationPoint, fmi2Real communicationStepSize, fmi2Boolean noSetFMUStatePriorToCurrentPoint) +{ + comp->currentTime = currentCommunicationPoint; + /* TODO: Calculate time/state-dependent variables here... */ + servo_loop_functionOutputs(comp); + return fmi2OK; +} + +int main(int argc, char **argv) +{ + int terminateSimulation = 0; + fmi2Status status = fmi2OK; + fmi2CallbackFunctions cbf = { + .logger = NULL, + .allocateMemory = NULL /*calloc*/, + .freeMemory = NULL /*free*/, + .stepFinished = NULL, //synchronous execution + .componentEnvironment = NULL + }; + + fmi2Component comp = servo_loop_fmi2Instantiate("", fmi2CoSimulation, "", "", &cbf, fmi2False, fmi2False); + if (comp==NULL) { + return 1; + } + servo_loop_fmi2SetupExperiment(comp, fmi2False, 0.0, 0.0, fmi2False, 1.0); + servo_loop_fmi2EnterInitializationMode(comp); + // Set start-values? Nah... + servo_loop_fmi2ExitInitializationMode(comp); + + double currentTime = 0.0; + double h = 0.002; + uint32_t i = 0; + + while (status == fmi2OK) { + //retrieve outputs + // fmi2GetReal(m, ..., 1, &y1); + //set inputs + // fmi2SetReal(m, ..., 1, &y2); + + //call slave and check status + status = servo_loop_fmi2DoStep(comp, currentTime, h, fmi2True); + switch (status) { + case fmi2Discard: + case fmi2Error: + case fmi2Fatal: + case fmi2Pending /* Cannot happen */: + terminateSimulation = 1; + break; + case fmi2OK: + case fmi2Warning: + break; + } + if (terminateSimulation) { + break; + } + i++; + /* increment master time */ + currentTime = 0.0 + h*i; + } + +#if 0 + if ((status != fmi2Error) && (status != fmi2Fatal)) { + fmi2Terminate(m); + } + if (status != fmi2Fatal) { + fmi2FreeInstance(m); + } +#endif +} + diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/servo/servo_pot.sh b/OpenModelica_Arduino_With_MDD/MDD_build/servo/servo_pot.sh new file mode 100644 index 0000000..41f9d90 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/servo/servo_pot.sh @@ -0,0 +1,61 @@ +#!/bin/bash +clear +if [ "$#" -ne 2 ]; then + echo "Usage: $0 port baudrate" >&2 + exit 1 +fi + +re='^[0-9]+$' +if ! [[ $1 =~ $re ]] ; then + echo "error: $1 -> Not a number" >&2; exit 1 +fi + +if ! [[ $2 =~ $re ]] ; then + echo "error: $2-> Not a number" >&2; exit 1 +fi + +b_rate=$2 + +present=`pwd` +unamestr=`uname` + +if [[ "$unamestr" == 'Linux' ]]; then + mdd_path=($(locate Modelica_DeviceDrivers/Modelica_DeviceDrivers/Resources/Include)) + om_path=($(locate /usr/include/omc/c)) + port="/dev/ttyACM$1" + omc --simCodeTarget=ExperimentalEmbeddedC runMDD_servo_pot.mos + if [ $? -ne 0 ]; then + exit 1 + fi +else + cd c: + om_path=($(dir -d OpenModelica*/include/omc/c/)) + path_to_om="C:$om_path" + cd f: + mdd_path=($(dir -d */Modelica_DeviceDrivers/Modelica_DeviceDrivers/Resources/Include/)) + if [ $? -eq 0 ]; then + path_to_mdd="F:/$mdd_path" + else + exit 1 + fi + + port="COM$1" + cd $present + omc --simCodeTarget=ExperimentalEmbeddedC run_servo_pot.mos + if [ $? -ne 0 ]; then + exit 1 + fi +fi + +avr-gcc -Os -std=c11 -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000UL -Wl,--gc-sections servo_pot_main.c -o servo_pot -I${mdd_path[0]} -I${path_to_om} -I${path_to_mdd} -I${om_path[0]} +if [ $? -ne 0 ]; then + exit 1 +fi +avr-objcopy -O ihex -R .eeprom servo_pot servo_pot.hex +if [ $? -ne 0 ]; then + exit 1 +fi +avrdude -F -V -c arduino -p ATMEGA328P -P $port -b $b_rate -U flash:w:servo_pot.hex +if [ $? -ne 0 ]; then + exit 1 +fi
\ No newline at end of file diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/servo/servo_pot_main.c b/OpenModelica_Arduino_With_MDD/MDD_build/servo/servo_pot_main.c new file mode 100644 index 0000000..4cb1705 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/servo/servo_pot_main.c @@ -0,0 +1,244 @@ +#define fmi2TypesPlatform_h + +#define fmi2TypesPlatform "default" /* Compatible */ + +typedef struct servo_pot_fmi2Component_s* fmi2Component; +typedef void* fmi2ComponentEnvironment; /* Pointer to FMU environment */ +typedef void* fmi2FMUstate; /* Pointer to internal FMU state */ +typedef unsigned int fmi2ValueReference; +typedef double fmi2Real; +typedef int fmi2Integer; +typedef int fmi2Boolean; +typedef char fmi2Char; +typedef const fmi2Char* fmi2String; +typedef char fmi2Byte; + +#define fmi2True 1 +#define fmi2False 0 + +#include "fmi2/fmi2Functions.h" + +#include <stdint.h> +#include <stdio.h> + +void ModelicaFormatMessage(const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + vprintf(fmt, args); + va_end(args); +} + +typedef struct servo_pot_fmi2Component_s { + fmi2Real currentTime; + fmi2Real fmi2RealVars[1]; + fmi2Integer fmi2IntegerVars[1]; + fmi2Real fmi2RealParameter[1]; + void* extObjs[5]; +} servo_pot_fmi2Component; + +servo_pot_fmi2Component servo_pot_component = { + .fmi2RealVars = { + 0.0 /*adc._y*/, + }, + .fmi2IntegerVars = { + 0 /*pwm._u[1]*/, + }, + .fmi2RealParameter = { + 0.002 /*synchronizeRealtime1._actualInterval*/, + }, +}; + +#include <math.h> +/* TODO: Generate used builtin functions before SimCode */ +static inline double om_mod(double x, double y) +{ + return x-floor(x/y)*y; +} + +static const char * const OMCLIT0 = "ElectricPotential"; +static const char * const OMCLIT1 = "V"; +#include "MDDAVRTimer.h" +#include "MDDAVRRealTime.h" +#include "MDDAVRAnalog.h" + +static inline fmi2Real Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_read__voltage(fmi2Component comp, fmi2Integer om_analogPort, fmi2Real om_vref, fmi2Integer om_voltageResolution); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_constructor(fmi2Component comp, fmi2Integer om_divisionFactor, fmi2Integer om_referenceVoltage); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_destructor(fmi2Component comp, void* om_avr); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_set(fmi2Component comp, void* om_pwm, fmi2Integer om_value); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_pin, fmi2Integer om_initialValue, fmi2Boolean om_inverted); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_Init_destructor(fmi2Component comp, void* om_pwm); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer); + +static inline fmi2Real Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_read__voltage(fmi2Component comp, fmi2Integer om_analogPort, fmi2Real om_vref, fmi2Integer om_voltageResolution) +{ + fmi2Real om_value; + om_value = MDD_avr_analog_read(om_analogPort, om_vref, om_voltageResolution); + return om_value; +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_constructor(fmi2Component comp, fmi2Integer om_divisionFactor, fmi2Integer om_referenceVoltage) +{ + void* om_avr; + om_avr = MDD_avr_analog_init(om_divisionFactor, om_referenceVoltage); + return om_avr; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_destructor(fmi2Component comp, void* om_avr) +{ + MDD_avr_analog_close(om_avr); +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_set(fmi2Component comp, void* om_pwm, fmi2Integer om_value) +{ + MDD_avr_pwm_set(om_pwm, om_value); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_pin, fmi2Integer om_initialValue, fmi2Boolean om_inverted) +{ + void* om_pwm; + om_pwm = MDD_avr_pwm_init(om_timer, om_pin, om_initialValue, om_inverted); + return om_pwm; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_Init_destructor(fmi2Component comp, void* om_pwm) +{ + MDD_avr_pwm_close(om_pwm); +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt) +{ + MDD_avr_rt_wait(om_rt); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle) +{ + void* om_rt; + om_rt = MDD_avr_rt_init(om_timer, om_timerValue, om_numTimerInterruptsPerCycle); + return om_rt; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt) +{ + MDD_avr_rt_close(om_rt); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch) +{ + void* om_timer; + om_timer = MDD_avr_timer_init(om_timerSelect, om_clockSelect, om_clearTimerOnMatch); + return om_timer; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer) +{ + MDD_avr_timer_close(om_timer); +} + +fmi2Component servo_pot_fmi2Instantiate(fmi2String name, fmi2Type ty, fmi2String GUID, fmi2String resources, const fmi2CallbackFunctions* functions, fmi2Boolean visible, fmi2Boolean loggingOn) +{ + static int initDone=0; + if (initDone) { + return NULL; + } + return &servo_pot_component; +} + +fmi2Status servo_pot_fmi2SetupExperiment(fmi2Component comp, fmi2Boolean toleranceDefined, fmi2Real tolerance, fmi2Real startTime, fmi2Boolean stopTimeDefined, fmi2Real stopTime) +{ + return fmi2OK; +} + +fmi2Status servo_pot_fmi2EnterInitializationMode(fmi2Component comp) +{ + comp->extObjs[1] /* pwm._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(comp, 2, 7, fmi2True); + comp->extObjs[2] /* pwm._pwm[1] EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.PWM.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_Init_constructor(comp, comp->extObjs[1] /* pwm._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */, 1, 0, fmi2False); + comp->extObjs[0] /* adc._analog EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Analog.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_constructor(comp, 7, 4); + comp->extObjs[3] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(comp, 1, 4, fmi2False); + comp->extObjs[4] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(comp, comp->extObjs[3] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */, 249, 2); + return fmi2OK; +} + +fmi2Status servo_pot_fmi2ExitInitializationMode(fmi2Component comp) +{ + return fmi2OK; +} + +static fmi2Status servo_pot_functionODE(fmi2Component comp) +{ +} + +static fmi2Status servo_pot_functionOutputs(fmi2Component comp) +{ + comp->fmi2RealVars[0] /* adc._y variable */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_read__voltage(comp, 3, 180.0, 10); /* equation 4 */ + comp->fmi2IntegerVars[0] /* pwm._u[1] DISCRETE */ = ((comp->fmi2RealVars[0] /* adc._y variable */)>(0.0)) ? (((int) + #error "[CodegenEmbeddedC.tpl:490:28-490:28] daeExpCallBuiltin: Not supported: floor(0.5 + adc.y, 1)" + )) : (((int) + #error "[CodegenEmbeddedC.tpl:490:28-490:28] daeExpCallBuiltin: Not supported: ceil(-0.5 + adc.y, 3)" + )); /* equation 5 */Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(comp, comp->extObjs[4] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */);Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_set(comp, comp->extObjs[2] /* pwm._pwm[1] EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.PWM.Init */, comp->fmi2IntegerVars[0] /* pwm._u[1] DISCRETE */); +} + +fmi2Status servo_pot_fmi2DoStep(fmi2Component comp, fmi2Real currentCommunicationPoint, fmi2Real communicationStepSize, fmi2Boolean noSetFMUStatePriorToCurrentPoint) +{ + comp->currentTime = currentCommunicationPoint; + /* TODO: Calculate time/state-dependent variables here... */ + servo_pot_functionOutputs(comp); + return fmi2OK; +} + +int main(int argc, char **argv) +{ + int terminateSimulation = 0; + fmi2Status status = fmi2OK; + fmi2CallbackFunctions cbf = { + .logger = NULL, + .allocateMemory = NULL /*calloc*/, + .freeMemory = NULL /*free*/, + .stepFinished = NULL, //synchronous execution + .componentEnvironment = NULL + }; + + fmi2Component comp = servo_pot_fmi2Instantiate("", fmi2CoSimulation, "", "", &cbf, fmi2False, fmi2False); + if (comp==NULL) { + return 1; + } + servo_pot_fmi2SetupExperiment(comp, fmi2False, 0.0, 0.0, fmi2False, 1.0); + servo_pot_fmi2EnterInitializationMode(comp); + // Set start-values? Nah... + servo_pot_fmi2ExitInitializationMode(comp); + + double currentTime = 0.0; + double h = 0.002; + uint32_t i = 0; + + while (status == fmi2OK) { + //retrieve outputs + // fmi2GetReal(m, ..., 1, &y1); + //set inputs + // fmi2SetReal(m, ..., 1, &y2); + + //call slave and check status + status = servo_pot_fmi2DoStep(comp, currentTime, h, fmi2True); + switch (status) { + case fmi2Discard: + case fmi2Error: + case fmi2Fatal: + case fmi2Pending /* Cannot happen */: + terminateSimulation = 1; + break; + case fmi2OK: + case fmi2Warning: + break; + } + if (terminateSimulation) { + break; + } + i++; + /* increment master time */ + currentTime = 0.0 + h*i; + } + +#if 0 + if ((status != fmi2Error) && (status != fmi2Fatal)) { + fmi2Terminate(m); + } + if (status != fmi2Fatal) { + fmi2FreeInstance(m); + } +#endif +} + diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/servo/servo_reverse b/OpenModelica_Arduino_With_MDD/MDD_build/servo/servo_reverse Binary files differnew file mode 100644 index 0000000..67359ad --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/servo/servo_reverse diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/servo/servo_reverse.hex b/OpenModelica_Arduino_With_MDD/MDD_build/servo/servo_reverse.hex new file mode 100644 index 0000000..565bd99 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/servo/servo_reverse.hex @@ -0,0 +1,101 @@ +:100000000C9434000C9451000C9451000C94510049
+:100010000C9451000C9451000C9451000C94E50088
+:100020000C9451000C9451000C9451000C94B400A9
+:100030000C9451000C9451000C9483000C945100CA
+:100040000C9451000C9451000C9451000C945100EC
+:100050000C9451000C9451000C9451000C945100DC
+:100060000C9451000C94510011241FBECFEFD8E026
+:10007000DEBFCDBF11E0A0E0B1E0ECE1F6E002C0F0
+:1000800005900D92A231B107D9F711E0A2E1B1E0DC
+:1000900001C01D92A731B107E1F70E9445010C9400
+:1000A0000C030C9400008230910561F083309105BF
+:1000B00099F00197C9F416BC80916E00826080931C
+:1000C0006E0016C0109285001092840080916F001F
+:1000D000826080936F000CC01092B200809170001B
+:1000E00082608093700004C081E090E00E940C0365
+:1000F00078949FB7F894809114019FBF8823C9F327
+:100100001092140108951F920F920FB60F921124AE
+:100110002F933F938F939F9380911201909113019E
+:100120000196909313018093120180911401813004
+:1001300091F020911201309113018091150190915D
+:1001400016012817390738F081E0809314011092C6
+:100150001301109212019F918F913F912F910F9057
+:100160000FBE0F901F9018951F920F920FB60F920F
+:1001700011242F933F938F939F938091120190911D
+:100180001301019690931301809312018091140141
+:10019000813091F02091120130911301809115016D
+:1001A000909116012817390738F081E080931401E7
+:1001B00010921301109212019F918F913F912F91F4
+:1001C0000F900FBE0F901F9018951F920F920FB6B1
+:1001D0000F9211242F933F938F939F93809112013D
+:1001E00090911301019690931301809312018091D5
+:1001F0001401813091F0209112013091130180910E
+:100200001501909116012817390738F081E0809385
+:10021000140110921301109212019F918F913F913E
+:100220002F910F900FBE0F901F901895FC01A1E821
+:10023000B0E08C918D608C9382E090E09387828710
+:10024000219AA0E8B0E08C9181688C93A8E8B0E096
+:1002500011961C921E921C92B587A48785B5836067
+:1002600085BD81E090E0978786872AE030E0309373
+:1002700016012093150124B5226024BD29EF27BD66
+:10028000918B808B80E090E00895CF92DF92EF9287
+:10029000FF9280E091E00E941601C12CD12C7601E2
+:1002A00060E070E0CB0160930001709301018093E6
+:1002B0000201909303012DEC3CEC4CE45EE30E94C0
+:1002C000F30187FF03C086E190E002C08FE090E079
+:1002D0009093050180930401809110019091110188
+:1002E0000E945300E0910C01F0910D0180910401F6
+:1002F00080838FEFC81AD80AE80AF80AC701B60146
+:100300000E94F7012FE632E143E05BE30E94A9027D
+:1003100020E030E0A9010E948F01C5CF5058BB27D3
+:10032000AA270ED0DCC0CDD030F0D2D020F031F4EE
+:100330009F3F11F41EF4C2C00EF4E095E7FBB8C075
+:10034000E92FDED080F3BA17620773078407950799
+:1003500018F071F49EF5F6C00EF4E0950B2EBA2F4E
+:10036000A02D0B01B90190010C01CA01A0011124BB
+:10037000FF27591B99F0593F50F4503E68F11A1667
+:10038000F040A22F232F342F4427585FF3CF4695F8
+:1003900037952795A795F0405395C9F77EF41F161A
+:1003A000BA0B620B730B840BBAF09150A1F0FF0FE4
+:1003B000BB1F661F771F881FC2F70EC0BA0F621FD0
+:1003C000731F841F48F4879577956795B795F795C0
+:1003D0009E3F08F0B3CF9395880F08F09927EE0F52
+:1003E00097958795089540D008F481E00895E894A2
+:1003F00009C097FB3EF490958095709561957F4F6D
+:100400008F4F9F4F9923A9F0F92F96E9BB2793951A
+:10041000F695879577956795B795F111F8CFFAF42A
+:10042000BB0F11F460FF1BC06F5F7F4F8F4F9F4F5B
+:1004300016C0882311F096E911C0772321F09EE8B9
+:10044000872F762F05C0662371F096E8862F70E01F
+:1004500060E02AF09A95660F771F881FDAF7880FF9
+:100460009695879597F90895990F0008550FAA0B4F
+:10047000E0E8FEEF16161706E807F907C0F01216B7
+:100480001306E407F50798F0621B730B840B950BBA
+:1004900039F40A2661F0232B242B252B21F408950F
+:1004A0000A2609F4A140A6958FEF811D811D0895AC
+:1004B00097F99F6780E870E060E008959FEF80EC17
+:1004C000089500240A9416161706180609060895BA
+:1004D00000240A9412161306140605060895092E20
+:1004E0000394000C11F4882352F0BB0F40F4BF2B8F
+:1004F00011F460FF04C06F5F7F4F8F4F9F4F0895CF
+:1005000057FD9058440F551F59F05F3F71F04795C4
+:10051000880F97FB991F61F09F3F79F087950895A9
+:10052000121613061406551FF2CF4695F1DF08C0C8
+:10053000161617061806991FF1CF869571056105E5
+:1005400008940895E894BB2766277727CB0197F98D
+:1005500008950BD0C4CFB5DF28F0BADF18F095238B
+:1005600009F0A6CFABCF1124EECFCADFA0F3959F41
+:10057000D1F3950F50E0551F629FF001729FBB278A
+:10058000F00DB11D639FAA27F00DB11DAA1F649F36
+:100590006627B00DA11D661F829F2227B00DA11DE9
+:1005A000621F739FB00DA11D621F839FA00D611D6F
+:1005B000221F749F3327A00D611D231F849F600D90
+:1005C000211D822F762F6A2F11249F5750408AF0C9
+:1005D000E1F088234AF0EE0FFF1FBB1F661F771F55
+:1005E000881F91505040A9F79E3F510570F060CF91
+:1005F000AACF5F3FECF3983EDCF38695779567953D
+:10060000B795F795E7959F5FC1F7FE2B880F911D72
+:0C0610009695879597F90895F894FFCF10
+:10061C000000000016000AD7233C00000000000078
+:02062C000000CC
+:00000001FF
diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/servo/servo_reverse.sh b/OpenModelica_Arduino_With_MDD/MDD_build/servo/servo_reverse.sh new file mode 100644 index 0000000..9c5927d --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/servo/servo_reverse.sh @@ -0,0 +1,61 @@ +#!/bin/bash +clear +if [ "$#" -ne 2 ]; then + echo "Usage: $0 port baudrate" >&2 + exit 1 +fi + +re='^[0-9]+$' +if ! [[ $1 =~ $re ]] ; then + echo "error: $1 -> Not a number" >&2; exit 1 +fi + +if ! [[ $2 =~ $re ]] ; then + echo "error: $2-> Not a number" >&2; exit 1 +fi + +b_rate=$2 + +present=`pwd` +unamestr=`uname` + +if [[ "$unamestr" == 'Linux' ]]; then + mdd_path=($(locate Modelica_DeviceDrivers/Modelica_DeviceDrivers/Resources/Include)) + om_path=($(locate /usr/include/omc/c)) + port="/dev/ttyACM$1" + omc --simCodeTarget=ExperimentalEmbeddedC runMDD_servo_reverse.mos + if [ $? -ne 0 ]; then + exit 1 + fi +else + cd c: + om_path=($(dir -d OpenModelica*/include/omc/c/)) + path_to_om="C:$om_path" + cd f: + mdd_path=($(dir -d */Modelica_DeviceDrivers/Modelica_DeviceDrivers/Resources/Include/)) + if [ $? -eq 0 ]; then + path_to_mdd="F:/$mdd_path" + else + exit 1 + fi + + port="COM$1" + cd $present + omc --simCodeTarget=ExperimentalEmbeddedC run_servo_reverse.mos + if [ $? -ne 0 ]; then + exit 1 + fi +fi + +avr-gcc -Os -std=c11 -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000UL -Wl,--gc-sections servo_reverse_main.c -o servo_reverse -I${mdd_path[0]} -I${path_to_om} -I${path_to_mdd} -I${om_path[0]} +if [ $? -ne 0 ]; then + exit 1 +fi +avr-objcopy -O ihex -R .eeprom servo_reverse servo_reverse.hex +if [ $? -ne 0 ]; then + exit 1 +fi +avrdude -F -V -c arduino -p ATMEGA328P -P $port -b $b_rate -U flash:w:servo_reverse.hex +if [ $? -ne 0 ]; then + exit 1 +fi
\ No newline at end of file diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/servo/servo_reverse_main.c b/OpenModelica_Arduino_With_MDD/MDD_build/servo/servo_reverse_main.c new file mode 100644 index 0000000..5382666 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/servo/servo_reverse_main.c @@ -0,0 +1,213 @@ +#define fmi2TypesPlatform_h + +#define fmi2TypesPlatform "default" /* Compatible */ + +typedef struct servo_reverse_fmi2Component_s* fmi2Component; +typedef void* fmi2ComponentEnvironment; /* Pointer to FMU environment */ +typedef void* fmi2FMUstate; /* Pointer to internal FMU state */ +typedef unsigned int fmi2ValueReference; +typedef double fmi2Real; +typedef int fmi2Integer; +typedef int fmi2Boolean; +typedef char fmi2Char; +typedef const fmi2Char* fmi2String; +typedef char fmi2Byte; + +#define fmi2True 1 +#define fmi2False 0 + +#include "fmi2/fmi2Functions.h" + +#include <stdint.h> +#include <stdio.h> + +void ModelicaFormatMessage(const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + vprintf(fmt, args); + va_end(args); +} + +typedef struct servo_reverse_fmi2Component_s { + fmi2Real currentTime; + fmi2Integer fmi2IntegerVars[1]; + fmi2Real fmi2RealParameter[1]; + void* extObjs[4]; +} servo_reverse_fmi2Component; + +servo_reverse_fmi2Component servo_reverse_component = { + .fmi2IntegerVars = { + 22 /*pwm._u[1]*/, + }, + .fmi2RealParameter = { + 0.01 /*synchronizeRealtime1._actualInterval*/, + }, +}; + +#include <math.h> +/* TODO: Generate used builtin functions before SimCode */ +static inline double om_mod(double x, double y) +{ + return x-floor(x/y)*y; +} + +#include "MDDAVRTimer.h" +#include "MDDAVRRealTime.h" +#include "MDDAVRAnalog.h" + +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_set(fmi2Component comp, void* om_pwm, fmi2Integer om_value); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_pin, fmi2Integer om_initialValue, fmi2Boolean om_inverted); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_Init_destructor(fmi2Component comp, void* om_pwm); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer); + +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_set(fmi2Component comp, void* om_pwm, fmi2Integer om_value) +{ + MDD_avr_pwm_set(om_pwm, om_value); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_pin, fmi2Integer om_initialValue, fmi2Boolean om_inverted) +{ + void* om_pwm; + om_pwm = MDD_avr_pwm_init(om_timer, om_pin, om_initialValue, om_inverted); + return om_pwm; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_Init_destructor(fmi2Component comp, void* om_pwm) +{ + MDD_avr_pwm_close(om_pwm); +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt) +{ + MDD_avr_rt_wait(om_rt); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle) +{ + void* om_rt; + om_rt = MDD_avr_rt_init(om_timer, om_timerValue, om_numTimerInterruptsPerCycle); + return om_rt; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt) +{ + MDD_avr_rt_close(om_rt); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch) +{ + void* om_timer; + om_timer = MDD_avr_timer_init(om_timerSelect, om_clockSelect, om_clearTimerOnMatch); + return om_timer; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer) +{ + MDD_avr_timer_close(om_timer); +} + +fmi2Component servo_reverse_fmi2Instantiate(fmi2String name, fmi2Type ty, fmi2String GUID, fmi2String resources, const fmi2CallbackFunctions* functions, fmi2Boolean visible, fmi2Boolean loggingOn) +{ + static int initDone=0; + if (initDone) { + return NULL; + } + return &servo_reverse_component; +} + +fmi2Status servo_reverse_fmi2SetupExperiment(fmi2Component comp, fmi2Boolean toleranceDefined, fmi2Real tolerance, fmi2Real startTime, fmi2Boolean stopTimeDefined, fmi2Real stopTime) +{ + return fmi2OK; +} + +fmi2Status servo_reverse_fmi2EnterInitializationMode(fmi2Component comp) +{ + comp->extObjs[0] /* pwm._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(comp, 2, 7, fmi2True); + comp->extObjs[1] /* pwm._pwm[1] EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.PWM.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_Init_constructor(comp, comp->extObjs[0] /* pwm._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */, 1, 0, fmi2False); + comp->extObjs[2] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(comp, 1, 4, fmi2False); + comp->extObjs[3] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(comp, comp->extObjs[2] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */, 249, 10); + return fmi2OK; +} + +fmi2Status servo_reverse_fmi2ExitInitializationMode(fmi2Component comp) +{ + return fmi2OK; +} + +static fmi2Status servo_reverse_functionODE(fmi2Component comp) +{ +} + +static fmi2Status servo_reverse_functionOutputs(fmi2Component comp) +{ + comp->fmi2IntegerVars[0] /* pwm._u[1] DISCRETE */ = ((comp->currentTime)<(0.2)) ? (22) : (15); /* equation 3 */Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(comp, comp->extObjs[3] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */);Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_set(comp, comp->extObjs[1] /* pwm._pwm[1] EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.PWM.Init */, comp->fmi2IntegerVars[0] /* pwm._u[1] DISCRETE */); +} + +fmi2Status servo_reverse_fmi2DoStep(fmi2Component comp, fmi2Real currentCommunicationPoint, fmi2Real communicationStepSize, fmi2Boolean noSetFMUStatePriorToCurrentPoint) +{ + comp->currentTime = currentCommunicationPoint; + /* TODO: Calculate time/state-dependent variables here... */ + servo_reverse_functionOutputs(comp); + return fmi2OK; +} + +int main(int argc, char **argv) +{ + int terminateSimulation = 0; + fmi2Status status = fmi2OK; + fmi2CallbackFunctions cbf = { + .logger = NULL, + .allocateMemory = NULL /*calloc*/, + .freeMemory = NULL /*free*/, + .stepFinished = NULL, //synchronous execution + .componentEnvironment = NULL + }; + + fmi2Component comp = servo_reverse_fmi2Instantiate("", fmi2CoSimulation, "", "", &cbf, fmi2False, fmi2False); + if (comp==NULL) { + return 1; + } + servo_reverse_fmi2SetupExperiment(comp, fmi2False, 0.0, 0.0, fmi2False, 1.0); + servo_reverse_fmi2EnterInitializationMode(comp); + // Set start-values? Nah... + servo_reverse_fmi2ExitInitializationMode(comp); + + double currentTime = 0.0; + double h = 0.002; + uint32_t i = 0; + + while (status == fmi2OK) { + //retrieve outputs + // fmi2GetReal(m, ..., 1, &y1); + //set inputs + // fmi2SetReal(m, ..., 1, &y2); + + //call slave and check status + status = servo_reverse_fmi2DoStep(comp, currentTime, h, fmi2True); + switch (status) { + case fmi2Discard: + case fmi2Error: + case fmi2Fatal: + case fmi2Pending /* Cannot happen */: + terminateSimulation = 1; + break; + case fmi2OK: + case fmi2Warning: + break; + } + if (terminateSimulation) { + break; + } + i++; + /* increment master time */ + currentTime = 0.0 + h*i; + } + +#if 0 + if ((status != fmi2Error) && (status != fmi2Fatal)) { + fmi2Terminate(m); + } + if (status != fmi2Fatal) { + fmi2FreeInstance(m); + } +#endif +} + diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/thermistor/runMDD_therm_buzzer.mos b/OpenModelica_Arduino_With_MDD/MDD_build/thermistor/runMDD_therm_buzzer.mos new file mode 100644 index 0000000..8164089 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/thermistor/runMDD_therm_buzzer.mos @@ -0,0 +1,11 @@ +loadModel(Modelica); +getErrorString(); + +loadFile("/home/souradip/Modelica_DeviceDrivers/Modelica_DeviceDrivers/package.mo"); +getErrorString(); + +loadFile("/home/souradip/OpenModelica/Arduino.mo"); +getErrorString(); + +translateModel(Arduino.SerialCommunication.MDD_Examples.MDD_thermistor.MDD_therm_buzzer, fileNamePrefix="therm_buzzer"); +getErrorString(); diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/thermistor/runMDD_therm_read.mos b/OpenModelica_Arduino_With_MDD/MDD_build/thermistor/runMDD_therm_read.mos new file mode 100644 index 0000000..a251626 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/thermistor/runMDD_therm_read.mos @@ -0,0 +1,11 @@ +loadModel(Modelica); +getErrorString(); + +loadFile("/home/souradip/Modelica_DeviceDrivers/Modelica_DeviceDrivers/package.mo"); +getErrorString(); + +loadFile("/home/souradip/OpenModelica/Arduino.mo"); +getErrorString(); + +translateModel(Arduino.SerialCommunication.MDD_Examples.MDD_thermistor.MDD_therm_read, fileNamePrefix="therm_read"); +getErrorString(); diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/thermistor/therm_buzzer b/OpenModelica_Arduino_With_MDD/MDD_build/thermistor/therm_buzzer Binary files differnew file mode 100644 index 0000000..4c841f2 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/thermistor/therm_buzzer diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/thermistor/therm_buzzer.hex b/OpenModelica_Arduino_With_MDD/MDD_build/thermistor/therm_buzzer.hex new file mode 100644 index 0000000..2517195 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/thermistor/therm_buzzer.hex @@ -0,0 +1,121 @@ +:100000000C9434000C9451000C9451000C94510049
+:100010000C9451000C9451000C9451000C9431013B
+:100020000C9451000C9451000C9451000C9400015C
+:100030000C9451000C9451000C94CF000C9451007E
+:100040000C9451000C9451000C9451000C945100EC
+:100050000C9451000C9451000C9451000C945100DC
+:100060000C9451000C94510011241FBECFEFD8E026
+:10007000DEBFCDBF11E0A0E0B1E0E2E4F7E002C0F6
+:1000800005900D92A832B107D9F711E0A8E2B1E0CE
+:1000900001C01D92AD32B107E1F70E948A010C94B4
+:1000A0009F030C9400000F931F93CF93DF93EC01F9
+:1000B00080917C00857E846080937C0080917A00B2
+:1000C000806480937A0080917A0086FDFCCF6091F5
+:1000D00078007091790080E090E00E94860220E034
+:1000E00030E040E854E40E94180320E030EC4FE791
+:1000F00054E40E941E026C837D838E839F8301E003
+:1001000010E02A893B894C895D890E94140387FF8E
+:1001100002C000E010E0198B088B8EA19FA18230F5
+:10012000910561F08330910599F00197C9F416BCEF
+:1001300080916E00826080936E0016C010928500E0
+:100140001092840080916F00826080936F000CC0D9
+:100150001092B2008091700082608093700004C0A1
+:1001600081E090E00E949F0378949FB7F89480917B
+:100170002A019FBF8823C9F310922A01EAA1FBA19B
+:1001800088899989892B19F08081886002C08081D3
+:10019000877F8083DF91CF911F910F9108951F92E8
+:1001A0000F920FB60F9211242F933F938F939F932B
+:1001B00080912801909129010196909329018093C3
+:1001C000280180912A01813091F0209128013091FD
+:1001D000290180912B0190912C012817390738F0C3
+:1001E00081E080932A0110922901109228019F91A9
+:1001F0008F913F912F910F900FBE0F901F901895E8
+:100200001F920F920FB60F9211242F933F938F934B
+:100210009F93809128019091290101969093290143
+:100220008093280180912A01813091F0209128014A
+:100230003091290180912B0190912C0128173907C9
+:1002400038F081E080932A01109229011092280150
+:100250009F918F913F912F910F900FBE0F901F9004
+:1002600018951F920F920FB60F9211242F933F9360
+:100270008F939F93809128019091290101969093EB
+:1002800029018093280180912A01813091F02091E9
+:1002900028013091290180912B0190912C01281780
+:1002A000390738F081E080932A01109229011092D9
+:1002B00028019F918F913F912F910F900FBE0F902A
+:1002C0001F901895FC01539A8BE290E093A382A3B0
+:1002D00085B5836085BD81E090E095A384A32AE085
+:1002E00030E030932C0120932B0124B5226024BDF3
+:1002F00029EF27BD97A386A3ACE7B0E08C918C9340
+:10030000AAE7B0E08C9187688C9311A210A280E0DC
+:1003100090E00895CF92DF92EF92FF9280E091E01B
+:100320000E946201C12CD12C760160E070E0CB010B
+:100330006093000170930101809302019093030187
+:1003400080E091E00E9453008FEFC81AD80AE80AB3
+:10035000F80AC701B6010E9486022FE632E143E0A7
+:100360005BE30E94180320E030E0A9010E94BA017B
+:10037000DFCF5058BB27AA270ED01CC10DD130F0BB
+:1003800012D120F031F49F3F11F41EF402C10EF49B
+:10039000E095E7FBF8C0E92F1ED180F3BA1762079A
+:1003A00073078407950718F071F49EF536C10EF4B3
+:1003B000E0950B2EBA2FA02D0B01B90190010C0175
+:1003C000CA01A0011124FF27591B99F0593F50F48D
+:1003D000503E68F11A16F040A22F232F342F4427E5
+:1003E000585FF3CF469537952795A795F0405395DD
+:1003F000C9F77EF41F16BA0B620B730B840BBAF0AD
+:100400009150A1F0FF0FBB1F661F771F881FC2F717
+:100410000EC0BA0F621F731F841F48F4879577952B
+:100420006795B795F7959E3F08F0B3CF9395880FE2
+:1004300008F09927EE0F9795879508950CD0BAC0CC
+:10044000B2D040F0A9D030F021F45F3F19F09BC04A
+:100450005111E4C09EC0BFD098F39923C9F355232E
+:10046000B1F3951B550BBB27AA27621773078407A7
+:1004700038F09F5F5F4F220F331F441FAA1FA9F35D
+:1004800033D00E2E3AF0E0E830D091505040E6954F
+:10049000001CCAF729D0FE2F27D0660F771F881FB0
+:1004A000BB1F261737074807AB07B0E809F0BB0B9F
+:1004B000802DBF01FF2793585F4F2AF09E3F5105C3
+:1004C00068F061C0ABC05F3FECF3983EDCF386950B
+:1004D00077956795B795F7959F5FC9F7880F911D39
+:1004E0009695879597F90895E1E0660F771F881F25
+:1004F000BB1F621773078407BA0720F0621B730BD8
+:10050000840BBA0BEE1F88F7E0950895E89409C0B4
+:1005100097FB3EF490958095709561957F4F8F4F36
+:100520009F4F9923A9F0F92F96E9BB279395F6954C
+:10053000879577956795B795F111F8CFFAF4BB0FCA
+:1005400011F460FF1BC06F5F7F4F8F4F9F4F16C02E
+:10055000882311F096E911C0772321F09EE8872FB8
+:10056000762F05C0662371F096E8862F70E060E074
+:100570002AF09A95660F771F881FDAF7880F9695ED
+:10058000879597F9089597F99F6780E870E060E094
+:1005900008959FEF80EC089500240A94161617061C
+:1005A00018060906089500240A9412161306140664
+:1005B00005060895092E0394000C11F4882352F0C7
+:1005C000BB0F40F4BF2B11F460FF04C06F5F7F4F7F
+:1005D0008F4F9F4F089557FD9058440F551F59F066
+:1005E0005F3F71F04795880F97FB991F61F09F3F20
+:1005F00079F087950895121613061406551FF2CF49
+:100600004695F1DF08C0161617061806991FF1CF98
+:1006100086957105610508940895E894BB276627BF
+:100620007727CB0197F9089566D008F48FEF0895E6
+:100630000BD0C0CFB1DF28F0B6DF18F0952309F05A
+:10064000A2CFA7CF1124EACFC6DFA0F3959FD1F3A5
+:10065000950F50E0551F629FF001729FBB27F00D70
+:10066000B11D639FAA27F00DB11DAA1F649F6627C5
+:10067000B00DA11D661F829F2227B00DA11D621F14
+:10068000739FB00DA11D621F839FA00D611D221FCE
+:10069000749F3327A00D611D231F849F600D211DB2
+:1006A000822F762F6A2F11249F5750408AF0E1F055
+:1006B00088234AF0EE0FFF1FBB1F661F771F881F9E
+:1006C00091505040A9F79E3F510570F05CCFA6CFE6
+:1006D0005F3FECF3983EDCF3869577956795B79589
+:1006E000F795E7959F5FC1F7FE2B880F911D9695B3
+:1006F000879597F90895990F0008550FAA0BE0E820
+:10070000FEEF16161706E807F907C0F012161306D3
+:10071000E407F50798F0621B730B840B950B39F413
+:100720000A2661F0232B242B252B21F408950A2679
+:1007300009F4A140A6958FEF811D811D0895F894BD
+:02074000FFCFE9
+:1007420000000000000000000000000000000000A7
+:10075200000000806D440AD7233C02000100000023
+:0807620000000000000000008F
+:00000001FF
diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/thermistor/therm_buzzer.sh b/OpenModelica_Arduino_With_MDD/MDD_build/thermistor/therm_buzzer.sh new file mode 100644 index 0000000..b6782eb --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/thermistor/therm_buzzer.sh @@ -0,0 +1,61 @@ +#!/bin/bash +clear +if [ "$#" -ne 2 ]; then + echo "Usage: $0 port baudrate" >&2 + exit 1 +fi + +re='^[0-9]+$' +if ! [[ $1 =~ $re ]] ; then + echo "error: $1 -> Not a number" >&2; exit 1 +fi + +if ! [[ $2 =~ $re ]] ; then + echo "error: $2-> Not a number" >&2; exit 1 +fi + +b_rate=$2 + +present=`pwd` +unamestr=`uname` + +if [[ "$unamestr" == 'Linux' ]]; then + mdd_path=($(locate Modelica_DeviceDrivers/Modelica_DeviceDrivers/Resources/Include)) + om_path=($(locate /usr/include/omc/c)) + port="/dev/ttyACM$1" + omc --simCodeTarget=ExperimentalEmbeddedC runMDD_therm_buzzer.mos + if [ $? -ne 0 ]; then + exit 1 + fi +else + cd c: + om_path=($(dir -d OpenModelica*/include/omc/c/)) + path_to_om="C:$om_path" + cd f: + mdd_path=($(dir -d */Modelica_DeviceDrivers/Modelica_DeviceDrivers/Resources/Include/)) + if [ $? -eq 0 ]; then + path_to_mdd="F:/$mdd_path" + else + exit 1 + fi + + port="COM$1" + cd $present + omc --simCodeTarget=ExperimentalEmbeddedC run_therm_buzzer.mos + if [ $? -ne 0 ]; then + exit 1 + fi +fi + +avr-gcc -Os -std=c11 -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000UL -Wl,--gc-sections therm_buzzer_main.c -o therm_buzzer -I${mdd_path[0]} -I${path_to_om} -I${path_to_mdd} -I${om_path[0]} +if [ $? -ne 0 ]; then + exit 1 +fi +avr-objcopy -O ihex -R .eeprom therm_buzzer therm_buzzer.hex +if [ $? -ne 0 ]; then + exit 1 +fi +avrdude -F -V -c arduino -p ATMEGA328P -P $port -b $b_rate -U flash:w:therm_buzzer.hex +if [ $? -ne 0 ]; then + exit 1 +fi
\ No newline at end of file diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/thermistor/therm_buzzer_main.c b/OpenModelica_Arduino_With_MDD/MDD_build/thermistor/therm_buzzer_main.c new file mode 100644 index 0000000..d729be2 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/thermistor/therm_buzzer_main.c @@ -0,0 +1,253 @@ +#define fmi2TypesPlatform_h + +#define fmi2TypesPlatform "default" /* Compatible */ + +typedef struct therm_buzzer_fmi2Component_s* fmi2Component; +typedef void* fmi2ComponentEnvironment; /* Pointer to FMU environment */ +typedef void* fmi2FMUstate; /* Pointer to internal FMU state */ +typedef unsigned int fmi2ValueReference; +typedef double fmi2Real; +typedef int fmi2Integer; +typedef int fmi2Boolean; +typedef char fmi2Char; +typedef const fmi2Char* fmi2String; +typedef char fmi2Byte; + +#define fmi2True 1 +#define fmi2False 0 + +#include "fmi2/fmi2Functions.h" + +#include <stdint.h> +#include <stdio.h> + +void ModelicaFormatMessage(const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + vprintf(fmt, args); + va_end(args); +} + +typedef struct therm_buzzer_fmi2Component_s { + fmi2Real currentTime; + fmi2Real fmi2RealVars[2]; + fmi2Boolean fmi2BooleanVars[3]; + fmi2Real fmi2RealParameter[2]; + fmi2Integer fmi2IntegerParameter[1]; + fmi2Boolean fmi2BooleanParameter[1]; + fmi2String fmi2StringParameter[1]; + void* extObjs[4]; +} therm_buzzer_fmi2Component; + +therm_buzzer_fmi2Component therm_buzzer_component = { + .fmi2RealVars = { + 0.0 /*adc._y*/, + 0.0 /*realValue1._number*/, + }, + .fmi2BooleanVars = { + fmi2False /*booleanExpression1._y*/, + fmi2False /*booleanExpression2._y*/, + fmi2False /*digitalWriteBoolean1._u*/, + }, + .fmi2RealParameter = { + 950.0 /*greaterEqualThreshold1._threshold*/, + 0.01 /*synchronizeRealtime1._actualInterval*/, + }, + .fmi2IntegerParameter = { + 2 /*realValue1._significantDigits*/, + }, + .fmi2BooleanParameter = { + fmi2True /*realValue1._use_numberPort*/, + }, +}; + +#include <math.h> +/* TODO: Generate used builtin functions before SimCode */ +static inline double om_mod(double x, double y) +{ + return x-floor(x/y)*y; +} + +static const char * const OMCLIT0 = "ElectricPotential"; +static const char * const OMCLIT1 = "V"; +#include "MDDAVRTimer.h" +#include "MDDAVRRealTime.h" +#include "MDDAVRDigital.h" +#include "MDDAVRAnalog.h" + +static inline fmi2Real Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_read__voltage(fmi2Component comp, fmi2Integer om_analogPort, fmi2Real om_vref, fmi2Integer om_voltageResolution); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_constructor(fmi2Component comp, fmi2Integer om_divisionFactor, fmi2Integer om_referenceVoltage); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_destructor(fmi2Component comp, void* om_avr); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(fmi2Component comp, void* om_port, fmi2Integer om_pin, fmi2Boolean om_value); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_destructor(fmi2Component comp, void* om_digital); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer); + +static inline fmi2Real Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_read__voltage(fmi2Component comp, fmi2Integer om_analogPort, fmi2Real om_vref, fmi2Integer om_voltageResolution) +{ + fmi2Real om_value; + om_value = MDD_avr_analog_read(om_analogPort, om_vref, om_voltageResolution); + return om_value; +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_constructor(fmi2Component comp, fmi2Integer om_divisionFactor, fmi2Integer om_referenceVoltage) +{ + void* om_avr; + om_avr = MDD_avr_analog_init(om_divisionFactor, om_referenceVoltage); + return om_avr; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_destructor(fmi2Component comp, void* om_avr) +{ + MDD_avr_analog_close(om_avr); +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(fmi2Component comp, void* om_port, fmi2Integer om_pin, fmi2Boolean om_value) +{ + MDD_avr_digital_pin_write(om_port, om_pin, om_value); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin) +{ + void* om_dig; + om_dig = MDD_avr_digital_pin_init(om_port, om_pin, fmi2True); + return om_dig; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_destructor(fmi2Component comp, void* om_digital) +{ + MDD_avr_digital_pin_close(om_digital); +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt) +{ + MDD_avr_rt_wait(om_rt); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle) +{ + void* om_rt; + om_rt = MDD_avr_rt_init(om_timer, om_timerValue, om_numTimerInterruptsPerCycle); + return om_rt; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt) +{ + MDD_avr_rt_close(om_rt); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch) +{ + void* om_timer; + om_timer = MDD_avr_timer_init(om_timerSelect, om_clockSelect, om_clearTimerOnMatch); + return om_timer; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer) +{ + MDD_avr_timer_close(om_timer); +} + +fmi2Component therm_buzzer_fmi2Instantiate(fmi2String name, fmi2Type ty, fmi2String GUID, fmi2String resources, const fmi2CallbackFunctions* functions, fmi2Boolean visible, fmi2Boolean loggingOn) +{ + static int initDone=0; + if (initDone) { + return NULL; + } + return &therm_buzzer_component; +} + +fmi2Status therm_buzzer_fmi2SetupExperiment(fmi2Component comp, fmi2Boolean toleranceDefined, fmi2Real tolerance, fmi2Real startTime, fmi2Boolean stopTimeDefined, fmi2Real stopTime) +{ + return fmi2OK; +} + +fmi2Status therm_buzzer_fmi2EnterInitializationMode(fmi2Component comp) +{ + comp->extObjs[1] /* digitalWriteBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(comp, 4, 4); + comp->extObjs[2] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(comp, 1, 4, fmi2False); + comp->extObjs[3] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(comp, comp->extObjs[2] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */, 249, 10); + comp->extObjs[0] /* adc._analog EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Analog.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_constructor(comp, 7, 1); + return fmi2OK; +} + +fmi2Status therm_buzzer_fmi2ExitInitializationMode(fmi2Component comp) +{ + return fmi2OK; +} + +static fmi2Status therm_buzzer_functionODE(fmi2Component comp) +{ +} + +static fmi2Status therm_buzzer_functionOutputs(fmi2Component comp) +{ + comp->fmi2RealVars[0] /* adc._y variable */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_read__voltage(comp, 5, 1024.0, 10); /* equation 7 */ + comp->fmi2BooleanVars[2] /* digitalWriteBoolean1._u DISCRETE */ = (comp->fmi2RealVars[0] /* adc._y variable */)>=(comp->fmi2RealParameter[0] /* greaterEqualThreshold1._threshold PARAM */); /* equation 8 */Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(comp, comp->extObjs[3] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */);Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(comp, comp->extObjs[1] /* digitalWriteBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */, 4, comp->fmi2BooleanVars[2] /* digitalWriteBoolean1._u DISCRETE */); +} + +fmi2Status therm_buzzer_fmi2DoStep(fmi2Component comp, fmi2Real currentCommunicationPoint, fmi2Real communicationStepSize, fmi2Boolean noSetFMUStatePriorToCurrentPoint) +{ + comp->currentTime = currentCommunicationPoint; + /* TODO: Calculate time/state-dependent variables here... */ + therm_buzzer_functionOutputs(comp); + return fmi2OK; +} + +int main(int argc, char **argv) +{ + int terminateSimulation = 0; + fmi2Status status = fmi2OK; + fmi2CallbackFunctions cbf = { + .logger = NULL, + .allocateMemory = NULL /*calloc*/, + .freeMemory = NULL /*free*/, + .stepFinished = NULL, //synchronous execution + .componentEnvironment = NULL + }; + + fmi2Component comp = therm_buzzer_fmi2Instantiate("", fmi2CoSimulation, "", "", &cbf, fmi2False, fmi2False); + if (comp==NULL) { + return 1; + } + therm_buzzer_fmi2SetupExperiment(comp, fmi2False, 0.0, 0.0, fmi2False, 1.0); + therm_buzzer_fmi2EnterInitializationMode(comp); + // Set start-values? Nah... + therm_buzzer_fmi2ExitInitializationMode(comp); + + double currentTime = 0.0; + double h = 0.002; + uint32_t i = 0; + + while (status == fmi2OK) { + //retrieve outputs + // fmi2GetReal(m, ..., 1, &y1); + //set inputs + // fmi2SetReal(m, ..., 1, &y2); + + //call slave and check status + status = therm_buzzer_fmi2DoStep(comp, currentTime, h, fmi2True); + switch (status) { + case fmi2Discard: + case fmi2Error: + case fmi2Fatal: + case fmi2Pending /* Cannot happen */: + terminateSimulation = 1; + break; + case fmi2OK: + case fmi2Warning: + break; + } + if (terminateSimulation) { + break; + } + i++; + /* increment master time */ + currentTime = 0.0 + h*i; + } + +#if 0 + if ((status != fmi2Error) && (status != fmi2Fatal)) { + fmi2Terminate(m); + } + if (status != fmi2Fatal) { + fmi2FreeInstance(m); + } +#endif +} + diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/thermistor/therm_read b/OpenModelica_Arduino_With_MDD/MDD_build/thermistor/therm_read Binary files differnew file mode 100644 index 0000000..93f6d1f --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/thermistor/therm_read diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/thermistor/therm_read.hex b/OpenModelica_Arduino_With_MDD/MDD_build/thermistor/therm_read.hex new file mode 100644 index 0000000..32ec1b8 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/thermistor/therm_read.hex @@ -0,0 +1,110 @@ +:100000000C9434000C9451000C9451000C94510049
+:100010000C9451000C9451000C9451000C94130159
+:100020000C9451000C9451000C9451000C94E2007B
+:100030000C9451000C9451000C94B1000C9451009C
+:100040000C9451000C9451000C9451000C945100EC
+:100050000C9451000C9451000C9451000C945100DC
+:100060000C9451000C94510011241FBECFEFD8E026
+:10007000DEBFCDBF11E0A0E0B1E0ECEAF6E002C0E7
+:1000800005900D92AC31B107D9F711E0ACE1B1E0C8
+:1000900001C01D92A132B107E1F70E9467010C94E3
+:1000A00054030C940000CF93DF93EC0180917C000B
+:1000B000857E846080937C0080917A008064809348
+:1000C0007A0080917A0086FDFCCF60917800709173
+:1000D000790080E090E00E94630220E030E040EA96
+:1000E00050E40E94F10220E030EC4FE754E40E941B
+:1000F000FB016C837D838E839F838A8D9B8D8230F1
+:10010000910561F08330910599F00197C9F416BC0F
+:1001100080916E00826080936E0016C01092850000
+:100120001092840080916F00826080936F000CC0F9
+:100130001092B2008091700082608093700004C0C1
+:1001400081E090E00E94540378949FB7F8948091E6
+:100150001E019FBF8823C9F310921E01DF91CF912A
+:1001600008951F920F920FB60F9211242F933F9371
+:100170008F939F9380911C0190911D010196909304
+:100180001D0180931C0180911E01813091F020910E
+:100190001C0130911D0180911F01909120012817B1
+:1001A000390738F081E080931E0110921D011092F2
+:1001B0001C019F918F913F912F910F900FBE0F9037
+:1001C0001F9018951F920F920FB60F9211242F9324
+:1001D0003F938F939F9380911C0190911D010196F5
+:1001E00090931D0180931C0180911E01813091F03C
+:1001F00020911C0130911D0180911F0190912001DF
+:100200002817390738F081E080931E0110921D01F4
+:1002100010921C019F918F913F912F910F900FBED3
+:100220000F901F9018951F920F920FB60F921124E6
+:100230002F933F938F939F9380911C0190911D0169
+:10024000019690931D0180931C0180911E018130C5
+:1002500091F020911C0130911D0180911F0190911E
+:1002600020012817390738F081E080931E01109291
+:100270001D0110921C019F918F913F912F910F9022
+:100280000FBE0F901F901895FC01ACE7B0E08C9169
+:100290008C93AAE7B0E08C9181688C93178A168AB8
+:1002A00085B5836085BD81E090E0918F808F2AE0E5
+:1002B00030E03093200120931F0124B5226024BD3B
+:1002C00029EF27BD938F828F80E090E00895CF9231
+:1002D000DF92EF92FF9280E091E00E944401C12CF6
+:1002E000D12C760160E070E0CB0160930001709347
+:1002F0000101809302019093030180E091E00E944C
+:1003000053008FEFC81AD80AE80AF80AC701B601E5
+:100310000E9463022FE632E143E05BE30E94F102B8
+:1003200020E030E0A9010E949701DFCF5058BB27A1
+:10033000AA270ED01CC10DD130F012D120F031F41B
+:100340009F3F11F41EF402C10EF4E095E7FBF8C0E4
+:10035000E92F1ED180F3BA17620773078407950748
+:1003600018F071F49EF536C10EF4E0950B2EBA2FFD
+:10037000A02D0B01B90190010C01CA01A0011124AB
+:10038000FF27591B99F0593F50F4503E68F11A1657
+:10039000F040A22F232F342F4427585FF3CF4695E8
+:1003A00037952795A795F0405395C9F77EF41F160A
+:1003B000BA0B620B730B840BBAF09150A1F0FF0FD4
+:1003C000BB1F661F771F881FC2F70EC0BA0F621FC0
+:1003D000731F841F48F4879577956795B795F795B0
+:1003E0009E3F08F0B3CF9395880F08F09927EE0F42
+:1003F0009795879508950CD0BAC0B2D040F0A9D097
+:1004000030F021F45F3F19F09BC05111E4C09EC051
+:10041000BFD098F39923C9F35523B1F3951B550B1E
+:10042000BB27AA2762177307840738F09F5F5F4FC7
+:10043000220F331F441FAA1FA9F333D00E2E3AF008
+:10044000E0E830D091505040E695001CCAF729D022
+:10045000FE2F27D0660F771F881FBB1F2617370771
+:100460004807AB07B0E809F0BB0B802DBF01FF27A1
+:1004700093585F4F2AF09E3F510568F061C0ABC0B2
+:100480005F3FECF3983EDCF3869577956795B795DB
+:10049000F7959F5FC9F7880F911D9695879597F9F6
+:1004A0000895E1E0660F771F881FBB1F621773076F
+:1004B0008407BA0720F0621B730B840BBA0BEE1F84
+:1004C00088F7E0950895E89409C097FB3EF490956D
+:1004D0008095709561957F4F8F4F9F4F9923A9F01D
+:1004E000F92F96E9BB279395F695879577956795AC
+:1004F000B795F111F8CFFAF4BB0F11F460FF1BC0F0
+:100500006F5F7F4F8F4F9F4F16C0882311F096E982
+:1005100011C0772321F09EE8872F762F05C0662330
+:1005200071F096E8862F70E060E02AF09A95660FE9
+:10053000771F881FDAF7880F9695879597F90895A2
+:1005400097F99F6780E870E060E008959FEF80EC86
+:10055000089500240A941616170618060906089529
+:1005600000240A9412161306140605060895092E8F
+:100570000394000C11F4882352F0BB0F40F4BF2BFE
+:1005800011F460FF04C06F5F7F4F8F4F9F4F08953E
+:1005900057FD9058440F551F59F05F3F71F0479534
+:1005A000880F97FB991F61F09F3F79F08795089519
+:1005B000121613061406551FF2CF4695F1DF08C038
+:1005C000161617061806991FF1CF86957105610555
+:1005D00008940895E894BB2766277727CB0197F9FD
+:1005E00008950BD0C4CFB5DF28F0BADF18F09523FB
+:1005F00009F0A6CFABCF1124EECFCADFA0F3959FB1
+:10060000D1F3950F50E0551F629FF001729FBB27F9
+:10061000F00DB11D639FAA27F00DB11DAA1F649FA5
+:100620006627B00DA11D661F829F2227B00DA11D58
+:10063000621F739FB00DA11D621F839FA00D611DDE
+:10064000221F749F3327A00D611D231F849F600DFF
+:10065000211D822F762F6A2F11249F5750408AF038
+:10066000E1F088234AF0EE0FFF1FBB1F661F771FC4
+:10067000881F91505040A9F79E3F510570F060CF00
+:10068000AACF5F3FECF3983EDCF3869577956795AC
+:10069000B795F795E7959F5FC1F7FE2B880F911DE2
+:0C06A0009695879597F90895F894FFCF80
+:1006AC000000000000000000000000000AD7233CFE
+:0C06BC000200010000000000000000002F
+:00000001FF
diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/thermistor/therm_read.sh b/OpenModelica_Arduino_With_MDD/MDD_build/thermistor/therm_read.sh new file mode 100644 index 0000000..9c1adac --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/thermistor/therm_read.sh @@ -0,0 +1,61 @@ +#!/bin/bash +clear +if [ "$#" -ne 2 ]; then + echo "Usage: $0 port baudrate" >&2 + exit 1 +fi + +re='^[0-9]+$' +if ! [[ $1 =~ $re ]] ; then + echo "error: $1 -> Not a number" >&2; exit 1 +fi + +if ! [[ $2 =~ $re ]] ; then + echo "error: $2-> Not a number" >&2; exit 1 +fi + +b_rate=$2 + +present=`pwd` +unamestr=`uname` + +if [[ "$unamestr" == 'Linux' ]]; then + mdd_path=($(locate Modelica_DeviceDrivers/Modelica_DeviceDrivers/Resources/Include)) + om_path=($(locate /usr/include/omc/c)) + port="/dev/ttyACM$1" + omc --simCodeTarget=ExperimentalEmbeddedC runMDD_therm_read.mos + if [ $? -ne 0 ]; then + exit 1 + fi +else + cd c: + om_path=($(dir -d OpenModelica*/include/omc/c/)) + path_to_om="C:$om_path" + cd f: + mdd_path=($(dir -d */Modelica_DeviceDrivers/Modelica_DeviceDrivers/Resources/Include/)) + if [ $? -eq 0 ]; then + path_to_mdd="F:/$mdd_path" + else + exit 1 + fi + + port="COM$1" + cd $present + omc --simCodeTarget=ExperimentalEmbeddedC run_therm_read.mos + if [ $? -ne 0 ]; then + exit 1 + fi +fi + +avr-gcc -Os -std=c11 -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000UL -Wl,--gc-sections therm_read_main.c -o therm_read -I${mdd_path[0]} -I${path_to_om} -I${path_to_mdd} -I${om_path[0]} +if [ $? -ne 0 ]; then + exit 1 +fi +avr-objcopy -O ihex -R .eeprom therm_read therm_read.hex +if [ $? -ne 0 ]; then + exit 1 +fi +avrdude -F -V -c arduino -p ATMEGA328P -P $port -b $b_rate -U flash:w:therm_read.hex +if [ $? -ne 0 ]; then + exit 1 +fi
\ No newline at end of file diff --git a/OpenModelica_Arduino_With_MDD/MDD_build/thermistor/therm_read_main.c b/OpenModelica_Arduino_With_MDD/MDD_build/thermistor/therm_read_main.c new file mode 100644 index 0000000..e3aa656 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/MDD_build/thermistor/therm_read_main.c @@ -0,0 +1,226 @@ +#define fmi2TypesPlatform_h + +#define fmi2TypesPlatform "default" /* Compatible */ + +typedef struct therm_read_fmi2Component_s* fmi2Component; +typedef void* fmi2ComponentEnvironment; /* Pointer to FMU environment */ +typedef void* fmi2FMUstate; /* Pointer to internal FMU state */ +typedef unsigned int fmi2ValueReference; +typedef double fmi2Real; +typedef int fmi2Integer; +typedef int fmi2Boolean; +typedef char fmi2Char; +typedef const fmi2Char* fmi2String; +typedef char fmi2Byte; + +#define fmi2True 1 +#define fmi2False 0 + +#include "fmi2/fmi2Functions.h" + +#include <stdint.h> +#include <stdio.h> + +void ModelicaFormatMessage(const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + vprintf(fmt, args); + va_end(args); +} + +typedef struct therm_read_fmi2Component_s { + fmi2Real currentTime; + fmi2Real fmi2RealVars[2]; + fmi2Real fmi2RealParameter[1]; + fmi2Integer fmi2IntegerParameter[1]; + fmi2Boolean fmi2BooleanParameter[1]; + fmi2String fmi2StringParameter[1]; + void* extObjs[3]; +} therm_read_fmi2Component; + +therm_read_fmi2Component therm_read_component = { + .fmi2RealVars = { + 0.0 /*adc._y*/, + 0.0 /*realValue1._number*/, + }, + .fmi2RealParameter = { + 0.01 /*synchronizeRealtime1._actualInterval*/, + }, + .fmi2IntegerParameter = { + 2 /*realValue1._significantDigits*/, + }, + .fmi2BooleanParameter = { + fmi2True /*realValue1._use_numberPort*/, + }, +}; + +#include <math.h> +/* TODO: Generate used builtin functions before SimCode */ +static inline double om_mod(double x, double y) +{ + return x-floor(x/y)*y; +} + +static const char * const OMCLIT0 = "ElectricPotential"; +static const char * const OMCLIT1 = "V"; +#include "MDDAVRTimer.h" +#include "MDDAVRRealTime.h" +#include "MDDAVRAnalog.h" + +static inline fmi2Real Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_read__voltage(fmi2Component comp, fmi2Integer om_analogPort, fmi2Real om_vref, fmi2Integer om_voltageResolution); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_constructor(fmi2Component comp, fmi2Integer om_divisionFactor, fmi2Integer om_referenceVoltage); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_destructor(fmi2Component comp, void* om_avr); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt); +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch); +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer); + +static inline fmi2Real Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_read__voltage(fmi2Component comp, fmi2Integer om_analogPort, fmi2Real om_vref, fmi2Integer om_voltageResolution) +{ + fmi2Real om_value; + om_value = MDD_avr_analog_read(om_analogPort, om_vref, om_voltageResolution); + return om_value; +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_constructor(fmi2Component comp, fmi2Integer om_divisionFactor, fmi2Integer om_referenceVoltage) +{ + void* om_avr; + om_avr = MDD_avr_analog_init(om_divisionFactor, om_referenceVoltage); + return om_avr; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_destructor(fmi2Component comp, void* om_avr) +{ + MDD_avr_analog_close(om_avr); +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt) +{ + MDD_avr_rt_wait(om_rt); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle) +{ + void* om_rt; + om_rt = MDD_avr_rt_init(om_timer, om_timerValue, om_numTimerInterruptsPerCycle); + return om_rt; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt) +{ + MDD_avr_rt_close(om_rt); +} +static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch) +{ + void* om_timer; + om_timer = MDD_avr_timer_init(om_timerSelect, om_clockSelect, om_clearTimerOnMatch); + return om_timer; +} +static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer) +{ + MDD_avr_timer_close(om_timer); +} + +fmi2Component therm_read_fmi2Instantiate(fmi2String name, fmi2Type ty, fmi2String GUID, fmi2String resources, const fmi2CallbackFunctions* functions, fmi2Boolean visible, fmi2Boolean loggingOn) +{ + static int initDone=0; + if (initDone) { + return NULL; + } + return &therm_read_component; +} + +fmi2Status therm_read_fmi2SetupExperiment(fmi2Component comp, fmi2Boolean toleranceDefined, fmi2Real tolerance, fmi2Real startTime, fmi2Boolean stopTimeDefined, fmi2Real stopTime) +{ + return fmi2OK; +} + +fmi2Status therm_read_fmi2EnterInitializationMode(fmi2Component comp) +{ + comp->extObjs[0] /* adc._analog EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Analog.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_constructor(comp, 1, 1); + comp->extObjs[1] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(comp, 1, 4, fmi2False); + comp->extObjs[2] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(comp, comp->extObjs[1] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */, 249, 10); + return fmi2OK; +} + +fmi2Status therm_read_fmi2ExitInitializationMode(fmi2Component comp) +{ + return fmi2OK; +} + +static fmi2Status therm_read_functionODE(fmi2Component comp) +{ +} + +static fmi2Status therm_read_functionOutputs(fmi2Component comp) +{ + comp->fmi2RealVars[0] /* adc._y variable */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_read__voltage(comp, 5, 5.0, 10); /* equation 4 */Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(comp, comp->extObjs[2] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */); +} + +fmi2Status therm_read_fmi2DoStep(fmi2Component comp, fmi2Real currentCommunicationPoint, fmi2Real communicationStepSize, fmi2Boolean noSetFMUStatePriorToCurrentPoint) +{ + comp->currentTime = currentCommunicationPoint; + /* TODO: Calculate time/state-dependent variables here... */ + therm_read_functionOutputs(comp); + return fmi2OK; +} + +int main(int argc, char **argv) +{ + int terminateSimulation = 0; + fmi2Status status = fmi2OK; + fmi2CallbackFunctions cbf = { + .logger = NULL, + .allocateMemory = NULL /*calloc*/, + .freeMemory = NULL /*free*/, + .stepFinished = NULL, //synchronous execution + .componentEnvironment = NULL + }; + + fmi2Component comp = therm_read_fmi2Instantiate("", fmi2CoSimulation, "", "", &cbf, fmi2False, fmi2False); + if (comp==NULL) { + return 1; + } + therm_read_fmi2SetupExperiment(comp, fmi2False, 0.0, 0.0, fmi2False, 1.0); + therm_read_fmi2EnterInitializationMode(comp); + // Set start-values? Nah... + therm_read_fmi2ExitInitializationMode(comp); + + double currentTime = 0.0; + double h = 0.002; + uint32_t i = 0; + + while (status == fmi2OK) { + //retrieve outputs + // fmi2GetReal(m, ..., 1, &y1); + //set inputs + // fmi2SetReal(m, ..., 1, &y2); + + //call slave and check status + status = therm_read_fmi2DoStep(comp, currentTime, h, fmi2True); + switch (status) { + case fmi2Discard: + case fmi2Error: + case fmi2Fatal: + case fmi2Pending /* Cannot happen */: + terminateSimulation = 1; + break; + case fmi2OK: + case fmi2Warning: + break; + } + if (terminateSimulation) { + break; + } + i++; + /* increment master time */ + currentTime = 0.0 + h*i; + } + +#if 0 + if ((status != fmi2Error) && (status != fmi2Fatal)) { + fmi2Terminate(m); + } + if (status != fmi2Fatal) { + fmi2FreeInstance(m); + } +#endif +} + diff --git a/OpenModelica_Arduino_With_MDD/Resources/Images/Icons/tqfp32.png b/OpenModelica_Arduino_With_MDD/Resources/Images/Icons/tqfp32.png Binary files differnew file mode 100644 index 0000000..f933f6a --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/Resources/Images/Icons/tqfp32.png diff --git a/OpenModelica_Arduino_With_MDD/Resources/Include/analog.h b/OpenModelica_Arduino_With_MDD/Resources/Include/analog.h new file mode 100644 index 0000000..a761139 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/Resources/Include/analog.h @@ -0,0 +1,2 @@ +int cmd_analog_out(int h,int pin_no,double val); +uint16_t cmd_analog_in(int h,int pin_no);
\ No newline at end of file diff --git a/OpenModelica_Arduino_With_MDD/Resources/Include/analogv.h b/OpenModelica_Arduino_With_MDD/Resources/Include/analogv.h new file mode 100644 index 0000000..a761139 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/Resources/Include/analogv.h @@ -0,0 +1,2 @@ +int cmd_analog_out(int h,int pin_no,double val); +uint16_t cmd_analog_in(int h,int pin_no);
\ No newline at end of file diff --git a/OpenModelica_Arduino_With_MDD/Resources/Include/dcmotor.h b/OpenModelica_Arduino_With_MDD/Resources/Include/dcmotor.h new file mode 100644 index 0000000..90314fc --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/Resources/Include/dcmotor.h @@ -0,0 +1,3 @@ +void cmd_dcmotor_setup(int h,int driver_type,int motor_no,int pin_no_1,int pin_no_2); +void cmd_dcmotor_run(int h,int motor_no,int u1); +void cmd_dcmotor_release(int h,int motor_no);
\ No newline at end of file diff --git a/OpenModelica_Arduino_With_MDD/Resources/Include/digital.h b/OpenModelica_Arduino_With_MDD/Resources/Include/digital.h new file mode 100644 index 0000000..c628bb8 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/Resources/Include/digital.h @@ -0,0 +1,2 @@ +int cmd_digital_out(int h,int pin_no,int val); +int cmd_digital_in(int h,int pin_no);
\ No newline at end of file diff --git a/OpenModelica_Arduino_With_MDD/Resources/Include/encoder.h b/OpenModelica_Arduino_With_MDD/Resources/Include/encoder.h new file mode 100644 index 0000000..2559766 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/Resources/Include/encoder.h @@ -0,0 +1 @@ +void cmd_encoder_init(int h,int enc_mode,int pin_no_1,int pin_no_2);
\ No newline at end of file diff --git a/OpenModelica_Arduino_With_MDD/Resources/Include/ieeesingle2num.h b/OpenModelica_Arduino_With_MDD/Resources/Include/ieeesingle2num.h new file mode 100644 index 0000000..27d701a --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/Resources/Include/ieeesingle2num.h @@ -0,0 +1,3 @@ +long int hex2dec(char hexadecimal[]); +void dec2hex(long int decimalnum,char hexadecimalnum[]); +double ieeesingle2num(char hexa[]);
\ No newline at end of file diff --git a/OpenModelica_Arduino_With_MDD/Resources/Include/modbus.h b/OpenModelica_Arduino_With_MDD/Resources/Include/modbus.h new file mode 100644 index 0000000..7a5c8d1 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/Resources/Include/modbus.h @@ -0,0 +1,4 @@ +double read_val(int addr_byte); +void read_voltage(); +void read_current(); +void read_active_power();
\ No newline at end of file diff --git a/OpenModelica_Arduino_With_MDD/Resources/Include/serial.h b/OpenModelica_Arduino_With_MDD/Resources/Include/serial.h new file mode 100644 index 0000000..c0cfed5 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/Resources/Include/serial.h @@ -0,0 +1,28 @@ +#include <errno.h> +#include <termios.h> +#include <unistd.h> +#include <fcntl.h> +#include <string.h> /* memset */ +#include <stdio.h> + +int set_interface_attribs (int fd, int speed, int parity); +void set_blocking (int b, int should_block); +int open_serial(int handle,int port, int baudrate); +int close_serial(int handle); +int write_serial(int handle, char str[],int size); +int status_serial(int handle,int nb[]); +int read_serial(int handle,char* buf,int size); +//int read_serial(int *handle,char buf[],int *size); + +void delay(long int t); + + + +/*int set_interface_attribs (int fd, int speed, int parity); +void set_blocking (int b, int should_block); +void open_serial(int *handle,int *port, int *baudrate, int *OK); +void close_serial(int *handle, int *OK); +void write_serial(int *handle, char str[],int *size, int *OK); +void status_serial(int *handle, int *OK,int *nbread, int *nbwrite); +void read_serial(int *handle,char buf[],int *size); +*/
\ No newline at end of file diff --git a/OpenModelica_Arduino_With_MDD/Resources/Include/servomotor.h b/OpenModelica_Arduino_With_MDD/Resources/Include/servomotor.h new file mode 100644 index 0000000..53b7457 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/Resources/Include/servomotor.h @@ -0,0 +1,3 @@ +void cmd_servo_attach(int h,int servo_no); +void cm_servo_move(int h,int servo_no,int u1); +void cmd_servo_detach(int h,int servo_no);
\ No newline at end of file diff --git a/OpenModelica_Arduino_With_MDD/Resources/Library/cmd_analog.o b/OpenModelica_Arduino_With_MDD/Resources/Library/cmd_analog.o Binary files differnew file mode 100644 index 0000000..47df91e --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/Resources/Library/cmd_analog.o diff --git a/OpenModelica_Arduino_With_MDD/Resources/Library/cmd_analog_volt.o b/OpenModelica_Arduino_With_MDD/Resources/Library/cmd_analog_volt.o Binary files differnew file mode 100644 index 0000000..0f94393 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/Resources/Library/cmd_analog_volt.o diff --git a/OpenModelica_Arduino_With_MDD/Resources/Library/cmd_digital.o b/OpenModelica_Arduino_With_MDD/Resources/Library/cmd_digital.o Binary files differnew file mode 100644 index 0000000..e05c668 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/Resources/Library/cmd_digital.o diff --git a/OpenModelica_Arduino_With_MDD/Resources/Library/dcmotor.o b/OpenModelica_Arduino_With_MDD/Resources/Library/dcmotor.o Binary files differnew file mode 100644 index 0000000..f86e9c6 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/Resources/Library/dcmotor.o diff --git a/OpenModelica_Arduino_With_MDD/Resources/Library/delay.o b/OpenModelica_Arduino_With_MDD/Resources/Library/delay.o Binary files differnew file mode 100644 index 0000000..5aa9222 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/Resources/Library/delay.o diff --git a/OpenModelica_Arduino_With_MDD/Resources/Library/ieeesingle2num.o b/OpenModelica_Arduino_With_MDD/Resources/Library/ieeesingle2num.o Binary files differnew file mode 100644 index 0000000..9d35dc6 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/Resources/Library/ieeesingle2num.o diff --git a/OpenModelica_Arduino_With_MDD/Resources/Library/libAnalog.so b/OpenModelica_Arduino_With_MDD/Resources/Library/libAnalog.so Binary files differnew file mode 100644 index 0000000..cefb472 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/Resources/Library/libAnalog.so diff --git a/OpenModelica_Arduino_With_MDD/Resources/Library/libAnalogv.so b/OpenModelica_Arduino_With_MDD/Resources/Library/libAnalogv.so Binary files differnew file mode 100644 index 0000000..c344625 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/Resources/Library/libAnalogv.so diff --git a/OpenModelica_Arduino_With_MDD/Resources/Library/libDCMotor.so b/OpenModelica_Arduino_With_MDD/Resources/Library/libDCMotor.so Binary files differnew file mode 100644 index 0000000..e1be915 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/Resources/Library/libDCMotor.so diff --git a/OpenModelica_Arduino_With_MDD/Resources/Library/libDigital.so b/OpenModelica_Arduino_With_MDD/Resources/Library/libDigital.so Binary files differnew file mode 100644 index 0000000..8ae4c56 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/Resources/Library/libDigital.so diff --git a/OpenModelica_Arduino_With_MDD/Resources/Library/libModbus.so b/OpenModelica_Arduino_With_MDD/Resources/Library/libModbus.so Binary files differnew file mode 100644 index 0000000..0247a2c --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/Resources/Library/libModbus.so diff --git a/OpenModelica_Arduino_With_MDD/Resources/Library/libSerialComm.so b/OpenModelica_Arduino_With_MDD/Resources/Library/libSerialComm.so Binary files differnew file mode 100644 index 0000000..9f20a5e --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/Resources/Library/libSerialComm.so diff --git a/OpenModelica_Arduino_With_MDD/Resources/Library/libServoMotor.so b/OpenModelica_Arduino_With_MDD/Resources/Library/libServoMotor.so Binary files differnew file mode 100644 index 0000000..bd8977a --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/Resources/Library/libServoMotor.so diff --git a/OpenModelica_Arduino_With_MDD/Resources/Library/libdelay.so b/OpenModelica_Arduino_With_MDD/Resources/Library/libdelay.so Binary files differnew file mode 100644 index 0000000..65b5090 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/Resources/Library/libdelay.so diff --git a/OpenModelica_Arduino_With_MDD/Resources/Library/libfloor.so b/OpenModelica_Arduino_With_MDD/Resources/Library/libfloor.so Binary files differnew file mode 100644 index 0000000..9550ad1 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/Resources/Library/libfloor.so diff --git a/OpenModelica_Arduino_With_MDD/Resources/Library/mfloor.o b/OpenModelica_Arduino_With_MDD/Resources/Library/mfloor.o Binary files differnew file mode 100644 index 0000000..2785ec6 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/Resources/Library/mfloor.o diff --git a/OpenModelica_Arduino_With_MDD/Resources/Library/modbus.o b/OpenModelica_Arduino_With_MDD/Resources/Library/modbus.o Binary files differnew file mode 100644 index 0000000..d465071 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/Resources/Library/modbus.o diff --git a/OpenModelica_Arduino_With_MDD/Resources/Library/serialComm.o b/OpenModelica_Arduino_With_MDD/Resources/Library/serialComm.o Binary files differnew file mode 100644 index 0000000..cf30ea8 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/Resources/Library/serialComm.o diff --git a/OpenModelica_Arduino_With_MDD/Resources/Library/servomotor.o b/OpenModelica_Arduino_With_MDD/Resources/Library/servomotor.o Binary files differnew file mode 100644 index 0000000..cdf0284 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/Resources/Library/servomotor.o diff --git a/OpenModelica_Arduino_With_MDD/Resources/src/cmd_analog.c b/OpenModelica_Arduino_With_MDD/Resources/src/cmd_analog.c new file mode 100644 index 0000000..5a8cf2f --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/Resources/src/cmd_analog.c @@ -0,0 +1,61 @@ +#include <errno.h> +#include <termios.h> +#include <unistd.h> +#include <fcntl.h> +#include <string.h> /* memset */ +#include <stdio.h> +#include <math.h> +#include <stdlib.h> +#include <stdint.h> +#include "../Include/serial.h" +#include "../Include/analog.h" + +uint16_t cmd_analog_in(int h,int pin_no) +{ + char pin[5],v1[2]; + int stat; + int read[3]; + sprintf(v1,"%c",pin_no+48); + strcpy(pin,"A"); + strcat(pin,v1); + int wr=write_serial(h,pin,2); + stat=status_serial(h,read); + //printf("Read:%d\n",read[0] ); + while (read[0] < 2) + stat=status_serial(h,read); + char values[5]; + int a_rd=read_serial(h,values,2); + values[2]='\0'; + printf("%s\n",values); + int l=strlen(values); + //printf("%d\n",l ); + uint8_t temp[l+1]; + int i; + for (i = 0; i < l; ++i) + { + temp[i]=(uint8_t)(values[i]); + } + //printf("%u %u\n",temp[0],temp[1]); + uint16_t result=(uint16_t)(256*temp[1]+temp[0]); + //printf("%u\n",result); + return result; +} + +int cmd_analog_out(int h,int pin_no,double val) +{ + char v1[2],v2[2]; + if(val > 255) + val = 255; + else if(val < 0) + val = 0; + //printf("%f\n",val); + char code_sent[10]; + strcpy(code_sent,"W"); + sprintf(v1,"%c",pin_no+48); + sprintf(v2,"%c",abs(ceil(val))); + strcat(code_sent,v1); + strcat(code_sent,v2); + //printf("%s\n",code_sent); + return write_serial(h,code_sent,3); + +}
\ No newline at end of file diff --git a/OpenModelica_Arduino_With_MDD/Resources/src/cmd_analog_volt.c b/OpenModelica_Arduino_With_MDD/Resources/src/cmd_analog_volt.c new file mode 100644 index 0000000..701c0c0 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/Resources/src/cmd_analog_volt.c @@ -0,0 +1,63 @@ +#include <errno.h> +#include <termios.h> +#include <unistd.h> +#include <fcntl.h> +#include <string.h> /* memset */ +#include <stdio.h> +#include <math.h> +#include <stdint.h> +#include <stdlib.h> +#include "../Include/serial.h" +#include "../Include/analogv.h" + +uint16_t cmd_analog_in_volt(int h,int pin_no) +{ + char pin[5]="A",v1[2]; + int stat; + int read[3]; + sprintf(v1,"%c",pin_no+48); + //strcpy(pin,"A"); + strcat(pin,v1); + int wr=write_serial(h,pin,2); + stat=status_serial(h,read); + //printf("Read:%d\n",read[0] ); + while (read[0] < 2) + stat=status_serial(h,read); + char values[5]; + int a_rd=read_serial(h,values,2); + values[2]='\0'; + printf("%s\n",values); + int l=strlen(values); + //printf("%d\n",l ); + uint8_t temp[l+1]; + int i; + for (i = 0; i < l; ++i) + { + temp[i]=(uint8_t)(values[i]); + } + //printf("%u %u\n",temp[0],temp[1]); + uint16_t result=(uint16_t)(256*temp[1]+temp[0]); + result/=1023; + //printf("%u\n",result); + return result; +} + +int cmd_analog_out_volt(int h,int pin_no,double val) +{ + char v1[2],v2[2]; + if(val > 5) + val = 5; + else if(val < 0) + val = 0; + val=val*255/5; + //printf("%f\n",val); + char code_sent[10]; + strcpy(code_sent,"W"); + sprintf(v1,"%c",pin_no+48); + sprintf(v2,"%c",abs(ceil(val))); + strcat(code_sent,v1); + strcat(code_sent,v2); + //printf("%s\n",code_sent); + return write_serial(h,code_sent,3); + +}
\ No newline at end of file diff --git a/OpenModelica_Arduino_With_MDD/Resources/src/cmd_digital.c b/OpenModelica_Arduino_With_MDD/Resources/src/cmd_digital.c new file mode 100644 index 0000000..f19d23b --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/Resources/src/cmd_digital.c @@ -0,0 +1,63 @@ +#include <errno.h> +#include <termios.h> +#include <unistd.h> +#include <fcntl.h> +#include <string.h> /* memset */ +#include <stdio.h> +#include <stdlib.h> +#include "../Include/serial.h" +#include "../Include/digital.h" + +int cmd_digital_out(int h,int pin_no,int val) +{ + int wr; + char pin[6]="Da"; + char v[2],temp[2]; + sprintf(temp,"%c",pin_no+48); + strcat(pin,temp); + strcat(pin,"1"); + //printf("%s",pin); + wr=write_serial(h,pin,4); + if (val > 0.5) + val = 1; + else + val = 0; + + sprintf(v,"%d",val); + strcpy(pin,"Dw"); + strcat(pin,temp); + strcat(pin,v); + //printf("%s",pin); + wr=write_serial(h,pin,4); + return wr; +} + +int cmd_digital_in(int h,int pin_no) +{ + int value = 0; + char pin[6]="Da"; + char v1[2],v2[2]; + int wr1, wr2; + sprintf(v1,"%c",pin_no+48); + strcat(pin,v1); + strcat(pin,"0"); + //printf("%s\n",pin); + wr1=write_serial(h,pin,4); + + strcpy(pin,"Dr"); + sprintf(v2,"%c",pin_no+48); + strcat(pin,v2); + wr2=write_serial(1,pin,3); + //binary transfer + int stat; + int num_bytes[2]; + char st[10]; + stat=status_serial(h,num_bytes); + while(num_bytes[0]<1) + stat=status_serial(h,num_bytes); + char* temp; + int wr=read_serial(h,st,1); + value=strtod(st,&temp); + //printf("%d\n",value); + return value; +} diff --git a/OpenModelica_Arduino_With_MDD/Resources/src/cmd_encoder_init.c b/OpenModelica_Arduino_With_MDD/Resources/src/cmd_encoder_init.c new file mode 100644 index 0000000..89a53dd --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/Resources/src/cmd_encoder_init.c @@ -0,0 +1,39 @@ +#include <errno.h> +#include <string.h> +#include <stdio.h> +#include <math.h> +#include <stdlib.h> +#include "../Include/encoder.h" +#include "../Include/serial.h" + +void cmd_encoder_init(int h,int enc_mode,int pin_no_1,int pin_no_2) +{ + + int wr; + char code_sent[10]="Ea"; + char c[2]; + + sprintf(c,"%c",48+corresp[block->rpar[2]]); + strcat(code_sent,c); + if(block.rpar(2)==4) + { + char c1[2],c2[2],v[10]; + sprintf(c1,"%c",48+0+corresp[block->rpar[3]]); + sprintf(v,"%s",(block->rpar[1])); + strcat(code_sent,c1); + strcat(code_sent,v); + } + else + { + char c2[2],v[10]; + sprintf(c2,"%c",48+0+corresp[block->rpar[3]]); + sprintf(v,"%s",block->rpar[1]); + strcat(code_sent,c1); + strcat(code_sent,v); + } + wr=write_serial(1,code_sent,5); + strcpy(code_sent,"Ez"); + sprintf(c,"%c",corresp[block->rpar[2]]) + strcat(code_sent,c); + wr=write_serial(1,code_sent,3) +}
\ No newline at end of file diff --git a/OpenModelica_Arduino_With_MDD/Resources/src/dcmotor.c b/OpenModelica_Arduino_With_MDD/Resources/src/dcmotor.c new file mode 100644 index 0000000..ac6775c --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/Resources/src/dcmotor.c @@ -0,0 +1,117 @@ +#include <errno.h> +#include <termios.h> +#include <unistd.h> +#include <fcntl.h> +#include <string.h> +#include <stdio.h> +#include <math.h> +#include "../Include/serial.h" +#include "../Include/dcmotor.h" + +#define abs(x) (x>=0?x:-x) + +void cmd_dcmotor_setup(int h,int driver_type,int motor_no,int pin_no_1,int pin_no_2) +{ + printf("init DCmotor\n"); + char code_sent[10]="C"; + int wr; + char v1[2],v2[2],motor[2]; + if(driver_type==1) + { + sprintf(v1,"%c",pin_no_1+48); + sprintf(v2,"%c",pin_no_2+48); + sprintf(motor,"%c",motor_no+48); + strcat(code_sent,motor); + strcat(code_sent,v1); + strcat(code_sent,v2); + strcat(code_sent,"1"); + } + //code_sent="C"+string(motor_no)+ascii(48+pin_no_1)+ascii(48+pin_no_2)+"1"; //adafruit + else if(driver_type==2) + { + sprintf(v1,"%c",pin_no_1+48); + sprintf(v2,"%c",pin_no_2+48); + sprintf(motor,"%c",motor_no+48); + strcat(code_sent,motor); + strcat(code_sent,v1); + strcat(code_sent,v2); + strcat(code_sent,"1"); + } + //code_sent="C"+string(motor_no)+ascii(48+pin_no_1)+ascii(48+pin_no_2)+"1"; //code pour initialiser L298 + else if(driver_type==3) + { + sprintf(v1,"%c",pin_no_1+48); + sprintf(v2,"%c",pin_no_2+48); + sprintf(motor,"%c",motor_no+48); + strcat(code_sent,motor); + strcat(code_sent,v1); + strcat(code_sent,v2); + strcat(code_sent,"0"); + + } + // code_sent="C"+string(motor_no)+ascii(48+pin_no_1)+ascii(48+pin_no_2)+"0"; //code pour initialiser L293 + //printf("%s\n",code_sent); + wr=write_serial(h,code_sent,5); + + int stat; + int num_bytes[2]; + //Attente que l'arduino reponde OK + stat=status_serial(1,num_bytes); + while (num_bytes[0] < 2) + stat=status_serial(1,num_bytes); + char values[5]; + int dcm_rd=read_serial(1,values,2); + if (dcm_rd == 0) + printf("Init motor successful\n"); + else + printf("Init motor unsuccessful\n"); +} + +void cmd_dcmotor_run(int h,int motor_no,int u1) +{ + char code_dir[2]; + char code_sent[10]="M"; + char motor[2]; + int val; + char v[2]; + if(u1>=0) + sprintf(code_dir,"%c",49); + //code_dir=ascii(49); + else + sprintf(code_dir,"%c",48); + //code_dir=ascii(48); + if(abs(u1)>255) + val=255; + else + val=abs(ceil(u1)); + //printf("%d\n",val); + sprintf(motor,"%c",motor_no+48); + sprintf(v,"%c",val); + strcat(code_sent,motor); + strcat(code_sent,code_dir); + strcat(code_sent,v); + //printf("%s\n",code_sent); + //code_sent="M"+ascii(48+motor_no)+code_dir+ascii(val); + int wr=write_serial(h,code_sent,4); +} + +void cmd_dcmotor_release(int h,int motor_no) +{ + char code_sent[6]="M"; + char motor[2]; + char v[2]; + sprintf(motor,"%c",motor_no+48); + sprintf(v,"%c",0); + strcat(code_sent,motor); + strcat(code_sent,"1"); + strcat(code_sent,v); + //code_sent="M"+ascii(48+motor_no)+"1"+ascii(0); + //printf("%s\n",code_sent); + int wr=write_serial(h,code_sent,4); + strcpy(code_sent,"M"); + strcat(code_sent,motor); + strcat(code_sent,"r"); + //printf("%s\n",code_sent); + //code_sent="M"+ascii(48+motor_no)+"r"; + wr=write_serial(h,code_sent,3); +} diff --git a/OpenModelica_Arduino_With_MDD/Resources/src/delay.c b/OpenModelica_Arduino_With_MDD/Resources/src/delay.c new file mode 100644 index 0000000..707a9bd --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/Resources/src/delay.c @@ -0,0 +1,10 @@ +#include <stdio.h> +#include <stdlib.h> +#include <time.h> +#include <math.h> +#include <unistd.h> + +void delay(long int t) +{ + usleep(abs(t*1000)); +}
\ No newline at end of file diff --git a/OpenModelica_Arduino_With_MDD/Resources/src/ieeesingle2num.c b/OpenModelica_Arduino_With_MDD/Resources/src/ieeesingle2num.c new file mode 100644 index 0000000..7331193 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/Resources/src/ieeesingle2num.c @@ -0,0 +1,87 @@ +#include <errno.h> +#include <termios.h> +#include <unistd.h> +#include <fcntl.h> +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <ctype.h> +#include "../Include/serial.h" + +#ifdef NAN +/* NAN is supported */ +#endif +#ifdef INFINITY +/* INFINITY is supported */ +#endif + + +long int hex2dec(char hexadecimal[]) +{ + long int decimalNumber=0; + char hexDigits[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', + '9', 'A', 'B', 'C', 'D', 'E', 'F'}; + int i, j, power=0; + + /* Converting hexadecimal number to decimal number */ + for(i=strlen(hexadecimal)-1; i >= 0; i--) { + /*search currect character in hexDigits array */ + if(isalpha(hexadecimal[i])) + hexadecimal[i]=toupper(hexadecimal[i]); + for(j=0; j<16; j++){ + if(hexadecimal[i] == hexDigits[j]){ + decimalNumber += j*pow(16, power); + } + // } + power++; + } + } + return decimalNumber; +} + +void dec2hex(long int decimalnum,char hexadecimalnum[]) +{ + long quotient, remainder; + int j = 1; + quotient = decimalnum; + + while (quotient != 0) + { + remainder = quotient % 16; + if (remainder < 10) + hexadecimalnum[j--] = 48 + remainder; + else + hexadecimalnum[j--] = 55 + remainder; + quotient = quotient / 16; + } + hexadecimalnum[2]='\0'; +} + +double ieeesingle2num(char hexa[]) +{ + long int x=hex2dec(hexa); + long int k =(long int)pow(2,31); //pow2(31); + int s = (x >= k); + if (s) + x = x - k; + //t = pow2(x,-23); + double t = x*pow(2,-23); + long int e = floor(t); + double f = t - e; + double y; + if (e == 255) + if(f == 0) + y = INFINITY; + else + y = NAN; + else if(e > 0) + y = (1+f)*pow(2,e-127); + //y = (1+f).*2.^(e-127); + else + y = f*pow(2,-126); + //y = f.*2.^-126; + if (s) + y = -y; + return y; +}
\ No newline at end of file diff --git a/OpenModelica_Arduino_With_MDD/Resources/src/mfloor.c b/OpenModelica_Arduino_With_MDD/Resources/src/mfloor.c new file mode 100644 index 0000000..3c9e884 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/Resources/src/mfloor.c @@ -0,0 +1,6 @@ +#include <math.h> + +int mfloor(double x) +{ + return floor(x); +}
\ No newline at end of file diff --git a/OpenModelica_Arduino_With_MDD/Resources/src/modbus.c b/OpenModelica_Arduino_With_MDD/Resources/src/modbus.c new file mode 100644 index 0000000..160bfb5 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/Resources/src/modbus.c @@ -0,0 +1,449 @@ +#include <errno.h> +#include <termios.h> +#include <unistd.h> +#include <fcntl.h> +#include <string.h> +#include <stdio.h> +#include <math.h> +#include "../Include/serial.h" +#include "../Include/ieeesingle2num.h" +#include "../Include/modbus.h" + +char ascii_n(int num) +{ + return (char)num; +} + +int ascii_c(char c) +{ + return (int)c; +} + +void read_voltage() +{ + char arr[9]={ascii_n(1),ascii_n(3),ascii_n(15),ascii_n(86),ascii_n(00),ascii_n(2),ascii_n(39),ascii_n(15),'\0'}; + + //printf("%s\n",arr);//debug + + int x,wr,rd; + char buf[12]; + for(x=0;x<5;x++) + { + wr=write_serial(1,arr,8); + rd = read_serial(1,buf,11); + usleep(500); + } + buf[11]='\0'; + + //printf("%s\n",buf );//debug + + int b1=0,b2=0,b3=0,b4=0; + int myresult[12]; + int i; + for (i = 0; i < 11; ++i) + { + myresult[i]=ascii_c(buf[i]); + //printf("%d",myresult[i]);//debug + } + + //printf("%d %d %d %d\n",myresult[4],myresult[5],myresult[6],myresult[7]);//debug + + int a1=myresult[4]; + if (a1<16) + { + b1=1; + } + char v1[3]; + dec2hex(a1,v1); + if (b1) + { + sprintf(v1,"0%s",v1); + } + else + { + sprintf(v1,"%s",v1); + } + int a2=myresult[5]; + if (a2<16) + { + b2=1; + } + char v2[3]; + dec2hex(a2,v2); + if (b2) + { + sprintf(v2,"0%s",v2); + } + else + { + sprintf(v2,"%s",v2); + } + int a3=myresult[6]; + if (a3<16) + { + b3=1; + } + char v3[3]; + dec2hex(a3,v3); + if (b3) + { + sprintf(v3,"0%s",v3); + } + else + { + sprintf(v3,"%s",v3); + } + int a4=myresult[7]; + if (a4<16) + { + b4=1; + } + char v4[3]; + dec2hex(a4,v4); + if (b4) + { + sprintf(v4,"0%s",v4); + } + else + { + sprintf(v4,"%s",v4); + } + char a6[20]=""; + strcat(a6,v3); + strcat(a6,v4); + strcat(a6,v1); + strcat(a6,v2); + a6[8]='\0'; + + //printf("%s",a6);//debug + + int cl=close_serial(1); + double p=ieeesingle2num(a6); + printf("Voltage(in V)=%f\n",p); +} + + +void read_current() +{ + char arr[9]={ascii_n(1),ascii_n(3),ascii_n(15),ascii_n(88),ascii_n(00),ascii_n(2),ascii_n(70),ascii_n(204),'\0'}; + //printf("%s\n",arr);//debug + + int x,wr,rd; + char buf[12]; + for(x=0;x<5;x++) + { + wr=write_serial(1,arr,8); + rd = read_serial(1,buf,11); + usleep(500); + } + buf[11]='\0'; + + //printf("%s\n",buf );//debug + + int b1=0,b2=0,b3=0,b4=0; + int myresult[12]; + int i; + for (i = 0; i < 11; ++i) + { + myresult[i]=ascii_c(buf[i]); + //printf("%d",myresult[i]);//debug + } + + //printf("%d %d %d %d\n",myresult[4],myresult[5],myresult[6],myresult[7]);//debug + + int a1=myresult[4]; + if (a1<16) + { + b1=1; + } + char v1[3]; + dec2hex(a1,v1); + if (b1) + { + sprintf(v1,"0%s",v1); + } + else + { + sprintf(v1,"%s",v1); + } + int a2=myresult[5]; + if (a2<16) + { + b2=1; + } + char v2[3]; + dec2hex(a2,v2); + if (b2) + { + sprintf(v2,"0%s",v2); + } + else + { + sprintf(v2,"%s",v2); + } + int a3=myresult[6]; + if (a3<16) + { + b3=1; + } + char v3[3]; + dec2hex(a3,v3); + if (b3) + { + sprintf(v3,"0%s",v3); + } + else + { + sprintf(v3,"%s",v3); + } + int a4=myresult[7]; + if (a4<16) + { + b4=1; + } + char v4[3]; + dec2hex(a4,v4); + if (b4) + { + sprintf(v4,"0%s",v4); + } + else + { + sprintf(v4,"%s",v4); + } + char a6[20]=""; + strcat(a6,v3); + strcat(a6,v4); + strcat(a6,v1); + strcat(a6,v2); + a6[8]='\0'; + + //printf("%s",a6);//debug + + int cl=close_serial(1); + double p=ieeesingle2num(a6); + printf("Current(in A)=%f\n",p); +} + +void read_active_power() +{ + char arr[9]={ascii_n(1),ascii_n(3),ascii_n(15),ascii_n(78),ascii_n(00),ascii_n(2),ascii_n(167),ascii_n(8),'\0'}; + //printf("%s\n",arr);//debug + + int x,wr,rd; + char buf[12]; + for(x=0;x<5;x++) + { + wr=write_serial(1,arr,8); + rd = read_serial(1,buf,11); + usleep(500); + } + buf[11]='\0'; + + //printf("%s\n",buf );//debug + + int b1=0,b2=0,b3=0,b4=0; + int myresult[12]; + int i; + for (i = 0; i < 11; ++i) + { + myresult[i]=ascii_c(buf[i]); + //printf("%d",myresult[i]);//debug + } + + //printf("%d %d %d %d\n",myresult[4],myresult[5],myresult[6],myresult[7]);//debug + + int a1=myresult[4]; + if (a1<16) + { + b1=1; + } + char v1[3]; + dec2hex(a1,v1); + if (b1) + { + sprintf(v1,"0%s",v1); + } + else + { + sprintf(v1,"%s",v1); + } + int a2=myresult[5]; + if (a2<16) + { + b2=1; + } + char v2[3]; + dec2hex(a2,v2); + if (b2) + { + sprintf(v2,"0%s",v2); + } + else + { + sprintf(v2,"%s",v2); + } + int a3=myresult[6]; + if (a3<16) + { + b3=1; + } + char v3[3]; + dec2hex(a3,v3); + if (b3) + { + sprintf(v3,"0%s",v3); + } + else + { + sprintf(v3,"%s",v3); + } + int a4=myresult[7]; + if (a4<16) + { + b4=1; + } + char v4[3]; + dec2hex(a4,v4); + if (b4) + { + sprintf(v4,"0%s",v4); + } + else + { + sprintf(v4,"%s",v4); + } + char a6[20]=""; + strcat(a6,v3); + strcat(a6,v4); + strcat(a6,v1); + strcat(a6,v2); + a6[8]='\0'; + + //printf("%s",a6);//debug + + int cl=close_serial(1); + double p=ieeesingle2num(a6); + printf("Active Power(in W)=%f\n",p); +} + +double read_val(int addr_byte) +{ + char* arr; + if(addr_byte==86) + { + char code[9]={ascii_n(1),ascii_n(3),ascii_n(15),ascii_n(86),ascii_n(00),ascii_n(2),ascii_n(39),ascii_n(15),'\0'}; + arr = code; + printf("Voltage(in V)="); + } + else if(addr_byte==88) + { + char code[9]={ascii_n(1),ascii_n(3),ascii_n(15),ascii_n(88),ascii_n(00),ascii_n(2),ascii_n(70),ascii_n(204),'\0'}; + arr =code; + printf("Current(in A)="); + } + else if(addr_byte==78) + { + char code[9]={ascii_n(1),ascii_n(3),ascii_n(15),ascii_n(78),ascii_n(00),ascii_n(2),ascii_n(167),ascii_n(8),'\0'}; + arr = code; + printf("Active Power(in W)="); + } + //printf("%s\n",arr);//debug + + int x,wr,rd; + char buf[12]; + for(x=0;x<5;x++) + { + wr=write_serial(1,arr,8); + rd = read_serial(1,buf,11); + usleep(500); + } + buf[11]='\0'; + + //printf("%s\n",buf );//debug + + int b1=0,b2=0,b3=0,b4=0; + int myresult[12]; + int i; + for (i = 0; i < 11; ++i) + { + myresult[i]=ascii_c(buf[i]); + //printf("%d",myresult[i]);//debug + } + + //printf("%d %d %d %d\n",myresult[4],myresult[5],myresult[6],myresult[7]);//debug + + int a1=myresult[4]; + if (a1<16) + { + b1=1; + } + char v1[3]; + dec2hex(a1,v1); + if (b1) + { + sprintf(v1,"0%s",v1); + } + else + { + sprintf(v1,"%s",v1); + } + int a2=myresult[5]; + if (a2<16) + { + b2=1; + } + char v2[3]; + dec2hex(a2,v2); + if (b2) + { + sprintf(v2,"0%s",v2); + } + else + { + sprintf(v2,"%s",v2); + } + int a3=myresult[6]; + if (a3<16) + { + b3=1; + } + char v3[3]; + dec2hex(a3,v3); + if (b3) + { + sprintf(v3,"0%s",v3); + } + else + { + sprintf(v3,"%s",v3); + } + int a4=myresult[7]; + if (a4<16) + { + b4=1; + } + char v4[3]; + dec2hex(a4,v4); + if (b4) + { + sprintf(v4,"0%s",v4); + } + else + { + sprintf(v4,"%s",v4); + } + char a6[20]=""; + strcat(a6,v3); + strcat(a6,v4); + strcat(a6,v1); + strcat(a6,v2); + a6[8]='\0'; + + //printf("%s",a6);//debug + + int cl=close_serial(1); + double p=ieeesingle2num(a6); + printf("%f\n",p); + return p; +} diff --git a/OpenModelica_Arduino_With_MDD/Resources/src/serialComm.c b/OpenModelica_Arduino_With_MDD/Resources/src/serialComm.c new file mode 100644 index 0000000..6fd915a --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/Resources/src/serialComm.c @@ -0,0 +1,156 @@ +#include <errno.h> +#include <termios.h> +#include <unistd.h> +#include <fcntl.h> +#include <string.h> /* memset */ +#include <stdio.h> +#include <stropts.h> +#include "../Include/serial.h" +#define MAXPORTS 5 +static int fd; + +int set_interface_attribs (int fd, int speed, int parity) +{ + struct termios tty; + memset (&tty, 0, sizeof(tty)); + if (tcgetattr (fd, &tty) != 0) + { + return -1; + } + int posix_baudrate=0; + + switch(speed) { + case 115200: posix_baudrate = B115200; break; + //default: return -1; + } + cfsetospeed (&tty, posix_baudrate); + cfsetispeed (&tty, posix_baudrate); + + tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8; // 8-bit chars + // disable IGNBRK for mismatched speed tests; otherwise receive break + // as \000 chars + tty.c_iflag &= ~IGNBRK; // disable break processing + tty.c_lflag = 0; // no signaling chars, no echo, + // no canonical processing + tty.c_oflag = 0; // no remapping, no delays + tty.c_cc[VMIN] = 0; // read doesn't block + tty.c_cc[VTIME] = 5; // 0.5 seconds read timeout + + tty.c_iflag &= ~(IXON | IXOFF | IXANY); // shut off xon/xoff ctrl + + tty.c_cflag |= (CLOCAL | CREAD);// ignore modem controls, + // enable reading + tty.c_cflag &= ~(PARENB | PARODD); // shut off parity + tty.c_cflag |= parity; + tty.c_cflag &= ~CSTOPB; + tty.c_cflag &= ~CRTSCTS; + + if (tcsetattr (fd, TCSANOW, &tty) != 0) + { + return -1; + } + return 0; +} + + +void set_blocking (int b, int should_block) +{ + struct termios tty; + memset (&tty, 0, sizeof tty); + if (tcgetattr (b, &tty) != 0) + { + return; + } + + tty.c_cc[VMIN] = should_block ? 1 : 0; + tty.c_cc[VTIME] = 5; // 0.5 seconds read timeout + + //if (tcsetattr (fd, TCSANOW, &tty) != 0) + // error_message ("error %d setting term attributes", errno); +} + +int open_serial(int handle,int port, int baudrate){ + char* portname; + //printf("%d\n",port); + int OK; + switch(port){ + case 0: portname = "//dev/ttyACM0";break; + case 1: portname = "//dev/ttyACM1";break; + case 2: portname = "//dev/ttyACM2";break; + case 3: portname = "//dev/ttyACM3";break; + case 4: portname = "//dev/ttyACM4";break; + case 5: portname = "//dev/ttyACM5";break; + case 6: portname = "//dev/ttyACM6";break; + case 7: portname = "//dev/ttyACM7";break; + //default : return 2; + } + OK = 0; + //printf("%s\n",portname); + fd = open (portname, O_RDWR | O_NOCTTY | O_SYNC); + //fd = open (portname, O_RDWR | O_NOCTTY); //srikant + //printf("%d\n",fd); + if (fd < 0) + { + OK=2; + return OK; + } + set_interface_attribs (fd, baudrate, 0); + set_blocking (fd, 0); // set no blocking + //printf("Program running with status : %d\n",OK); + return OK; +} + +int close_serial(int handle){ + //usleep(1000); + close(fd); + //printf("Program closing....\n"); + return 0; +} + +int write_serial(int handle, char str[],int size){ + if(write(fd, str, size)!=-1) + { + //printf("serial write started.\n"); + //printf("%s\n",str ); + //printf("%d\n",(int)str[0] ); + } + usleep(size*100); + return 0; +} + + +int status_serial(int handle,int nb[]){ + nb[0] = 2; + nb[1] = 2; + int OK=0; + //printf("Getting status.....\n"); + return OK; +} + +int read_serial(int handle,char buf[],int size){ + + char readbuf[size+1]; + //int fl=tcflush(fd,TCOFLUSH); + //int fl=ioctl(fd,I_FLUSH,FLUSHW); + if(read(fd, readbuf, size)!=-1) + { + readbuf[size]='\0'; + int i; + for (i = 0; i < size; ++i) + { + buf[i]=(readbuf[i]); + //printf("%u\n",buf[i] ); + } + buf[size]='\0'; + //printf("Reading has commenced..\n"); + //printf("%d\n",(int)strlen(readbuf)); + //printf("%s\n",readbuf); + return 0; + } + else + return 2 ; +} +/*void read_serial(int *handle,char buf[],int *size){ + read(fd, buf, *size); + printf("Reading has commenced..\n"); +}*/ diff --git a/OpenModelica_Arduino_With_MDD/Resources/src/serialComm.c~ b/OpenModelica_Arduino_With_MDD/Resources/src/serialComm.c~ new file mode 100644 index 0000000..b7f0743 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/Resources/src/serialComm.c~ @@ -0,0 +1,156 @@ +#include <errno.h> +#include <termios.h> +#include <unistd.h> +#include <fcntl.h> +#include <string.h> /* memset */ +#include <stdio.h> +#include <stropts.h> +#include "../Include/serial.h" +#define MAXPORTS 5 +static int fd; + +int set_interface_attribs (int fd, int speed, int parity) +{ + struct termios tty; + memset (&tty, 0, sizeof(tty)); + if (tcgetattr (fd, &tty) != 0) + { + return -1; + } + int posix_baudrate=0; + + switch(speed) { + case 115200: posix_baudrate = B115200; break; + //default: return -1; + } + cfsetospeed (&tty, posix_baudrate); + cfsetispeed (&tty, posix_baudrate); + + tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8; // 8-bit chars + // disable IGNBRK for mismatched speed tests; otherwise receive break + // as \000 chars + tty.c_iflag &= ~IGNBRK; // disable break processing + tty.c_lflag = 0; // no signaling chars, no echo, + // no canonical processing + tty.c_oflag = 0; // no remapping, no delays + tty.c_cc[VMIN] = 0; // read doesn't block + tty.c_cc[VTIME] = 5; // 0.5 seconds read timeout + + tty.c_iflag &= ~(IXON | IXOFF | IXANY); // shut off xon/xoff ctrl + + tty.c_cflag |= (CLOCAL | CREAD);// ignore modem controls, + // enable reading + tty.c_cflag &= ~(PARENB | PARODD); // shut off parity + tty.c_cflag |= parity; + tty.c_cflag &= ~CSTOPB; + tty.c_cflag &= ~CRTSCTS; + + if (tcsetattr (fd, TCSANOW, &tty) != 0) + { + return -1; + } + return 0; +} + + +void set_blocking (int b, int should_block) +{ + struct termios tty; + memset (&tty, 0, sizeof tty); + if (tcgetattr (b, &tty) != 0) + { + return; + } + + tty.c_cc[VMIN] = should_block ? 1 : 0; + tty.c_cc[VTIME] = 5; // 0.5 seconds read timeout + + //if (tcsetattr (fd, TCSANOW, &tty) != 0) + // error_message ("error %d setting term attributes", errno); +} + +int open_serial(int handle,int port, int baudrate){ + char* portname; + //printf("%d\n",port); + int OK; + switch(port){ + case 0: portname = "//dev/ttyACM0";break; + case 1: portname = "//dev/ttyACM1";break; + case 2: portname = "//dev/ttyACM2";break; + case 3: portname = "//dev/ttyACM3";break; + case 4: portname = "//dev/ttyACM4";break; + case 5: portname = "//dev/ttyACM5";break; + case 6: portname = "//dev/ttyACM6";break; + case 7: portname = "//dev/ttyACM7";break; + //default : return 2; + } + OK = 0; + //printf("%s\n",portname); + fd = open (portname, O_RDWR | O_NOCTTY | O_SYNC); + //fd = open (portname, O_RDWR | O_NOCTTY); //srikant + //printf("%d\n",fd); + if (fd < 0) + { + OK=2; + return OK; + } + set_interface_attribs (fd, baudrate, 0); + set_blocking (fd, 0); // set no blocking + //printf("Program running with status : %d\n",OK); + return OK; +} + +int close_serial(int handle){ + //usleep(1000); + close(fd); + //printf("Program closing....\n"); + return 0; +} + +int write_serial(int handle, char str[],int size){ + if(write(fd, str, size)!=-1) + { + //printf("serial write started.\n"); + //printf("%s\n",str ); + //printf("%d\n",(int)str[0] ); + } + usleep(size*100); + return 0; +} + + +int status_serial(int handle,int nb[]){ + nb[0] = 2; + nb[1] = 2; + int OK=0; + //printf("Getting status.....\n"); + return OK; +} + +int read_serial(int handle,char buf[],int size){ + + char readbuf[size+1]; + //int fl=tcflush(fd,TCOFLUSH); + //int fl=ioctl(fd,I_FLUSH,FLUSHW); + if(read(fd, readbuf, size)!=-1) + { + readbuf[size]='\0'; + int i; + for (i = 0; i < size; ++i) + { + buf[i]=(readbuf[i]); + //printf("%u\n",buf[i] ); + } + buf[size]='\0'; + printf("Reading has commenced..\n"); + printf("%d\n",(int)strlen(readbuf)); + printf("%s\n",readbuf); + return 0; + } + else + return 2 ; +} +/*void read_serial(int *handle,char buf[],int *size){ + read(fd, buf, *size); + printf("Reading has commenced..\n"); +}*/ diff --git a/OpenModelica_Arduino_With_MDD/Resources/src/servomotor.c b/OpenModelica_Arduino_With_MDD/Resources/src/servomotor.c new file mode 100644 index 0000000..74048a3 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/Resources/src/servomotor.c @@ -0,0 +1,87 @@ +#include <errno.h> +#include <termios.h> +#include <unistd.h> +#include <fcntl.h> +#include <string.h> +#include <stdio.h> +#include <stdint.h> +#include <math.h> +#include "../Include/serial.h" +#include "../Include/servomotor.h" + +void cmd_servo_attach(int h,int servo_no) +{ + char pin[5]; + int wr; + printf("init servo write\n"); + if(servo_no==1)//servo 1 on pin 9 + { + strcpy(pin,"Sa1"); + //printf("%s\n",pin); + wr=write_serial(h,pin,3); + } + else if(servo_no==2)//servo 2 on pin 10 + { + strcpy(pin,"Sa2"); + wr=write_serial(h,pin,3); + } + else + perror("Error."); +} + + +void cmd_servo_move(int h,int servo_no,int u1) +{ + int wr; + char servo[2]; + char v[2]; + char pin[5]="Sw"; + if (u1<0) + { + sprintf(servo,"%c",48+servo_no); + sprintf(v,"%c",0); + strcat(pin,servo); + strcat(pin,v); + //printf("%s\n",pin ); + //pin="Sw"+ascii(48+servo_no)+ascii(0); + } + else if(u1>180) + { + sprintf(servo,"%c",48+servo_no); + sprintf(v,"%c",180); + strcat(pin,servo); + strcat(pin,v); + //printf("%s\n",pin ); + } //pin="Sw"+ascii(48+servo_no)+ascii(180); + else + { + sprintf(servo,"%c",48+servo_no); + sprintf(v,"%c",(uint8_t)u1); + strcat(pin,servo); + strcat(pin,v); + //printf("%s\n",pin ); + } //pin="Sw"+ascii(48+servo_no)+ascii(uint8(u1)); + wr=write_serial(1,pin,4); +} + + +void cmd_servo_detach(int h,int servo_no) +{ + int wr; + char pin[5]="Sd"; + if(servo_no==1) //servo 1 on pin 10 + { + strcat(pin,"1"); + //pin="Sd1" + wr=write_serial(h,pin,3); + } + else if(servo_no==2) //servo 2 on pin 9 + { + strcat(pin,"2"); + //pin="Sd2" + wr=write_serial(h,pin,3); + } + else + perror("Error."); + +}
\ No newline at end of file diff --git a/OpenModelica_Arduino_With_MDD/_gitignore b/OpenModelica_Arduino_With_MDD/_gitignore new file mode 100644 index 0000000..b3bdba3 --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/_gitignore @@ -0,0 +1,37 @@ +# Compiled source # +################### +*.com +*.class + +# Backup Files # +############ +*~ + +# Packages # +############ +# it's better to unpack these files and commit the raw source +# git has its own built in compression methods +*.7z +*.dmg +*.gz +*.iso +*.jar +*.rar +*.tar +*.zip + +# Logs and databases # +###################### +*.log +*.sql +*.sqlite + +# OS generated files # +###################### +.DS_Store +.DS_Store? +._* +.Spotlight-V100 +.Trashes +ehthumbs.db +Thumbs.db diff --git a/OpenModelica_Arduino_With_MDD/test_firmware.mo b/OpenModelica_Arduino_With_MDD/test_firmware.mo new file mode 100644 index 0000000..854d60f --- /dev/null +++ b/OpenModelica_Arduino_With_MDD/test_firmware.mo @@ -0,0 +1,20 @@ +model test_firmware "Testing SerialCommunication with Arduino" + +import sComm=Arduino.SerialCommunication.Functions; +Integer h(fixed = false); +Integer byte_read(fixed = false); +//String str(fixed =false); +Integer wr(fixed =false); +Integer c_OK(fixed =false); +algorithm + when initial() then + h:=sComm.open_serial(1,0,115200); + sComm.delay(2000); + wr:=sComm.write_serial(1,"v",1); + byte_read:= sComm.read_serial(1,2); + c_OK := sComm.close_serial(1) "To close the connection safely"; + end when; + annotation( + experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-6, Interval = 10)); + +end test_firmware;
\ No newline at end of file diff --git a/Report.tar.gz b/Report.tar.gz Binary files differnew file mode 100644 index 0000000..cb1615f --- /dev/null +++ b/Report.tar.gz diff --git a/Report/1.PNG b/Report/1.PNG Binary files differnew file mode 100644 index 0000000..4c9406f --- /dev/null +++ b/Report/1.PNG diff --git a/Report/2.PNG b/Report/2.PNG Binary files differnew file mode 100644 index 0000000..c0bdc01 --- /dev/null +++ b/Report/2.PNG diff --git a/Report/3.PNG b/Report/3.PNG Binary files differnew file mode 100644 index 0000000..af6f7ce --- /dev/null +++ b/Report/3.PNG diff --git a/Report/4.PNG b/Report/4.PNG Binary files differnew file mode 100644 index 0000000..5c91fc5 --- /dev/null +++ b/Report/4.PNG diff --git a/Report/5.PNG b/Report/5.PNG Binary files differnew file mode 100644 index 0000000..0b7b45f --- /dev/null +++ b/Report/5.PNG diff --git a/Report/6.PNG b/Report/6.PNG Binary files differnew file mode 100644 index 0000000..9840019 --- /dev/null +++ b/Report/6.PNG diff --git a/Report/7.PNG b/Report/7.PNG Binary files differnew file mode 100644 index 0000000..9e5c8eb --- /dev/null +++ b/Report/7.PNG diff --git a/Report/Final.aux b/Report/Final.aux new file mode 100644 index 0000000..99a75c7 --- /dev/null +++ b/Report/Final.aux @@ -0,0 +1,131 @@ +\relax +\providecommand\hyper@newdestlabel[2]{} +\providecommand\HyperFirstAtBeginDocument{\AtBeginDocument} +\HyperFirstAtBeginDocument{\ifx\hyper@anchor\@undefined +\global\let\oldcontentsline\contentsline +\gdef\contentsline#1#2#3#4{\oldcontentsline{#1}{#2}{#3}} +\global\let\oldnewlabel\newlabel +\gdef\newlabel#1#2{\newlabelxx{#1}#2} +\gdef\newlabelxx#1#2#3#4#5#6{\oldnewlabel{#1}{{#2}{#3}}} +\AtEndDocument{\ifx\hyper@anchor\@undefined +\let\contentsline\oldcontentsline +\let\newlabel\oldnewlabel +\fi} +\fi} +\global\let\hyper@last\relax +\gdef\HyperFirstAtBeginDocument#1{#1} +\providecommand\HyField@AuxAddToFields[1]{} +\providecommand\HyField@AuxAddToCoFields[2]{} +\@writefile{toc}{\contentsline {chapter}{\numberline {1}\textbf {Introduction}}{4}{chapter.1}} +\@writefile{lof}{\addvspace {10\p@ }} +\@writefile{lot}{\addvspace {10\p@ }} +\@writefile{toc}{\contentsline {chapter}{\numberline {2}\textbf {Implementation}}{5}{chapter.2}} +\@writefile{lof}{\addvspace {10\p@ }} +\@writefile{lot}{\addvspace {10\p@ }} +\@writefile{toc}{\contentsline {section}{\numberline {2.1}Algorithm}{5}{section.2.1}} +\@writefile{toc}{\contentsline {section}{\numberline {2.2}Making changes in source code}{6}{section.2.2}} +\@writefile{toc}{\contentsline {subsection}{\numberline {2.2.1}How to make changes to source code and make libraries}{6}{subsection.2.2.1}} +\@writefile{toc}{\contentsline {subsection}{\numberline {2.2.2}Working with Arduino UNO [Atmega328p]}{6}{subsection.2.2.2}} +\@writefile{toc}{\contentsline {subsection}{\numberline {2.2.3}Working with Tiva C [TM4C123G]}{7}{subsection.2.2.3}} +\@writefile{toc}{\contentsline {chapter}{\numberline {3}\textbf {Download and Installation}}{8}{chapter.3}} +\@writefile{lof}{\addvspace {10\p@ }} +\@writefile{lot}{\addvspace {10\p@ }} +\@writefile{toc}{\contentsline {section}{\numberline {3.1}OpenModelica}{8}{section.3.1}} +\@writefile{toc}{\contentsline {section}{\numberline {3.2}Arduino IDE}{8}{section.3.2}} +\@writefile{toc}{\contentsline {section}{\numberline {3.3}Energia IDE}{8}{section.3.3}} +\@writefile{toc}{\contentsline {chapter}{\numberline {4}\textbf {About OpenModelicaEmbedded package}}{9}{chapter.4}} +\@writefile{lof}{\addvspace {10\p@ }} +\@writefile{lot}{\addvspace {10\p@ }} +\@writefile{lof}{\contentsline {figure}{\numberline {4.1}{\ignorespaces Structure of OpenModelicaEmbedded package\relax }}{9}{figure.caption.4}} +\providecommand*\caption@xref[2]{\@setref\relax\@undefined{#1}} +\newlabel{figure:1}{{4.1}{9}{Structure of OpenModelicaEmbedded package\relax }{figure.caption.4}{}} +\@writefile{toc}{\contentsline {section}{\numberline {4.1}SynchronizeRealTime Block}{9}{section.4.1}} +\@writefile{lof}{\contentsline {figure}{\numberline {4.2}{\ignorespaces SymchronizeRealTime block\relax }}{10}{figure.caption.5}} +\newlabel{figure:2}{{4.2}{10}{SymchronizeRealTime block\relax }{figure.caption.5}{}} +\@writefile{toc}{\contentsline {section}{\numberline {4.2}Pins}{10}{section.4.2}} +\@writefile{lof}{\contentsline {figure}{\numberline {4.3}{\ignorespaces AnalogInput block\relax }}{11}{figure.caption.6}} +\newlabel{figure:3}{{4.3}{11}{AnalogInput block\relax }{figure.caption.6}{}} +\@writefile{lof}{\contentsline {figure}{\numberline {4.4}{\ignorespaces AnalogOutput block\relax }}{11}{figure.caption.7}} +\newlabel{figure:4}{{4.4}{11}{AnalogOutput block\relax }{figure.caption.7}{}} +\@writefile{lof}{\contentsline {figure}{\numberline {4.5}{\ignorespaces DigitalInput block\relax }}{12}{figure.caption.8}} +\newlabel{figure:5}{{4.5}{12}{DigitalInput block\relax }{figure.caption.8}{}} +\@writefile{lof}{\contentsline {figure}{\numberline {4.6}{\ignorespaces DigitalOutput block\relax }}{12}{figure.caption.9}} +\newlabel{figure:6}{{4.6}{12}{DigitalOutput block\relax }{figure.caption.9}{}} +\@writefile{lof}{\contentsline {figure}{\numberline {4.7}{\ignorespaces Servo block\relax }}{13}{figure.caption.10}} +\newlabel{figure:7}{{4.7}{13}{Servo block\relax }{figure.caption.10}{}} +\@writefile{toc}{\contentsline {section}{\numberline {4.3}Boards}{13}{section.4.3}} +\@writefile{lof}{\contentsline {figure}{\numberline {4.8}{\ignorespaces Arduino block\relax }}{13}{figure.caption.11}} +\newlabel{figure:8}{{4.8}{13}{Arduino block\relax }{figure.caption.11}{}} +\@writefile{lof}{\contentsline {figure}{\numberline {4.9}{\ignorespaces ArduinoLeonardo block\relax }}{13}{figure.caption.12}} +\newlabel{figure:9}{{4.9}{13}{ArduinoLeonardo block\relax }{figure.caption.12}{}} +\@writefile{lof}{\contentsline {figure}{\numberline {4.10}{\ignorespaces StandardFirmata block\relax }}{14}{figure.caption.13}} +\newlabel{figure:10}{{4.10}{14}{StandardFirmata block\relax }{figure.caption.13}{}} +\@writefile{lof}{\contentsline {figure}{\numberline {4.11}{\ignorespaces CustomFirmata block\relax }}{14}{figure.caption.14}} +\newlabel{figure:11}{{4.11}{14}{CustomFirmata block\relax }{figure.caption.14}{}} +\@writefile{lof}{\contentsline {figure}{\numberline {4.12}{\ignorespaces customBoard block\relax }}{14}{figure.caption.15}} +\newlabel{figure:12}{{4.12}{14}{customBoard block\relax }{figure.caption.15}{}} +\@writefile{toc}{\contentsline {section}{\numberline {4.4}Examples}{14}{section.4.4}} +\@writefile{toc}{\contentsline {section}{\numberline {4.5}ArduinoExamples}{14}{section.4.5}} +\@writefile{toc}{\contentsline {section}{\numberline {4.6}TivaC\_Examples}{15}{section.4.6}} +\@writefile{toc}{\contentsline {section}{\numberline {4.7}Internal}{15}{section.4.7}} +\@writefile{toc}{\contentsline {chapter}{\numberline {5}\textbf {Hardware In Loop Simulation}}{16}{chapter.5}} +\@writefile{lof}{\addvspace {10\p@ }} +\@writefile{lot}{\addvspace {10\p@ }} +\@writefile{toc}{\contentsline {section}{\numberline {5.1}Implementation}{16}{section.5.1}} +\@writefile{toc}{\contentsline {chapter}{\numberline {6}\textbf {PID Controller}}{17}{chapter.6}} +\@writefile{lof}{\addvspace {10\p@ }} +\@writefile{lot}{\addvspace {10\p@ }} +\@writefile{toc}{\contentsline {section}{\numberline {6.1}Implementation}{17}{section.6.1}} +\@writefile{lof}{\contentsline {figure}{\numberline {6.1}{\ignorespaces Firmata to work with PID Controller\relax }}{17}{figure.caption.16}} +\newlabel{figure:24}{{6.1}{17}{Firmata to work with PID Controller\relax }{figure.caption.16}{}} +\@writefile{toc}{\contentsline {section}{\numberline {6.2}Example for PID}{18}{section.6.2}} +\@writefile{lof}{\contentsline {figure}{\numberline {6.2}{\ignorespaces Model for PID Controller with DC Motor\relax }}{18}{figure.caption.17}} +\newlabel{figure:25}{{6.2}{18}{Model for PID Controller with DC Motor\relax }{figure.caption.17}{}} +\@writefile{lof}{\contentsline {figure}{\numberline {6.3}{\ignorespaces Plot for PID Controller with DC Motor\relax }}{18}{figure.caption.18}} +\newlabel{figure:26}{{6.3}{18}{Plot for PID Controller with DC Motor\relax }{figure.caption.18}{}} +\@writefile{toc}{\contentsline {chapter}{\numberline {7}\textbf {Working with Arduino UNO}}{19}{chapter.7}} +\@writefile{lof}{\addvspace {10\p@ }} +\@writefile{lot}{\addvspace {10\p@ }} +\@writefile{lof}{\contentsline {figure}{\numberline {7.1}{\ignorespaces Pin Diagram of Arduino UNO\relax }}{19}{figure.caption.19}} +\newlabel{figure:13}{{7.1}{19}{Pin Diagram of Arduino UNO\relax }{figure.caption.19}{}} +\@writefile{toc}{\contentsline {section}{\numberline {7.1}Connecting and Configuring the Board}{20}{section.7.1}} +\@writefile{toc}{\contentsline {section}{\numberline {7.2}Interfacing with OpenModelica}{20}{section.7.2}} +\@writefile{toc}{\contentsline {section}{\numberline {7.3}Examples for Arduino}{20}{section.7.3}} +\@writefile{toc}{\contentsline {subsection}{\numberline {7.3.1}LED Examples}{21}{subsection.7.3.1}} +\@writefile{lof}{\contentsline {figure}{\numberline {7.2}{\ignorespaces Arduino Led Example\relax }}{21}{figure.caption.20}} +\newlabel{figure:14}{{7.2}{21}{Arduino Led Example\relax }{figure.caption.20}{}} +\@writefile{toc}{\contentsline {subsection}{\numberline {7.3.2}Push Button Examples}{21}{subsection.7.3.2}} +\@writefile{lof}{\contentsline {figure}{\numberline {7.3}{\ignorespaces Arduino Push Button Example\relax }}{22}{figure.caption.21}} +\newlabel{figure:15}{{7.3}{22}{Arduino Push Button Example\relax }{figure.caption.21}{}} +\@writefile{lof}{\contentsline {figure}{\numberline {7.4}{\ignorespaces Print Statement\relax }}{22}{figure.caption.22}} +\newlabel{figure:23}{{7.4}{22}{Print Statement\relax }{figure.caption.22}{}} +\@writefile{toc}{\contentsline {subsection}{\numberline {7.3.3}LDR Examples}{22}{subsection.7.3.3}} +\@writefile{lof}{\contentsline {figure}{\numberline {7.5}{\ignorespaces Arduino LDR Example\relax }}{23}{figure.caption.23}} +\newlabel{figure:16}{{7.5}{23}{Arduino LDR Example\relax }{figure.caption.23}{}} +\@writefile{toc}{\contentsline {subsection}{\numberline {7.3.4}DC Motor Examples}{23}{subsection.7.3.4}} +\@writefile{lof}{\contentsline {figure}{\numberline {7.6}{\ignorespaces Arduino DC Motor Example\relax }}{24}{figure.caption.24}} +\newlabel{figure:17}{{7.6}{24}{Arduino DC Motor Example\relax }{figure.caption.24}{}} +\@writefile{toc}{\contentsline {subsection}{\numberline {7.3.5}Potentiometer Examples}{24}{subsection.7.3.5}} +\@writefile{lof}{\contentsline {figure}{\numberline {7.7}{\ignorespaces Arduino Potentiometer Example\relax }}{25}{figure.caption.25}} +\newlabel{figure:18}{{7.7}{25}{Arduino Potentiometer Example\relax }{figure.caption.25}{}} +\@writefile{toc}{\contentsline {subsection}{\numberline {7.3.6}Thermistor Examples}{25}{subsection.7.3.6}} +\@writefile{lof}{\contentsline {figure}{\numberline {7.8}{\ignorespaces Arduino Thermistor Example\relax }}{26}{figure.caption.26}} +\newlabel{figure:19}{{7.8}{26}{Arduino Thermistor Example\relax }{figure.caption.26}{}} +\@writefile{toc}{\contentsline {subsection}{\numberline {7.3.7}Servo Motor Examples}{26}{subsection.7.3.7}} +\@writefile{lof}{\contentsline {figure}{\numberline {7.9}{\ignorespaces Data Sheet for Servo Motor SG90\relax }}{27}{figure.caption.27}} +\newlabel{figure:27}{{7.9}{27}{Data Sheet for Servo Motor SG90\relax }{figure.caption.27}{}} +\@writefile{lof}{\contentsline {figure}{\numberline {7.10}{\ignorespaces Arduino Servo Motor Example\relax }}{27}{figure.caption.28}} +\newlabel{figure:20}{{7.10}{27}{Arduino Servo Motor Example\relax }{figure.caption.28}{}} +\@writefile{toc}{\contentsline {chapter}{\numberline {8}\textbf {Working with Tiva C Launchpad}}{28}{chapter.8}} +\@writefile{lof}{\addvspace {10\p@ }} +\@writefile{lot}{\addvspace {10\p@ }} +\@writefile{lof}{\contentsline {figure}{\numberline {8.1}{\ignorespaces Pin Diagram of Tiva C Launchpad\relax }}{28}{figure.caption.29}} +\newlabel{figure:21}{{8.1}{28}{Pin Diagram of Tiva C Launchpad\relax }{figure.caption.29}{}} +\@writefile{toc}{\contentsline {section}{\numberline {8.1}Connecting and Configuring the Board}{28}{section.8.1}} +\@writefile{toc}{\contentsline {section}{\numberline {8.2}Interfacing with OpenModelica}{29}{section.8.2}} +\@writefile{toc}{\contentsline {section}{\numberline {8.3}Examples for Tiva C}{29}{section.8.3}} +\@writefile{lof}{\contentsline {figure}{\numberline {8.2}{\ignorespaces Tiva C Led Example\relax }}{30}{figure.caption.30}} +\newlabel{figure:22}{{8.2}{30}{Tiva C Led Example\relax }{figure.caption.30}{}} +\@writefile{toc}{\contentsline {chapter}{\numberline {9}\textbf {Conclusion}}{31}{chapter.9}} +\@writefile{lof}{\addvspace {10\p@ }} +\@writefile{lot}{\addvspace {10\p@ }} diff --git a/Report/Final.lof b/Report/Final.lof new file mode 100644 index 0000000..751e94b --- /dev/null +++ b/Report/Final.lof @@ -0,0 +1,36 @@ +\addvspace {10\p@ } +\addvspace {10\p@ } +\addvspace {10\p@ } +\addvspace {10\p@ } +\contentsline {figure}{\numberline {4.1}{\ignorespaces Structure of OpenModelicaEmbedded package\relax }}{9}{figure.caption.4} +\contentsline {figure}{\numberline {4.2}{\ignorespaces SymchronizeRealTime block\relax }}{10}{figure.caption.5} +\contentsline {figure}{\numberline {4.3}{\ignorespaces AnalogInput block\relax }}{11}{figure.caption.6} +\contentsline {figure}{\numberline {4.4}{\ignorespaces AnalogOutput block\relax }}{11}{figure.caption.7} +\contentsline {figure}{\numberline {4.5}{\ignorespaces DigitalInput block\relax }}{12}{figure.caption.8} +\contentsline {figure}{\numberline {4.6}{\ignorespaces DigitalOutput block\relax }}{12}{figure.caption.9} +\contentsline {figure}{\numberline {4.7}{\ignorespaces Servo block\relax }}{13}{figure.caption.10} +\contentsline {figure}{\numberline {4.8}{\ignorespaces Arduino block\relax }}{13}{figure.caption.11} +\contentsline {figure}{\numberline {4.9}{\ignorespaces ArduinoLeonardo block\relax }}{13}{figure.caption.12} +\contentsline {figure}{\numberline {4.10}{\ignorespaces StandardFirmata block\relax }}{14}{figure.caption.13} +\contentsline {figure}{\numberline {4.11}{\ignorespaces CustomFirmata block\relax }}{14}{figure.caption.14} +\contentsline {figure}{\numberline {4.12}{\ignorespaces customBoard block\relax }}{14}{figure.caption.15} +\addvspace {10\p@ } +\addvspace {10\p@ } +\contentsline {figure}{\numberline {6.1}{\ignorespaces Firmata to work with PID Controller\relax }}{17}{figure.caption.16} +\contentsline {figure}{\numberline {6.2}{\ignorespaces Model for PID Controller with DC Motor\relax }}{18}{figure.caption.17} +\contentsline {figure}{\numberline {6.3}{\ignorespaces Plot for PID Controller with DC Motor\relax }}{18}{figure.caption.18} +\addvspace {10\p@ } +\contentsline {figure}{\numberline {7.1}{\ignorespaces Pin Diagram of Arduino UNO\relax }}{19}{figure.caption.19} +\contentsline {figure}{\numberline {7.2}{\ignorespaces Arduino Led Example\relax }}{21}{figure.caption.20} +\contentsline {figure}{\numberline {7.3}{\ignorespaces Arduino Push Button Example\relax }}{22}{figure.caption.21} +\contentsline {figure}{\numberline {7.4}{\ignorespaces Print Statement\relax }}{22}{figure.caption.22} +\contentsline {figure}{\numberline {7.5}{\ignorespaces Arduino LDR Example\relax }}{23}{figure.caption.23} +\contentsline {figure}{\numberline {7.6}{\ignorespaces Arduino DC Motor Example\relax }}{24}{figure.caption.24} +\contentsline {figure}{\numberline {7.7}{\ignorespaces Arduino Potentiometer Example\relax }}{25}{figure.caption.25} +\contentsline {figure}{\numberline {7.8}{\ignorespaces Arduino Thermistor Example\relax }}{26}{figure.caption.26} +\contentsline {figure}{\numberline {7.9}{\ignorespaces Data Sheet for Servo Motor SG90\relax }}{27}{figure.caption.27} +\contentsline {figure}{\numberline {7.10}{\ignorespaces Arduino Servo Motor Example\relax }}{27}{figure.caption.28} +\addvspace {10\p@ } +\contentsline {figure}{\numberline {8.1}{\ignorespaces Pin Diagram of Tiva C Launchpad\relax }}{28}{figure.caption.29} +\contentsline {figure}{\numberline {8.2}{\ignorespaces Tiva C Led Example\relax }}{30}{figure.caption.30} +\addvspace {10\p@ } diff --git a/Report/Final.log b/Report/Final.log new file mode 100644 index 0000000..a01d45b --- /dev/null +++ b/Report/Final.log @@ -0,0 +1,1254 @@ +This is pdfTeX, Version 3.14159265-2.6-1.40.16 (TeX Live 2015/Debian) (preloaded format=pdflatex 2019.1.21) 21 AUG 2019 17:05 +entering extended mode + restricted \write18 enabled. + %&-line parsing enabled. +**Final.tex +(./Final.tex +LaTeX2e <2016/02/01> +Babel <3.9q> and hyphenation patterns for 81 language(s) loaded. +(/usr/share/texlive/texmf-dist/tex/latex/base/report.cls +Document Class: report 2014/09/29 v1.4h Standard LaTeX document class +(/usr/share/texlive/texmf-dist/tex/latex/base/size12.clo +File: size12.clo 2014/09/29 v1.4h Standard LaTeX file (size option) +) +\c@part=\count79 +\c@chapter=\count80 +\c@section=\count81 +\c@subsection=\count82 +\c@subsubsection=\count83 +\c@paragraph=\count84 +\c@subparagraph=\count85 +\c@figure=\count86 +\c@table=\count87 +\abovecaptionskip=\skip41 +\belowcaptionskip=\skip42 +\bibindent=\dimen102 +) +(/usr/share/texlive/texmf-dist/tex/latex/geometry/geometry.sty +Package: geometry 2010/09/12 v5.6 Page Geometry + +(/usr/share/texlive/texmf-dist/tex/latex/graphics/keyval.sty +Package: keyval 2014/10/28 v1.15 key=value parser (DPC) +\KV@toks@=\toks14 +) +(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/ifpdf.sty +Package: ifpdf 2011/01/30 v2.3 Provides the ifpdf switch (HO) +Package ifpdf Info: pdfTeX in PDF mode is detected. +) +(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/ifvtex.sty +Package: ifvtex 2010/03/01 v1.5 Detect VTeX and its facilities (HO) +Package ifvtex Info: VTeX not detected. +) +(/usr/share/texlive/texmf-dist/tex/generic/ifxetex/ifxetex.sty +Package: ifxetex 2010/09/12 v0.6 Provides ifxetex conditional +) +\Gm@cnth=\count88 +\Gm@cntv=\count89 +\c@Gm@tempcnt=\count90 +\Gm@bindingoffset=\dimen103 +\Gm@wd@mp=\dimen104 +\Gm@odd@mp=\dimen105 +\Gm@even@mp=\dimen106 +\Gm@layoutwidth=\dimen107 +\Gm@layoutheight=\dimen108 +\Gm@layouthoffset=\dimen109 +\Gm@layoutvoffset=\dimen110 +\Gm@dimlist=\toks15 +) +(/usr/share/texlive/texmf-dist/tex/latex/graphics/graphicx.sty +Package: graphicx 2014/10/28 v1.0g Enhanced LaTeX Graphics (DPC,SPQR) + +(/usr/share/texlive/texmf-dist/tex/latex/graphics/graphics.sty +Package: graphics 2016/01/03 v1.0q Standard LaTeX Graphics (DPC,SPQR) + +(/usr/share/texlive/texmf-dist/tex/latex/graphics/trig.sty +Package: trig 2016/01/03 v1.10 sin cos tan (DPC) +) +(/usr/share/texlive/texmf-dist/tex/latex/latexconfig/graphics.cfg +File: graphics.cfg 2010/04/23 v1.9 graphics configuration of TeX Live +) +Package graphics Info: Driver file: pdftex.def on input line 95. + +(/usr/share/texlive/texmf-dist/tex/latex/pdftex-def/pdftex.def +File: pdftex.def 2011/05/27 v0.06d Graphics/color for pdfTeX + +(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/infwarerr.sty +Package: infwarerr 2010/04/08 v1.3 Providing info/warning/error messages (HO) +) +(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/ltxcmds.sty +Package: ltxcmds 2011/11/09 v1.22 LaTeX kernel commands for general use (HO) +) +\Gread@gobject=\count91 +)) +\Gin@req@height=\dimen111 +\Gin@req@width=\dimen112 +) +(/usr/share/texlive/texmf-dist/tex/latex/caption/caption.sty +Package: caption 2016/02/21 v3.3-144 Customizing captions (AR) + +(/usr/share/texlive/texmf-dist/tex/latex/caption/caption3.sty +Package: caption3 2016/02/04 v1.7-139 caption3 kernel (AR) +Package caption3 Info: TeX engine: e-TeX on input line 67. +\captionmargin=\dimen113 +\captionmargin@=\dimen114 +\captionwidth=\dimen115 +\caption@tempdima=\dimen116 +\caption@indent=\dimen117 +\caption@parindent=\dimen118 +\caption@hangindent=\dimen119 +) +\c@ContinuedFloat=\count92 +) +(/usr/share/texlive/texmf-dist/tex/latex/tools/array.sty +Package: array 2014/10/28 v2.4c Tabular extension package (FMi) +\col@sep=\dimen120 +\extrarowheight=\dimen121 +\NC@list=\toks16 +\extratabsurround=\skip43 +\backup@length=\skip44 +) +(/usr/share/texlive/texmf-dist/tex/latex/listings/listings.sty +\lst@mode=\count93 +\lst@gtempboxa=\box26 +\lst@token=\toks17 +\lst@length=\count94 +\lst@currlwidth=\dimen122 +\lst@column=\count95 +\lst@pos=\count96 +\lst@lostspace=\dimen123 +\lst@width=\dimen124 +\lst@newlines=\count97 +\lst@lineno=\count98 +\lst@maxwidth=\dimen125 + +(/usr/share/texlive/texmf-dist/tex/latex/listings/lstmisc.sty +File: lstmisc.sty 2015/06/04 1.6 (Carsten Heinz) +\c@lstnumber=\count99 +\lst@skipnumbers=\count100 +\lst@framebox=\box27 +) +(/usr/share/texlive/texmf-dist/tex/latex/listings/listings.cfg +File: listings.cfg 2015/06/04 1.6 listings configuration +)) +Package: listings 2015/06/04 1.6 (Carsten Heinz) + +(/usr/share/texlive/texmf-dist/tex/latex/hyperref/hyperref.sty +Package: hyperref 2012/11/06 v6.83m Hypertext links for LaTeX + +(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/hobsub-hyperref.sty +Package: hobsub-hyperref 2012/05/28 v1.13 Bundle oberdiek, subset hyperref (HO) + + +(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/hobsub-generic.sty +Package: hobsub-generic 2012/05/28 v1.13 Bundle oberdiek, subset generic (HO) +Package: hobsub 2012/05/28 v1.13 Construct package bundles (HO) +Package hobsub Info: Skipping package `infwarerr' (already loaded). +Package hobsub Info: Skipping package `ltxcmds' (already loaded). +Package: ifluatex 2010/03/01 v1.3 Provides the ifluatex switch (HO) +Package ifluatex Info: LuaTeX not detected. +Package hobsub Info: Skipping package `ifvtex' (already loaded). +Package: intcalc 2007/09/27 v1.1 Expandable calculations with integers (HO) +Package hobsub Info: Skipping package `ifpdf' (already loaded). +Package: etexcmds 2011/02/16 v1.5 Avoid name clashes with e-TeX commands (HO) +Package etexcmds Info: Could not find \expanded. +(etexcmds) That can mean that you are not using pdfTeX 1.50 or +(etexcmds) that some package has redefined \expanded. +(etexcmds) In the latter case, load this package earlier. +Package: kvsetkeys 2012/04/25 v1.16 Key value parser (HO) +Package: kvdefinekeys 2011/04/07 v1.3 Define keys (HO) +Package: pdftexcmds 2011/11/29 v0.20 Utility functions of pdfTeX for LuaTeX (HO +) +Package pdftexcmds Info: LuaTeX not detected. +Package pdftexcmds Info: \pdf@primitive is available. +Package pdftexcmds Info: \pdf@ifprimitive is available. +Package pdftexcmds Info: \pdfdraftmode found. +Package: pdfescape 2011/11/25 v1.13 Implements pdfTeX's escape features (HO) +Package: bigintcalc 2012/04/08 v1.3 Expandable calculations on big integers (HO +) +Package: bitset 2011/01/30 v1.1 Handle bit-vector datatype (HO) +Package: uniquecounter 2011/01/30 v1.2 Provide unlimited unique counter (HO) +) +Package hobsub Info: Skipping package `hobsub' (already loaded). +Package: letltxmacro 2010/09/02 v1.4 Let assignment for LaTeX macros (HO) +Package: hopatch 2012/05/28 v1.2 Wrapper for package hooks (HO) +Package: xcolor-patch 2011/01/30 xcolor patch +Package: atveryend 2011/06/30 v1.8 Hooks at the very end of document (HO) +Package atveryend Info: \enddocument detected (standard20110627). +Package: atbegshi 2011/10/05 v1.16 At begin shipout hook (HO) +Package: refcount 2011/10/16 v3.4 Data extraction from label references (HO) +Package: hycolor 2011/01/30 v1.7 Color options for hyperref/bookmark (HO) +) +(/usr/share/texlive/texmf-dist/tex/latex/oberdiek/auxhook.sty +Package: auxhook 2011/03/04 v1.3 Hooks for auxiliary files (HO) +) +(/usr/share/texlive/texmf-dist/tex/latex/oberdiek/kvoptions.sty +Package: kvoptions 2011/06/30 v3.11 Key value format for package options (HO) +) +\@linkdim=\dimen126 +\Hy@linkcounter=\count101 +\Hy@pagecounter=\count102 + +(/usr/share/texlive/texmf-dist/tex/latex/hyperref/pd1enc.def +File: pd1enc.def 2012/11/06 v6.83m Hyperref: PDFDocEncoding definition (HO) +) +\Hy@SavedSpaceFactor=\count103 + +(/usr/share/texlive/texmf-dist/tex/latex/latexconfig/hyperref.cfg +File: hyperref.cfg 2002/06/06 v1.2 hyperref configuration of TeXLive +) +Package hyperref Info: Hyper figures OFF on input line 4443. +Package hyperref Info: Link nesting OFF on input line 4448. +Package hyperref Info: Hyper index ON on input line 4451. +Package hyperref Info: Plain pages OFF on input line 4458. +Package hyperref Info: Backreferencing OFF on input line 4463. +Package hyperref Info: Implicit mode ON; LaTeX internals redefined. +Package hyperref Info: Bookmarks ON on input line 4688. +\c@Hy@tempcnt=\count104 + +(/usr/share/texlive/texmf-dist/tex/latex/url/url.sty +\Urlmuskip=\muskip10 +Package: url 2013/09/16 ver 3.4 Verb mode for urls, etc. +) +LaTeX Info: Redefining \url on input line 5041. +\XeTeXLinkMargin=\dimen127 +\Fld@menulength=\count105 +\Field@Width=\dimen128 +\Fld@charsize=\dimen129 +Package hyperref Info: Hyper figures OFF on input line 6295. +Package hyperref Info: Link nesting OFF on input line 6300. +Package hyperref Info: Hyper index ON on input line 6303. +Package hyperref Info: backreferencing OFF on input line 6310. +Package hyperref Info: Link coloring OFF on input line 6315. +Package hyperref Info: Link coloring with OCG OFF on input line 6320. +Package hyperref Info: PDF/A mode OFF on input line 6325. +LaTeX Info: Redefining \ref on input line 6365. +LaTeX Info: Redefining \pageref on input line 6369. +\Hy@abspage=\count106 +\c@Item=\count107 +\c@Hfootnote=\count108 +) + +Package hyperref Message: Driver (autodetected): hpdftex. + +(/usr/share/texlive/texmf-dist/tex/latex/hyperref/hpdftex.def +File: hpdftex.def 2012/11/06 v6.83m Hyperref driver for pdfTeX +\Fld@listcount=\count109 +\c@bookmark@seq@number=\count110 + +(/usr/share/texlive/texmf-dist/tex/latex/oberdiek/rerunfilecheck.sty +Package: rerunfilecheck 2011/04/15 v1.7 Rerun checks for auxiliary files (HO) +Package uniquecounter Info: New unique counter `rerunfilecheck' on input line 2 +82. +) +\Hy@SectionHShift=\skip45 +) +(/usr/share/texlive/texmf-dist/tex/latex/float/float.sty +Package: float 2001/11/08 v1.3d Float enhancements (AL) +\c@float@type=\count111 +\float@exts=\toks18 +\float@box=\box28 +\@float@everytoks=\toks19 +\@floatcapt=\box29 +) +(/usr/share/texlive/texmf-dist/tex/latex/base/textcomp.sty +Package: textcomp 2005/09/27 v1.99g Standard LaTeX package +Package textcomp Info: Sub-encoding information: +(textcomp) 5 = only ISO-Adobe without \textcurrency +(textcomp) 4 = 5 + \texteuro +(textcomp) 3 = 4 + \textohm +(textcomp) 2 = 3 + \textestimated + \textcurrency +(textcomp) 1 = TS1 - \textcircled - \t +(textcomp) 0 = TS1 (full) +(textcomp) Font families with sub-encoding setting implement +(textcomp) only a restricted character set as indicated. +(textcomp) Family '?' is the default used for unknown fonts. +(textcomp) See the documentation for details. +Package textcomp Info: Setting ? sub-encoding to TS1/1 on input line 79. + +(/usr/share/texlive/texmf-dist/tex/latex/base/ts1enc.def +File: ts1enc.def 2001/06/05 v3.0e (jk/car/fm) Standard LaTeX file +) +LaTeX Info: Redefining \oldstylenums on input line 334. +Package textcomp Info: Setting cmr sub-encoding to TS1/0 on input line 349. +Package textcomp Info: Setting cmss sub-encoding to TS1/0 on input line 350. +Package textcomp Info: Setting cmtt sub-encoding to TS1/0 on input line 351. +Package textcomp Info: Setting cmvtt sub-encoding to TS1/0 on input line 352. +Package textcomp Info: Setting cmbr sub-encoding to TS1/0 on input line 353. +Package textcomp Info: Setting cmtl sub-encoding to TS1/0 on input line 354. +Package textcomp Info: Setting ccr sub-encoding to TS1/0 on input line 355. +Package textcomp Info: Setting ptm sub-encoding to TS1/4 on input line 356. +Package textcomp Info: Setting pcr sub-encoding to TS1/4 on input line 357. +Package textcomp Info: Setting phv sub-encoding to TS1/4 on input line 358. +Package textcomp Info: Setting ppl sub-encoding to TS1/3 on input line 359. +Package textcomp Info: Setting pag sub-encoding to TS1/4 on input line 360. +Package textcomp Info: Setting pbk sub-encoding to TS1/4 on input line 361. +Package textcomp Info: Setting pnc sub-encoding to TS1/4 on input line 362. +Package textcomp Info: Setting pzc sub-encoding to TS1/4 on input line 363. +Package textcomp Info: Setting bch sub-encoding to TS1/4 on input line 364. +Package textcomp Info: Setting put sub-encoding to TS1/5 on input line 365. +Package textcomp Info: Setting uag sub-encoding to TS1/5 on input line 366. +Package textcomp Info: Setting ugq sub-encoding to TS1/5 on input line 367. +Package textcomp Info: Setting ul8 sub-encoding to TS1/4 on input line 368. +Package textcomp Info: Setting ul9 sub-encoding to TS1/4 on input line 369. +Package textcomp Info: Setting augie sub-encoding to TS1/5 on input line 370. +Package textcomp Info: Setting dayrom sub-encoding to TS1/3 on input line 371. +Package textcomp Info: Setting dayroms sub-encoding to TS1/3 on input line 372. + +Package textcomp Info: Setting pxr sub-encoding to TS1/0 on input line 373. +Package textcomp Info: Setting pxss sub-encoding to TS1/0 on input line 374. +Package textcomp Info: Setting pxtt sub-encoding to TS1/0 on input line 375. +Package textcomp Info: Setting txr sub-encoding to TS1/0 on input line 376. +Package textcomp Info: Setting txss sub-encoding to TS1/0 on input line 377. +Package textcomp Info: Setting txtt sub-encoding to TS1/0 on input line 378. +Package textcomp Info: Setting lmr sub-encoding to TS1/0 on input line 379. +Package textcomp Info: Setting lmdh sub-encoding to TS1/0 on input line 380. +Package textcomp Info: Setting lmss sub-encoding to TS1/0 on input line 381. +Package textcomp Info: Setting lmssq sub-encoding to TS1/0 on input line 382. +Package textcomp Info: Setting lmvtt sub-encoding to TS1/0 on input line 383. +Package textcomp Info: Setting lmtt sub-encoding to TS1/0 on input line 384. +Package textcomp Info: Setting qhv sub-encoding to TS1/0 on input line 385. +Package textcomp Info: Setting qag sub-encoding to TS1/0 on input line 386. +Package textcomp Info: Setting qbk sub-encoding to TS1/0 on input line 387. +Package textcomp Info: Setting qcr sub-encoding to TS1/0 on input line 388. +Package textcomp Info: Setting qcs sub-encoding to TS1/0 on input line 389. +Package textcomp Info: Setting qpl sub-encoding to TS1/0 on input line 390. +Package textcomp Info: Setting qtm sub-encoding to TS1/0 on input line 391. +Package textcomp Info: Setting qzc sub-encoding to TS1/0 on input line 392. +Package textcomp Info: Setting qhvc sub-encoding to TS1/0 on input line 393. +Package textcomp Info: Setting futs sub-encoding to TS1/4 on input line 394. +Package textcomp Info: Setting futx sub-encoding to TS1/4 on input line 395. +Package textcomp Info: Setting futj sub-encoding to TS1/4 on input line 396. +Package textcomp Info: Setting hlh sub-encoding to TS1/3 on input line 397. +Package textcomp Info: Setting hls sub-encoding to TS1/3 on input line 398. +Package textcomp Info: Setting hlst sub-encoding to TS1/3 on input line 399. +Package textcomp Info: Setting hlct sub-encoding to TS1/5 on input line 400. +Package textcomp Info: Setting hlx sub-encoding to TS1/5 on input line 401. +Package textcomp Info: Setting hlce sub-encoding to TS1/5 on input line 402. +Package textcomp Info: Setting hlcn sub-encoding to TS1/5 on input line 403. +Package textcomp Info: Setting hlcw sub-encoding to TS1/5 on input line 404. +Package textcomp Info: Setting hlcf sub-encoding to TS1/5 on input line 405. +Package textcomp Info: Setting pplx sub-encoding to TS1/3 on input line 406. +Package textcomp Info: Setting pplj sub-encoding to TS1/3 on input line 407. +Package textcomp Info: Setting ptmx sub-encoding to TS1/4 on input line 408. +Package textcomp Info: Setting ptmj sub-encoding to TS1/4 on input line 409. +) +(/usr/share/texlive/texmf-dist/tex/latex/caption/subcaption.sty +Package: subcaption 2016/02/20 v1.1-142 Sub-captions (AR) +\c@subfigure=\count112 +\c@subtable=\count113 +) +Package hyperref Info: Option `colorlinks' set `true' on input line 18. + (./Final.aux) +\openout1 = `Final.aux'. + +LaTeX Font Info: Checking defaults for OML/cmm/m/it on input line 19. +LaTeX Font Info: ... okay on input line 19. +LaTeX Font Info: Checking defaults for T1/cmr/m/n on input line 19. +LaTeX Font Info: ... okay on input line 19. +LaTeX Font Info: Checking defaults for OT1/cmr/m/n on input line 19. +LaTeX Font Info: ... okay on input line 19. +LaTeX Font Info: Checking defaults for OMS/cmsy/m/n on input line 19. +LaTeX Font Info: ... okay on input line 19. +LaTeX Font Info: Checking defaults for OMX/cmex/m/n on input line 19. +LaTeX Font Info: ... okay on input line 19. +LaTeX Font Info: Checking defaults for U/cmr/m/n on input line 19. +LaTeX Font Info: ... okay on input line 19. +LaTeX Font Info: Checking defaults for PD1/pdf/m/n on input line 19. +LaTeX Font Info: ... okay on input line 19. +LaTeX Font Info: Checking defaults for TS1/cmr/m/n on input line 19. +LaTeX Font Info: Try loading font information for TS1+cmr on input line 19. + +(/usr/share/texlive/texmf-dist/tex/latex/base/ts1cmr.fd +File: ts1cmr.fd 2014/09/29 v2.5h Standard LaTeX font definitions +) +LaTeX Font Info: ... okay on input line 19. + +*geometry* driver: auto-detecting +*geometry* detected driver: pdftex +*geometry* verbose mode - [ preamble ] result: +* driver: pdftex +* paper: a4paper +* layout: <same size as paper> +* layoutoffset:(h,v)=(0.0pt,0.0pt) +* modes: +* h-part:(L,W,R)=(85.35826pt, 426.79135pt, 85.35826pt) +* v-part:(T,H,B)=(85.35826pt, 674.33032pt, 85.35826pt) +* \paperwidth=597.50787pt +* \paperheight=845.04684pt +* \textwidth=426.79135pt +* \textheight=674.33032pt +* \oddsidemargin=13.08827pt +* \evensidemargin=13.08827pt +* \topmargin=-23.91173pt +* \headheight=12.0pt +* \headsep=25.0pt +* \topskip=12.0pt +* \footskip=30.0pt +* \marginparwidth=35.0pt +* \marginparsep=10.0pt +* \columnsep=10.0pt +* \skip\footins=10.8pt plus 4.0pt minus 2.0pt +* \hoffset=0.0pt +* \voffset=0.0pt +* \mag=1000 +* \@twocolumnfalse +* \@twosidefalse +* \@mparswitchfalse +* \@reversemarginfalse +* (1in=72.27pt=25.4mm, 1cm=28.453pt) + +(/usr/share/texlive/texmf-dist/tex/context/base/supp-pdf.mkii +[Loading MPS to PDF converter (version 2006.09.02).] +\scratchcounter=\count114 +\scratchdimen=\dimen130 +\scratchbox=\box30 +\nofMPsegments=\count115 +\nofMParguments=\count116 +\everyMPshowfont=\toks20 +\MPscratchCnt=\count117 +\MPscratchDim=\dimen131 +\MPnumerator=\count118 +\makeMPintoPDFobject=\count119 +\everyMPtoPDFconversion=\toks21 +) (/usr/share/texlive/texmf-dist/tex/latex/oberdiek/epstopdf-base.sty +Package: epstopdf-base 2010/02/09 v2.5 Base part for package epstopdf + +(/usr/share/texlive/texmf-dist/tex/latex/oberdiek/grfext.sty +Package: grfext 2010/08/19 v1.1 Manage graphics extensions (HO) +) +Package grfext Info: Graphics extension search list: +(grfext) [.png,.pdf,.jpg,.mps,.jpeg,.jbig2,.jb2,.PNG,.PDF,.JPG,.JPE +G,.JBIG2,.JB2,.eps] +(grfext) \AppendGraphicsExtensions on input line 452. + +(/usr/share/texlive/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg +File: epstopdf-sys.cfg 2010/07/13 v1.3 Configuration of (r)epstopdf for TeX Liv +e +)) +Package caption Info: Begin \AtBeginDocument code. +Package caption Info: float package is loaded. +Package caption Info: hyperref package is loaded. +Package caption Info: listings package is loaded. +Package caption Info: End \AtBeginDocument code. +\c@lstlisting=\count120 +\AtBeginShipoutBox=\box31 + +(/usr/share/texlive/texmf-dist/tex/latex/graphics/color.sty +Package: color 2016/01/03 v1.1b Standard LaTeX Color (DPC) + +(/usr/share/texlive/texmf-dist/tex/latex/latexconfig/color.cfg +File: color.cfg 2007/01/18 v1.5 color configuration of teTeX/TeXLive +) +Package color Info: Driver file: pdftex.def on input line 143. +) +Package hyperref Info: Link coloring ON on input line 19. + +(/usr/share/texlive/texmf-dist/tex/latex/hyperref/nameref.sty +Package: nameref 2012/10/27 v2.43 Cross-referencing by name of section + +(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/gettitlestring.sty +Package: gettitlestring 2010/12/03 v1.4 Cleanup title references (HO) +) +\c@section@level=\count121 +) +LaTeX Info: Redefining \ref on input line 19. +LaTeX Info: Redefining \pageref on input line 19. +LaTeX Info: Redefining \nameref on input line 19. + +(./Final.out) (./Final.out) +\@outlinefile=\write3 +\openout3 = `Final.out'. + + <iit.png, id=164, 185.94469pt x 189.70876pt> +File: iit.png Graphic file (type png) + +<use iit.png> +Package pdftex.def Info: iit.png used on input line 23. +(pdftex.def) Requested size: 128.0387pt x 130.63286pt. + <fossee-logo.png, id=166, 145.0234pt x 55.5923pt> +File: fossee-logo.png Graphic file (type png) + +<use fossee-logo.png> +Package pdftex.def Info: fossee-logo.png used on input line 25. +(pdftex.def) Requested size: 170.71393pt x 65.44308pt. +LaTeX Font Info: External font `cmex10' loaded for size +(Font) <14.4> on input line 37. +LaTeX Font Info: External font `cmex10' loaded for size +(Font) <7> on input line 37. + + +LaTeX Warning: No \author given. + +[1 + +{/var/lib/texmf/fonts/map/pdftex/updmap/pdftex.map} <./iit.png> <./fossee-logo. +png>] (./Final.toc +LaTeX Font Info: External font `cmex10' loaded for size +(Font) <12> on input line 3. +LaTeX Font Info: External font `cmex10' loaded for size +(Font) <8> on input line 3. +LaTeX Font Info: External font `cmex10' loaded for size +(Font) <6> on input line 3. +pdfTeX warning (ext4): destination with the same identifier (name{page.1}) has +been already used, duplicate ignored +<to be read again> + \relax +l.33 ...entiometer Examples}{25}{subsection.7.3.5} + [1 + +]) +\tf@toc=\write4 +\openout4 = `Final.toc'. + + [2] (./Final.lof) +\tf@lof=\write5 +\openout5 = `Final.lof'. + + +[3 + +] +Chapter 1. +[4 + +] +Chapter 2. +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +[5 + +] +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! + +Underfull \hbox (badness 10000) in paragraph at lines 70--71 + + [] + +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! + +Underfull \hbox (badness 10000) in paragraph at lines 72--75 + + [] + + +Underfull \hbox (badness 10000) in paragraph at lines 72--75 + + [] + +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! + +Underfull \hbox (badness 10000) in paragraph at lines 76--77 + + [] + + +Overfull \hbox (17.94862pt too wide) in paragraph at lines 79--83 +\OT1/cmr/m/n/12 Open pid-mata3 sketch: File \TS1/cmr/m/n/12 ^^Y\OT1/cmr/m/n/12 +Open \TS1/cmr/m/n/12 ^^Y\OT1/cmr/m/n/12 OpenModelicaEmbedded \TS1/cmr/m/n/12 ^^ +Y\OT1/cmr/m/n/12 Firmware \TS1/cmr/m/n/12 ^^Y\OT1/cmr/m/n/12 Arduino + [] + + +Underfull \hbox (badness 10000) in paragraph at lines 79--83 + + [] + +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +[6] +Underfull \hbox (badness 10000) in paragraph at lines 90--93 + + [] + + +Underfull \hbox (badness 10000) in paragraph at lines 94--98 + + [] + +[7] +Chapter 3. + +Underfull \hbox (badness 10000) in paragraph at lines 101--108 + + [] + + +Overfull \hbox (18.41837pt too wide) in paragraph at lines 101--108 +\OT1/cmr/m/n/12 fol-low-ing the in-struc-tions on [][]$\OT1/cmtt/m/n/12 https : + / / openmodelica . org / download / download-[]linux$[][]\OT1/cmr/m/n/12 . + [] + + +Underfull \hbox (badness 10000) in paragraph at lines 101--108 + + [] + + +Overfull \hbox (38.20384pt too wide) in paragraph at lines 101--108 +\OT1/cmr/m/n/12 The setup for Open-Mod-el-ica on Win-dows can be down-loaded fr +om [][]$\OT1/cmtt/m/n/12 https : / / openmodelica . + [] + + +Overfull \hbox (3.69864pt too wide) in paragraph at lines 113--116 +\OT1/cmr/m/n/12 Energia is a Arduino-like cod-ing en-vi-ron-ment de-signed for +Texas In-stru-ments Launch- + [] + + +Overfull \hbox (10.69019pt too wide) in paragraph at lines 113--116 +\OT1/cmr/m/n/12 pads. The setup for En-er-gia can be down-loaded from [][]$\OT1 +/cmtt/m/n/12 http : / / energia . nu / download/$[][]\OT1/cmr/m/n/12 . + [] + + +Overfull \hbox (22.49632pt too wide) in paragraph at lines 113--116 +\OT1/cmr/m/n/12 For Linux: [][]$\OT1/cmtt/m/n/12 http : / / energia . nu / guid +e / guide _ linux/$[][] \OT1/cmr/m/n/12 For Win-dows: [][]$\OT1/cmtt/m/n/12 htt +p : / / energia . + [] + +[8 + +] +Chapter 4. + +Underfull \hbox (badness 10000) in paragraph at lines 120--126 + + [] + +<package_str.PNG, id=335, 129.98563pt x 100.375pt> +File: package_str.PNG Graphic file (type png) + <use package_str.PNG> +Package pdftex.def Info: package_str.PNG used on input line 129. +(pdftex.def) Requested size: 213.39568pt x 164.78452pt. + +[9 + + <./package_str.PNG>] <realtime.PNG, id=341, 311.1625pt x 308.15125pt> +File: realtime.PNG Graphic file (type png) + +<use realtime.PNG> +Package pdftex.def Info: realtime.PNG used on input line 139. +(pdftex.def) Requested size: 128.0387pt x 126.79892pt. + <realtimepara.PNG, id=342, 357.83687pt x 307.1475pt> +File: realtimepara.PNG Graphic file (type png) + +<use realtimepara.PNG> +Package pdftex.def Info: realtimepara.PNG used on input line 140. +(pdftex.def) Requested size: 277.41176pt x 238.13058pt. + +Underfull \hbox (badness 10000) in paragraph at lines 146--147 + + [] + +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +<pin11.PNG, id=343, 371.3875pt x 312.66812pt> +File: pin11.PNG Graphic file (type png) + <use pin11.PNG> +Package pdftex.def Info: pin11.PNG used on input line 152. +(pdftex.def) Requested size: 170.71393pt x 143.72412pt. + +<pin12.PNG, id=344, 350.81062pt x 362.35374pt> +File: pin12.PNG Graphic file (type png) + <use pin12.PNG> +Package pdftex.def Info: pin12.PNG used on input line 153. +(pdftex.def) Requested size: 234.73654pt x 242.46611pt. + [10 <./realtime.PNG> <./realtimepara.PNG>] +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! + <pin21.PNG, id=351, 366.36874pt x 311.1625pt> +File: pin21.PNG Graphic file (type png) + +<use pin21.PNG> +Package pdftex.def Info: pin21.PNG used on input line 160. +(pdftex.def) Requested size: 170.71393pt x 144.99294pt. + <pin22.PNG, id=352, 345.79187pt x 306.14375pt> +File: pin22.PNG Graphic file (type png) + <use pin22.PNG> +Package pdftex.def Info: pin22.PNG used on input line 161. +(pdftex.def) Requested size: 234.73654pt x 207.82463pt. +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! + +<pin31.PNG, id=353, 370.38374pt x 309.155pt> +File: pin31.PNG Graphic file (type png) + <use pin31.PNG> +Package pdftex.def Info: pin31.PNG used on input line 168. +(pdftex.def) Requested size: 170.71393pt x 142.49133pt. + +<pin32.PNG, id=354, 275.0275pt x 292.09125pt> +File: pin32.PNG Graphic file (type png) + <use pin32.PNG> +Package pdftex.def Info: pin32.PNG used on input line 169. +(pdftex.def) Requested size: 234.73654pt x 249.30827pt. + [11 <./pin11.PNG> <./pin12.PNG> <./pin21.PNG> <./pin22.PNG>] +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! + +<pin41.PNG, id=363, 358.33875pt x 309.155pt> +File: pin41.PNG Graphic file (type png) + <use pin41.PNG> +Package pdftex.def Info: pin41.PNG used on input line 176. +(pdftex.def) Requested size: 170.71393pt x 147.28413pt. + +<pin42.PNG, id=364, 245.91875pt x 251.94125pt> +File: pin42.PNG Graphic file (type png) + <use pin42.PNG> +Package pdftex.def Info: pin42.PNG used on input line 177. +(pdftex.def) Requested size: 234.73654pt x 240.49611pt. + +<pin51.PNG, id=365, 359.3425pt x 311.1625pt> +File: pin51.PNG Graphic file (type png) + <use pin51.PNG> +Package pdftex.def Info: pin51.PNG used on input line 184. +(pdftex.def) Requested size: 170.71393pt x 147.82745pt. + +<pin52.PNG, id=366, 653.94313pt x 338.76563pt> +File: pin52.PNG Graphic file (type png) + <use pin52.PNG> +Package pdftex.def Info: pin52.PNG used on input line 185. +(pdftex.def) Requested size: 234.73654pt x 121.59885pt. + [12 <./pin31.PNG> <./pin32.PNG> <./pin41.PNG> <./pin42.PNG>] +<board1.PNG, id=376, 317.68687pt x 307.64937pt> +File: board1.PNG Graphic file (type png) + <use board1.PNG> +Package pdftex.def Info: board1.PNG used on input line 197. +(pdftex.def) Requested size: 106.69783pt x 103.32722pt. + +<board2.PNG, id=377, 315.67938pt x 307.64937pt> +File: board2.PNG Graphic file (type png) + <use board2.PNG> +Package pdftex.def Info: board2.PNG used on input line 204. +(pdftex.def) Requested size: 106.69783pt x 103.98444pt. + +<board3.PNG, id=378, 319.1925pt x 308.65312pt> +File: board3.PNG Graphic file (type png) + <use board3.PNG> +Package pdftex.def Info: board3.PNG used on input line 211. +(pdftex.def) Requested size: 106.69783pt x 103.17455pt. + [13 <./pin51.PNG> <./pin52.PNG> <./board1.PNG> <./board2.PNG>] +<board4.PNG, id=387, 315.1775pt x 307.1475pt> +File: board4.PNG Graphic file (type png) + <use board4.PNG> +Package pdftex.def Info: board4.PNG used on input line 218. +(pdftex.def) Requested size: 106.69783pt x 103.97884pt. + +<board5.PNG, id=388, 308.65312pt x 309.65688pt> +File: board5.PNG Graphic file (type png) + <use board5.PNG> +Package pdftex.def Info: board5.PNG used on input line 225. +(pdftex.def) Requested size: 106.69783pt x 107.04436pt. + [14 <./board3.PNG> <./board4.PNG> <./board5.PNG>] [15] +Chapter 5. +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! + +Underfull \hbox (badness 10000) in paragraph at lines 244--245 + + [] + + +Underfull \hbox (badness 10000) in paragraph at lines 249--250 + + [] + +[16 + +] +Chapter 6. +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +<pid.png, id=404, 989.19562pt x 565.36218pt> +File: pid.png Graphic file (type png) + <use pid.png> +Package pdftex.def Info: pid.png used on input line 261. +(pdftex.def) Requested size: 384.1096pt x 219.53279pt. + +<pid_ex.PNG, id=405, 466.74374pt x 375.20175pt> +File: pid_ex.PNG Graphic file (type png) + <use pid_ex.PNG> +Package pdftex.def Info: pid_ex.PNG used on input line 270. +(pdftex.def) Requested size: 384.1096pt x 308.78954pt. + [17 + + <./pid.png>] <pid_graph.PNG, id=410, 953.36176pt x 467.346pt> +File: pid_graph.PNG Graphic file (type png) + <use pid_graph.PNG> +Package pdftex.def Info: pid_graph.PNG used on input line 276. +(pdftex.def) Requested size: 384.1096pt x 188.29pt. + +[18 <./pid_ex.PNG> <./pid_graph.PNG>] +Chapter 7. +<arduino_uno_pinout.png, id=418, 1027.84pt x 1027.84pt> +File: arduino_uno_pinout.png Graphic file (type png) + +<use arduino_uno_pinout.png> +Package pdftex.def Info: arduino_uno_pinout.png used on input line 286. +(pdftex.def) Requested size: 320.0935pt x 320.08568pt. + [19 + + <./arduino_uno_pinout.png>] +Overfull \hbox (2.61125pt too wide) in paragraph at lines 302--305 +[]\OT1/cmr/m/n/12 Click File \TS1/cmr/m/n/12 ^^Y\OT1/cmr/m/n/12 Open and browse + Open-Mod-el-i-caEm-bed-ded \TS1/cmr/m/n/12 ^^Y\OT1/cmr/m/n/12 Firmware \TS1/cm +r/m/n/12 ^^Y\OT1/cmr/m/n/12 Arduino + [] + + +Underfull \hbox (badness 10000) in paragraph at lines 302--305 + + [] + +[20] +Underfull \hbox (badness 10000) in paragraph at lines 321--322 + + [] + +<1.PNG, id=440, 385.94188pt x 274.02374pt> +File: 1.PNG Graphic file (type png) + <use 1.PNG> +Package pdftex.def Info: 1.PNG used on input line 328. +(pdftex.def) Requested size: 213.39568pt x 151.51215pt. + +<led_ex1.PNG, id=441, 436.63126pt x 358.33875pt> +File: led_ex1.PNG Graphic file (type png) + <use led_ex1.PNG> +Package pdftex.def Info: led_ex1.PNG used on input line 333. +(pdftex.def) Requested size: 213.39568pt x 175.1337pt. + +Overfull \hbox (2.61108pt too wide) in paragraph at lines 326--336 +[]$[]$ $[]$ + [] + + +Underfull \hbox (badness 10000) in paragraph at lines 341--342 + + [] + + +Underfull \hbox (badness 10000) in paragraph at lines 343--344 + + [] + + +Underfull \hbox (badness 10000) in paragraph at lines 345--346 + + [] + + +Underfull \hbox (badness 10000) in paragraph at lines 347--348 + + [] + +<2.PNG, id=443, 421.575pt x 259.97125pt> +File: 2.PNG Graphic file (type png) + <use 2.PNG> +Package pdftex.def Info: 2.PNG used on input line 354. +(pdftex.def) Requested size: 213.39568pt x 131.59584pt. + +<pb_ex1.PNG, id=444, 510.10574pt x 369.7815pt> +File: pb_ex1.PNG Graphic file (type png) + <use pb_ex1.PNG> +Package pdftex.def Info: pb_ex1.PNG used on input line 359. +(pdftex.def) Requested size: 213.39568pt x 154.69214pt. + +Overfull \hbox (2.61108pt too wide) in paragraph at lines 352--362 +[]$[]$ $[]$ + [] + +[21 <./1.PNG> <./led_ex1.PNG>] +<pb_ex1_print.PNG, id=452, 799.18575pt x 155.3805pt> +File: pb_ex1_print.PNG Graphic file (type png) + <use pb_ex1_print.PNG> +Package pdftex.def Info: pb_ex1_print.PNG used on input line 368. +(pdftex.def) Requested size: 426.79135pt x 82.97954pt. + +Underfull \hbox (badness 10000) in paragraph at lines 375--376 + + [] + + +Underfull \hbox (badness 10000) in paragraph at lines 377--378 + + [] + + +Underfull \hbox (badness 10000) in paragraph at lines 379--380 + + [] + + +Underfull \hbox (badness 10000) in paragraph at lines 381--382 + + [] + +<3.PNG, id=453, 425.59pt x 235.88126pt> +File: 3.PNG Graphic file (type png) + <use 3.PNG> +Package pdftex.def Info: 3.PNG used on input line 388. +(pdftex.def) Requested size: 213.39568pt x 118.27505pt. + +<ldr_ex2.PNG, id=454, 368.577pt x 357.7365pt> +File: ldr_ex2.PNG Graphic file (type png) + <use ldr_ex2.PNG> +Package pdftex.def Info: ldr_ex2.PNG used on input line 393. +(pdftex.def) Requested size: 213.39568pt x 207.12158pt. + +Overfull \hbox (2.61108pt too wide) in paragraph at lines 386--396 +[]$[]$ $[]$ + [] + +[22 <./2.PNG> <./pb_ex1.PNG> <./pb_ex1_print.PNG>] +Underfull \hbox (badness 10000) in paragraph at lines 401--402 + + [] + + +Underfull \hbox (badness 10000) in paragraph at lines 403--404 + + [] + +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! + +Underfull \hbox (badness 10000) in paragraph at lines 405--406 + + [] + +<4.PNG, id=462, 380.42125pt x 270.00874pt> +File: 4.PNG Graphic file (type png) + <use 4.PNG> +Package pdftex.def Info: 4.PNG used on input line 412. +(pdftex.def) Requested size: 320.0935pt x 227.19719pt. + +<dc_ex2.PNG, id=463, 337.86224pt x 313.77225pt> +File: dc_ex2.PNG Graphic file (type png) + <use dc_ex2.PNG> +Package pdftex.def Info: dc_ex2.PNG used on input line 417. +(pdftex.def) Requested size: 128.0387pt x 118.90912pt. + +<dc_ex2_2.PNG, id=464, 373.99725pt x 337.26pt> +File: dc_ex2_2.PNG Graphic file (type png) + <use dc_ex2_2.PNG> +Package pdftex.def Info: dc_ex2_2.PNG used on input line 418. +(pdftex.def) Requested size: 128.0387pt x 115.46454pt. + +<dc_ex2_3.PNG, id=465, 372.1905pt x 334.24875pt> +File: dc_ex2_3.PNG Graphic file (type png) + <use dc_ex2_3.PNG> +Package pdftex.def Info: dc_ex2_3.PNG used on input line 419. +(pdftex.def) Requested size: 128.0387pt x 114.98442pt. + +Underfull \hbox (badness 10000) in paragraph at lines 410--422 +[]$[]$ + [] + +[23 <./3.PNG> <./ldr_ex2.PNG>] +Underfull \hbox (badness 10000) in paragraph at lines 427--428 + + [] + +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! + +Underfull \hbox (badness 10000) in paragraph at lines 429--430 + + [] + + +Underfull \hbox (badness 10000) in paragraph at lines 431--432 + + [] + + +Underfull \hbox (badness 10000) in paragraph at lines 433--434 + + [] + +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +<5.PNG, id=472, 486.31688pt x 328.22626pt> +File: 5.PNG Graphic file (type png) + <use 5.PNG> +Package pdftex.def Info: 5.PNG used on input line 440. +(pdftex.def) Requested size: 213.39568pt x 144.02434pt. + +<potentio_ex1.PNG, id=473, 373.99725pt x 357.7365pt> +File: potentio_ex1.PNG Graphic file (type png) + <use potentio_ex1.PNG> +Package pdftex.def Info: potentio_ex1.PNG used on input line 445. +(pdftex.def) Requested size: 213.39568pt x 204.11934pt. + +Overfull \hbox (2.61108pt too wide) in paragraph at lines 438--448 +[]$[]$ $[]$ + [] + +[24 <./4.PNG> <./dc_ex2.PNG> <./dc_ex2_2.PNG> <./dc_ex2_3.PNG>] +Underfull \hbox (badness 10000) in paragraph at lines 453--454 + + [] + + +Underfull \hbox (badness 10000) in paragraph at lines 455--456 + + [] + +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +Missing character: There is no in font cmr12! +<6.PNG, id=483, 624.3325pt x 312.66812pt> +File: 6.PNG Graphic file (type png) + <use 6.PNG> +Package pdftex.def Info: 6.PNG used on input line 462. +(pdftex.def) Requested size: 213.39568pt x 106.86871pt. + +<thermistor_ex1.PNG, id=484, 242.1045pt x 227.04825pt> +File: thermistor_ex1.PNG Graphic file (type png) + +<use thermistor_ex1.PNG> +Package pdftex.def Info: thermistor_ex1.PNG used on input line 467. +(pdftex.def) Requested size: 213.39568pt x 200.13219pt. + +Overfull \hbox (2.61108pt too wide) in paragraph at lines 460--470 +[]$[]$ $[]$ + [] + +[25 <./5.PNG> <./potentio_ex1.PNG>] +Underfull \hbox (badness 10000) in paragraph at lines 475--476 + + [] + + +Underfull \hbox (badness 10000) in paragraph at lines 477--478 + + [] + + +Underfull \hbox (badness 10000) in paragraph at lines 479--480 + + [] + + +Overfull \hbox (35.56775pt too wide) in paragraph at lines 481--482 +[]\OT1/cmr/m/n/12 In Servo pin, set In-putU-nit to Open-Mod-el-i-caEm-bed-ded.I +nternal.Types.ServoUnit.None. + [] + + +Underfull \hbox (badness 10000) in paragraph at lines 481--482 + + [] + +<servo_datasheet.PNG, id=492, 551.05875pt x 196.3335pt> +File: servo_datasheet.PNG Graphic file (type png) + +<use servo_datasheet.PNG> +Package pdftex.def Info: servo_datasheet.PNG used on input line 487. +(pdftex.def) Requested size: 426.79135pt x 152.06401pt. + [26 <./6.PNG> <./thermistor_ex1.PNG>] +<7.PNG, id=499, 391.96437pt x 269.005pt> +File: 7.PNG Graphic file (type png) + <use 7.PNG> +Package pdftex.def Info: 7.PNG used on input line 495. +(pdftex.def) Requested size: 213.39568pt x 146.45499pt. + +<servo_ex3.PNG, id=500, 396.88275pt x 352.31625pt> +File: servo_ex3.PNG Graphic file (type png) + <use servo_ex3.PNG> +Package pdftex.def Info: servo_ex3.PNG used on input line 500. +(pdftex.def) Requested size: 213.39568pt x 189.43617pt. + +Overfull \hbox (2.61108pt too wide) in paragraph at lines 493--503 +[]$[]$ $[]$ + [] + +[27 <./servo_datasheet.PNG> <./7.PNG> <./servo_ex3.PNG>] +Chapter 8. +<tiva_c_launchpad_pinout.png, id=508, 1129.97156pt x 846.91406pt> +File: tiva_c_launchpad_pinout.png Graphic file (type png) + +<use tiva_c_launchpad_pinout.png> +Package pdftex.def Info: tiva_c_launchpad_pinout.png used on input line 512. +(pdftex.def) Requested size: 426.79135pt x 319.87933pt. + [28 + + <./tiva_c_launchpad_pinout.png>] +Underfull \hbox (badness 10000) in paragraph at lines 539--540 + + [] + +<tiva_led.PNG, id=516, 303.63437pt x 236.38312pt> +File: tiva_led.PNG Graphic file (type png) + <use tiva_led.PNG> +Package pdftex.def Info: tiva_led.PNG used on input line 544. +(pdftex.def) Requested size: 320.0935pt x 249.20149pt. + [29] +Underfull \hbox (badness 10000) in paragraph at lines 548--549 + + [] + +[30 <./tiva_led.PNG>] +Chapter 9. + +Underfull \hbox (badness 10000) in paragraph at lines 553--554 + + [] + +[31 + +] +Overfull \hbox (80.05858pt too wide) in paragraph at lines 569--570 +[][][]$\OT1/cmtt/m/n/12 https : / / www . codeproject . com / Articles / 84461 +/ MinGW-[]Static-[]and-[]Dynamic-[]Libraries$[][] + [] + + +Overfull \hbox (173.68362pt too wide) in paragraph at lines 570--571 +[][][]$\OT1/cmtt/m/n/12 https : / / stackoverflow . com / questions / 10039401 +/ use-[]32bit-[]shared-[]library-[]from-[]64bit-[]application$[][] + [] + + +Overfull \hbox (162.33362pt too wide) in paragraph at lines 571--572 +[][][]$\OT1/cmtt/m/n/12 https : / / stackoverflow . com / questions / 142508 / +how-[]do-[]i-[]check-[]os-[]with-[]a-[]preprocessor-[]directive$[][] + [] + + +Overfull \hbox (16.30855pt too wide) in paragraph at lines 573--574 +[][][]$\OT1/cmtt/m/n/12 https : / / openmodelica . org / doc / OpenModelicaUser +sGuide / latest / interop _ + [] + +Package atveryend Info: Empty hook `BeforeClearDocument' on input line 576. +[32] +Package atveryend Info: Empty hook `AfterLastShipout' on input line 576. + (./Final.aux) +Package atveryend Info: Executing hook `AtVeryEndDocument' on input line 576. +Package atveryend Info: Executing hook `AtEndAfterFileList' on input line 576. +Package rerunfilecheck Info: File `Final.out' has not changed. +(rerunfilecheck) Checksum: C39EA63355D40134AB746DB78954129D;2640. + + +LaTeX Warning: Label(s) may have changed. Rerun to get cross-references right. + +Package atveryend Info: Empty hook `AtVeryVeryEnd' on input line 576. + ) +Here is how much of TeX's memory you used: + 9015 strings out of 493029 + 134922 string characters out of 6136234 + 221197 words of memory out of 5000000 + 12056 multiletter control sequences out of 15000+600000 + 10527 words of font info for 37 fonts, out of 8000000 for 9000 + 1141 hyphenation exceptions out of 8191 + 36i,8n,39p,809b,463s stack positions out of 5000i,500n,10000p,200000b,80000s +{/usr/share/texmf/fonts/enc/dvips/cm-super/cm-super-ts1.enc}</usr/share/texli +ve/texmf-dist/fonts/type1/public/amsfonts/cm/cmbx12.pfb></usr/share/texlive/tex +mf-dist/fonts/type1/public/amsfonts/cm/cmr10.pfb></usr/share/texlive/texmf-dist +/fonts/type1/public/amsfonts/cm/cmr12.pfb></usr/share/texlive/texmf-dist/fonts/ +type1/public/amsfonts/cm/cmtt12.pfb></usr/share/texmf/fonts/type1/public/cm-sup +er/sfrm1200.pfb> +Output written on Final.pdf (33 pages, 4536910 bytes). +PDF statistics: + 605 PDF objects out of 1000 (max. 8388607) + 474 compressed objects within 5 object streams + 140 named destinations out of 1000 (max. 500000) + 541 words of extra memory for PDF output out of 10000 (max. 10000000) + diff --git a/Report/Final.out b/Report/Final.out new file mode 100644 index 0000000..348814b --- /dev/null +++ b/Report/Final.out @@ -0,0 +1,40 @@ +\BOOKMARK [0][-]{chapter.1}{Introduction}{}% 1 +\BOOKMARK [0][-]{chapter.2}{Implementation}{}% 2 +\BOOKMARK [1][-]{section.2.1}{Algorithm}{chapter.2}% 3 +\BOOKMARK [1][-]{section.2.2}{Making changes in source code}{chapter.2}% 4 +\BOOKMARK [2][-]{subsection.2.2.1}{How to make changes to source code and make libraries}{section.2.2}% 5 +\BOOKMARK [2][-]{subsection.2.2.2}{Working with Arduino UNO [Atmega328p]}{section.2.2}% 6 +\BOOKMARK [2][-]{subsection.2.2.3}{Working with Tiva C [TM4C123G]}{section.2.2}% 7 +\BOOKMARK [0][-]{chapter.3}{Download and Installation}{}% 8 +\BOOKMARK [1][-]{section.3.1}{OpenModelica}{chapter.3}% 9 +\BOOKMARK [1][-]{section.3.2}{Arduino IDE}{chapter.3}% 10 +\BOOKMARK [1][-]{section.3.3}{Energia IDE}{chapter.3}% 11 +\BOOKMARK [0][-]{chapter.4}{About OpenModelicaEmbedded package}{}% 12 +\BOOKMARK [1][-]{section.4.1}{SynchronizeRealTime Block}{chapter.4}% 13 +\BOOKMARK [1][-]{section.4.2}{Pins}{chapter.4}% 14 +\BOOKMARK [1][-]{section.4.3}{Boards}{chapter.4}% 15 +\BOOKMARK [1][-]{section.4.4}{Examples}{chapter.4}% 16 +\BOOKMARK [1][-]{section.4.5}{ArduinoExamples}{chapter.4}% 17 +\BOOKMARK [1][-]{section.4.6}{TivaC\137Examples}{chapter.4}% 18 +\BOOKMARK [1][-]{section.4.7}{Internal}{chapter.4}% 19 +\BOOKMARK [0][-]{chapter.5}{Hardware In Loop Simulation}{}% 20 +\BOOKMARK [1][-]{section.5.1}{Implementation}{chapter.5}% 21 +\BOOKMARK [0][-]{chapter.6}{PID Controller}{}% 22 +\BOOKMARK [1][-]{section.6.1}{Implementation}{chapter.6}% 23 +\BOOKMARK [1][-]{section.6.2}{Example for PID}{chapter.6}% 24 +\BOOKMARK [0][-]{chapter.7}{Working with Arduino UNO}{}% 25 +\BOOKMARK [1][-]{section.7.1}{Connecting and Configuring the Board}{chapter.7}% 26 +\BOOKMARK [1][-]{section.7.2}{Interfacing with OpenModelica}{chapter.7}% 27 +\BOOKMARK [1][-]{section.7.3}{Examples for Arduino}{chapter.7}% 28 +\BOOKMARK [2][-]{subsection.7.3.1}{LED Examples}{section.7.3}% 29 +\BOOKMARK [2][-]{subsection.7.3.2}{Push Button Examples}{section.7.3}% 30 +\BOOKMARK [2][-]{subsection.7.3.3}{LDR Examples}{section.7.3}% 31 +\BOOKMARK [2][-]{subsection.7.3.4}{DC Motor Examples}{section.7.3}% 32 +\BOOKMARK [2][-]{subsection.7.3.5}{Potentiometer Examples}{section.7.3}% 33 +\BOOKMARK [2][-]{subsection.7.3.6}{Thermistor Examples}{section.7.3}% 34 +\BOOKMARK [2][-]{subsection.7.3.7}{Servo Motor Examples}{section.7.3}% 35 +\BOOKMARK [0][-]{chapter.8}{Working with Tiva C Launchpad}{}% 36 +\BOOKMARK [1][-]{section.8.1}{Connecting and Configuring the Board}{chapter.8}% 37 +\BOOKMARK [1][-]{section.8.2}{Interfacing with OpenModelica}{chapter.8}% 38 +\BOOKMARK [1][-]{section.8.3}{Examples for Tiva C}{chapter.8}% 39 +\BOOKMARK [0][-]{chapter.9}{Conclusion}{}% 40 diff --git a/Report/Final.pdf b/Report/Final.pdf Binary files differnew file mode 100644 index 0000000..bf3c688 --- /dev/null +++ b/Report/Final.pdf diff --git a/Report/Final.tex b/Report/Final.tex new file mode 100644 index 0000000..8a6906d --- /dev/null +++ b/Report/Final.tex @@ -0,0 +1,578 @@ +\documentclass[12pt,a4paper]{report} +\usepackage[hmargin=3cm,vmargin=3cm]{geometry} +\usepackage{graphicx} +\usepackage{caption} +\usepackage{array} +\usepackage{listings} +\usepackage{hyperref} +\usepackage{float} +\usepackage{textcomp} +\usepackage{subcaption} +\newcommand\tab[1][0.5cm]{\hspace*{#1}} +\graphicspath{Images} + +\hypersetup{ + colorlinks=true, + linkcolor=black, + urlcolor=blue +} +\begin{document} + +\begin{figure} +\centering +\includegraphics[width = 0.3\textwidth]{iit} +\hspace{1cm} +\includegraphics[width = 0.4\textwidth]{fossee-logo} +\end{figure} + +\title{\textbf{\textbf{Developing a Generic Purpose OpenModelica Library for Embedded Applications}}\vspace{5mm}\\ +\vspace{5mm} \large Developer's Document - II\vspace{5mm} \\ \vspace{5mm}\small by\\ \vspace{1mm} \large \textbf{Manas Ranjan Das}\\ \vspace{5mm} +%\small Under the guidance of \\ \vspace{2mm} +%\large \textbf{Mentor: Mr. Manas Ranjan Das}\\ \vspace{3mm} +%\large \textbf{Prof. Kannan M. Moudgalya} \vspace{1mm}\\Department of Chemical Engineering \vspace{1mm} \\IIT Bombay +} +%\vspace{1cm} + +\maketitle + +\tableofcontents +\listoffigures + +\chapter{\textbf{Introduction}} +OpenModelica is a free and open source environment based on the Modelica modeling language for simulating, optimizing and analyzing complex dynamic systems. OpenModelica is used in academic and industrial environments. Industrial applications include the use of OpenModelica along with proprietary software in the fields of power plant optimization, automotive and water treatment. Models are either built through line by line code or graphical code in OpenModelica. OpenModelica can interact with C, Python languages and can call C, Python functions from within its models. OpenModelica is a powerful tool that can be used to design and simulate complete control systems. + +Our project was to implement model based design i.e. creating models for different embedded applications and generating C code that can be ported to the respective family of microcontrollers.We also worked towards Improving the Hardware In Loop (HIL) implementation on OpenModelica and microcontrollers like arduino and TivaC.The current implementation which is based on Inter Process Communication (IPC) needs to be made robust. Hence there is a need to come up with a less cumbersome IPC for HIL. + + +\chapter{\textbf{Implementation}} +\section{Algorithm} +\begin{enumerate} +\item Once you have installed OpenModelica, launch OMEdit and open the OpenModelicaEmbedded package. +\item To use the above package you will also need to load Modelica\_DeviceDrivers package. The ‘synchronizeRealtime’ block present in this package is used to make the simulation of models real-time. All it does is that, it maps the time interval provided by you before simulation with clock your PC. +\item The components provided in this package are: +\begin{enumerate} +\item Pins: It contains Analog input, Analog output, Digital input, Digital output and Servo pins to perform corresponding function in model. +\item Boards: Any of the provided board can be used depending the one you are using, else use the ‘customBoard’ provided and vary it’s parameters to match the configuration of the development board you are using. +\end{enumerate} +\item Take a look at the examples provided along with the package to understand the basics structure of a model. Each model has ‘Board’ block which represents the development board used. This block when added to a model, on simulation calls a couple of functions present in ‘Internal > ExternalFunctions’ which set the initialisation parameters for communication like PORT, BAUD rate, etc. +\item These modelica functions present in ‘ExternalFunctions’ then call external C functions which perform the actual task the function is supposed to do. +\item These external C functions are bundled together and provided in the form of libraries. The Libraries used will be ‘*.dll’ in case of WindowsOS and ‘*.so’ in case of Linux. +\item After adding a board to your model add pins using blocks provided for the same. If you want to send some data from OpenModelica to connected microcontroller the use Analog/Digital Output Pin, and vice versa. Use Analog Pin while working with real data and Digital pin while working with Boolean. +\item These pin blocks again call functions in similar manner to either send or receive data. +\item Once your model is ready and check is successful, upload appropriate Firmware on microcontroller board connected. +\item The Firmware’s for Arduino and Tiva C borads have been provided along with the package. Open Arduino IDE if using Arduino board and Energia IDE if using Tiva C board and upload corresponding firmware on board. +\item The Firmware implements Firmata protocol to establish communication with OpenModelica. +\item Now go back to OpenModelica and simulate your model. +\end{enumerate} + +\section{Making changes in source code} +\subsection{How to make changes to source code and make libraries} +{\textbf {Linux Operating System}}\\ + +Open the source codes by browsing to this location : OpenModelicaEmbedded \textrightarrow Source.After making changes to the source code files open Terminal.Browse to OpenModelicaEmbedded \textrightarrow Source folder using ‘cd’ command.Run command ‘make’ to generate shared object file('*.so').\\ +\\ +{\textbf {Windows Operating System}}\\ + +Open the source codes by browsing to this location : OpenModelicaEmbedded \textrightarrow Source. After making changes to the source code, open Command Prompt (cmd).Browse to OpenModelicaEmbedded \textrightarrow Source folder using ‘cd’ command.To compile the CPP files run the command: g++ -c modelPlugFirmata.cpp serial.cpp. To create a DLL from generated object files, run the command: g++ -shared -o modelPlugFirmata.dll modelPlugFirmata.o serial.o.Then copy the generated DLL file and paste it in folders: OpenModelicaEmbedded and Resources \textrightarrow Library \textrightarrow win64.\\ + +\subsection{Working with Arduino UNO [Atmega328p]} + Setting up firmware for Arduino board\\ + In Tools Menu, select appropriate Board (Arduino/Genuino UNO) and Port as the available serial port to which Arduino is connected.\\ + Open pidmata3 sketch: File \textrightarrow Open \textrightarrow OpenModelicaEmbedded \textrightarrow Firmware \textrightarrow Arduino \textrightarrow pidmata3 \textrightarrow pidmata3.ino. + Upload the sketch to the board.\\ + +\textbf{Simulating the Modelica model}\\ +Now open OMEdit window.\\ +Open ‘package.mo’ file OpenModelicaEmbedded folder.\\ +In OpenModelicaEmbedded package, open ArduinoExamples’ package which consists of examples for arduino board. Check and simulate the example models and verify the results. + +\subsection{Working with Tiva C [TM4C123G]} +In Energia, open the firmware for Tiva C provided in folder through path : File \textrightarrow Open \textrightarrow OpenModelicaEmbedded \textrightarrow Firmware \textrightarrow Tiva C \textrightarrow StandardFirmata \textrightarrow \\ StandardFirmata.ino or add zip file of this StandardFirmata as an external library in Energia from the same folder.\\ +Select appropriate Board (Tiva C) and Port (USB port where Tiva C is connected) in Tools menu.\\ +Then, upload the firmware on board.\\ + +\textbf{Simulate a model with Tiva C.}\\ +Now open OMEdit and Open the package.mo file from OpenModelicaEmbedded package\\ +Open an example provided in the OpenModelicaEmbedded package which includes a Tiva C board.\\ +Check and Simulate the model and verify the results in Plotting window.\\ + +\chapter{\textbf{Download and Installation}} +\section{OpenModelica} +OpenModelica can be downloaded online from \url{https://openmodelica.org}.\\ +\\ +For Linux:\\ +The Debian/Ubuntu package for OpenModelica can be downloaded and installed by following the instructions on \url{https://openmodelica.org/download/download-linux}. OMEdit can be launched by typing OMEdit in the Terminal.\\ +\\ +For Windows:\\ +The setup for OpenModelica on Windows can be downloaded from \url{https://openmodelica.org/download/download-windows}. After downloading and installation of the software, OMEdit or OpenModelica Connection Editor can be launched by clicking on its icon or by navigating through Start menu. + +\section{Arduino IDE} +The open source Arduino Software is used to write codes and upload them to the board. For the setup of Arduino IDE for both Windows and Linux go to \url{https://www.arduino.cc/en/Main/Software} and follow the download and install instructions. + +\section{Energia IDE} +Energia is a Arduino-like coding environment designed for Texas Instruments Launchpads. The setup for Energia can be downloaded from \url{http://energia.nu/download/}. The instructions for installation can be referred from - \\ +For Linux: \url{http://energia.nu/guide/guide_linux/} +For Windows: \url{http://energia.nu/guide/guide_windows/} + + +\chapter{\textbf{About OpenModelicaEmbedded package}} + +OpenModelicaEmbedded package is designed to interact between embedded systems and OpenModelica models using C/C++ functions. This package can work for both Atmega series (tested for Arduino UNO - Atmega328p) and Texas Instruments Tiva C series (tested for Tiva C EK-TM4C123GXL Launchpad).\\ +\\ +The package can be downloaded from the following link:\\ +\url{https://github.com/manasdas17/OpenModelicaEmbedded}\\ +This library requires Modelica\_DeviceDrivers library as a supporting library which can be downloaded from the following link:\\ +\url{https://github.com/modelica/Modelica_DeviceDrivers} + +\begin{figure}[H] +\centering +\includegraphics[width =0.5 \textwidth]{package_str} +\caption{Structure of OpenModelicaEmbedded package} +\label{figure:1} +\end{figure} + +\section{SynchronizeRealTime Block} +This block is a part of Modelica\_DeviceDrivers library used for real-time simulation of the model, i.e., this block synchronizes simulation time of the process to real- time clock of the operating system. Without this block, the models designed using this package will not be able to give proper real-time output. This block works at five different priorty levels which can be changed in Parameters dialog box by double-clicking the block. + +\begin{figure}[H] +\centering +\includegraphics[width = 0.3\textwidth]{realtime} +\includegraphics[width = 0.65\textwidth]{realtimepara} +\caption{SymchronizeRealTime block} +\label{figure:2} +\end{figure} + +\section{Pins} +This package contains blocks which define to input and output pins of the board to which our hardware can be connected. These pin components define the properties and working of the pins used in the hardware.\\ + +\begin{itemize} +\item \textbf{AnalogInput:} It reads an analog signal from the specified pin. This component uses the function ‘analogRead’ of Arduino. It takes minimum and maximum values of the signal as parameter (default values being 0 and 1 respectively) and gives output depending on the size of ADC (analog to digital convertor) which is 10-bit for Arduino UNO board and 12-bit for Tiva C series TM4C123G board. +\begin{figure}[H] +\centering +\includegraphics[width = 0.4\textwidth]{pin11} +\includegraphics[width = 0.55\textwidth]{pin12} +\caption{AnalogInput block} +\label{figure:3} +\end{figure} +\item \textbf{AnalogOutput:} It writes analog value (PWM wave) to the specified pin. This component uses the function ‘analogWrite’ of Arduino. It takes minimum and maximum values of the signal as parameter (default values being 0 and 1 respectively) and gives output depending on the size of ADC. +\begin{figure}[H] +\centering +\includegraphics[width = 0.4\textwidth]{pin21} +\includegraphics[width = 0.55\textwidth]{pin22} +\caption{AnalogOutput block} +\label{figure:4} +\end{figure} +\item \textbf{DigitalInput:} It reads an digital signal from the specified pin. This component uses the function ‘digitalRead’ of Arduino. It only takes boolean signals. +\begin{figure}[H] +\centering +\includegraphics[width = 0.4\textwidth]{pin31} +\includegraphics[width = 0.55\textwidth]{pin32} +\caption{DigitalInput block} +\label{figure:5} +\end{figure} +\item \textbf{DigitalOutput:} It writes digital value to the specified pin. This component uses the function ‘digitalWrite’ of Arduino. It only takes boolean signals. +\begin{figure}[H] +\centering +\includegraphics[width = 0.4\textwidth]{pin41} +\includegraphics[width = 0.55\textwidth]{pin42} +\caption{DigitalOutput block} +\label{figure:6} +\end{figure} +\item \textbf{Servo:} It controls a servo motor attached to the specified pin. This component uses the 'Servo' library of Arduino. By default, the range goes from 0 to 1, which corresponds to 0 to 180 degrees. If you want to input values in degrees or radians, you can change the parameter 'InputUnit' to 'Degrees' or 'Radians'. +\begin{figure}[H] +\centering +\includegraphics[width = 0.4\textwidth]{pin51} +\includegraphics[width = 0.55\textwidth]{pin52} +\caption{Servo block} +\label{figure:7} +\end{figure} +\end{itemize} + +\section{Boards} +This package contains block components which enable connection with different firmata boards. These components take serial port used for connection as parameter. +\begin{itemize} +\item \textbf{Arduino:} Used for connecting to Arduino boards, such as Arduino UNO, Arduino Mega 2500 and others having similar firmata. +\begin{figure}[H] +\centering +\includegraphics[width =0.25 \textwidth]{board1} +\caption{Arduino block} +\label{figure:8} +\end{figure} +\item \textbf{ArduinoLeonardo:} Supports Arduino Leonardo board and other boards using native USB. +\begin{figure}[H] +\centering +\includegraphics[width =0.25 \textwidth]{board2} +\caption{ArduinoLeonardo block} +\label{figure:9} +\end{figure} +\item \textbf{StandardFirmata:} Connects to Arduino compatible boards. +\begin{figure}[H] +\centering +\includegraphics[width =0.25 \textwidth]{board3} +\caption{StandardFirmata block} +\label{figure:10} +\end{figure} +\item \textbf{CustomFirmata:} Supports any board firmata. +\begin{figure}[H] +\centering +\includegraphics[width =0.25 \textwidth]{board4} +\caption{CustomFirmata block} +\label{figure:11} +\end{figure} +\item \textbf{customBoard:} Takes name of the board also as parameter and can be used to connect any board supporting firmata. +\begin{figure}[H] +\centering +\includegraphics[width =0.25 \textwidth]{board5} +\caption{customBoard block} +\label{figure:12} +\end{figure} +\end{itemize} + +\section{Examples} +The package contains example models to get introduced to the working of components of the package. These models accomplish different tasks using different blocks provided in Pins and Boards package. + +\section{ArduinoExamples} +The package contains example models specifc to Arduino UNO board. It can be used for other Arduino boards by change Pin Number parameter for the Pin blocks. Detailed description for the package is given in 'Working with Arduino'. + +\section{TivaC\_Examples} +The package contains example models specifc to Tiva C Launchpad TM4C123G board. It can be used for other similar boards by change Pin Number parameter for the Pin blocks. Detailed description for the package is given in 'Working with Tiva C'. + +\section{Internal} +The components of this package cannot be used directly in the models. This package consists of icons and connectors defined and used for block designing, new types defined and used for the blocks and functions designed using external C/C++ functions at backend. + +\chapter{\textbf{Hardware In Loop Simulation}} +\tab Hardware-in-the-loop (HIL) simulation, or HWIL, is a technique that is used in the development and test of complex real-time embedded systems. HIL simulation provides an effective platform by adding the complexity of the plant under control to the test platform. The complexity of the plant under control is included in test and development by adding a mathematical representation of all related dynamic systems. These mathematical representations are referred to as the “plant simulation”. The embedded system to be tested interacts with this plant simulation.\\ + +A HIL simulation must include electrical emulation of sensors and actuators. These electrical emulations act as the interface between the plant simulation and the embedded system under test. The value of each electrically emulated sensor is controlled by the plant simulation and is read by the embedded system under test (feedback). Likewise, the embedded system under test implements its control algorithms by outputting actuator control signals. Changes in the control signals result in changes to variable values in the plant simulation. + +\section{Implementation} +\tab The package developed (OpenModelicaEmbedded) has several components like micro-controller boards, Digital/Analog Pins, etc. which you will have to use in your model to make it interact with connected hardware device. These components make calls to external C functions present in the library provided in Library directory. Those functions using serial communication communicate with the connected device. This source file will remain same irrespective of the connected hardware device and platform used (Windows, Linux, Mac).\\ + +The connected hardware device uses Firmata protocol to communicate with OpenModelica. The source code implementing Firmata protocol on hardware will vary depending on the language/ IDE used by that hardware/microcontroller, but the underlying protocol remains the same. + +\chapter{\textbf{PID Controller}} +A \textbf{proportional - integral - derivative controller} (\textbf{PID controller} or \textbf{three term controller}) is a control loop feedback mechanism widely used in industrial control systems and a variety of other applications requiring continuously modulated control. A PID controller continuously calculates an error value e(t) as the difference between a desired setpoint (SP) and a measured process variable (PV) and applies a correction based on proportional, integral, and derivative terms (denoted P, I, and D respectively) which give the controller its name. + +\section{Implementation} +The PID is implemented in the Firmware present on the hardware device using ‘AutoPID’ Library. To use the hardware for PID you will have to change the Firmware (Arduino source code) a bit by following the instructions mentioned in the Firmware itself. The only thing you have to do is just comment/uncomment a few macros depending on your application. + +\begin{figure}[H] +\centering +\includegraphics[width =0.9\textwidth]{pid} +\caption{Firmata to work with PID Controller} +\label{figure:24} +\end{figure} + +\section{Example for PID} +\textbf{Example:} DCMotorWithPID (from Examples package) +\begin{figure}[H] +\centering +\includegraphics[width =0.9\textwidth]{pid_ex} +\caption{Model for PID Controller with DC Motor} +\label{figure:25} +\end{figure} +\begin{figure}[H] +\centering +\includegraphics[width = 0.9\textwidth]{pid_graph} +\caption{Plot for PID Controller with DC Motor} +\label{figure:26} +\end{figure} + +\chapter{\textbf{Working with Arduino UNO}} +The Arduino UNO is a widely used microcontroller board based of ATmega328P microcontroller IC and is developed by Arduino.cc. It operates at a voltage of 5V. The board contains 14 Digital and 6 Analog input/output (I/O) pins, a 10-bit ADC (Analog to Digital Convertor), 8-bit DAC, a in-built LED connected to digital pin no. 13 and many other features. + +\begin{figure}[H] +\centering +\includegraphics[width =0.75 \textwidth]{arduino_uno_pinout} +\caption{Pin Diagram of Arduino UNO} +\label{figure:13} +\end{figure} + +\section{Connecting and Configuring the Board} +\begin{enumerate} +\item Connect the Arduino UNO board to the computer using a USB cable. +\item Open Arduino IDE. +\item In Tools Menu, select Board \textrightarrow Arduino/Genuino UNO and Port as the available serial port to which Arduino is connected. +\item The serial port can be identified by:\\ +For Linux:\\ +Type the command \textbf{ls -l /dev/ttyACM*} in the terminal and the output it returns gives the port to which Arduino is connected, for example \textbf{/dev/ttyACM0}.\\ +For Windows:\\ +Open \textbf{Device Manager} and check for the name of connected port which will be in the form, for example, \textbf{COM5}. +\item Click Sketch \textrightarrow Include libraries and select Manage libraries, type AutoPID in the search bar and install the library. +\item Click File \textrightarrow Open and browse OpenModelicaEmbedded \textrightarrow Firmware \textrightarrow Arduino \textrightarrow pidmata3 and open pidmata3.ino.\\ +OR\\ +Open StandardFirmata sketch: File \textrightarrow Examples \textrightarrow StandardFirmata , if not working with PID.\\ +\item Upload the sketch to the board. +\end{enumerate} + +\section{Interfacing with OpenModelica} +\begin{enumerate} +\item Upload StandardFirmata sketch to the Arduino board. +\item Open package.mo from OpenModelicaEmbedded package, also open package.mo file from Modelica\_DeviceDrivers library. +\item In OpenModelicaEmbedded package, open ArduinoExamples package. +\item In Diagram view, change the port name for the board component to the port to which board is connected by double-clicking on it. +\item Simulate the example model. +\end{enumerate} + +\section{Examples for Arduino} +ArduinoExamples package consists of example models designed for specificly to work with Arduino UNO board. In order to work with these examples, double-click of board block in the Diagram view and change port name to the port to which board is connected. If working with any other similar Arduino board, double-click the pin blocks and change pin number as per the used board. + +\subsection{LED Examples} +\textbf{Example:} arduino\_ex1\_led\_blue\\ + +The following is an example to turn on the blue led indefinitely. Double clicking each block opens the parameter window for it. Change the parameters according to the following image. + +\begin{figure}[H] +\begin{subfigure}{.5\textwidth} +\centering +\includegraphics[width =\linewidth]{1} +\caption{Connections for lighting up blue led} +\end{subfigure} +\begin{subfigure}{.5\textwidth} +\centering +\includegraphics[width =\linewidth]{led_ex1} +\caption{Model for lighting up blue led} +\end{subfigure} +\caption {Arduino Led Example} +\label{figure:14} +\end{figure} + +\subsection{Push Button Examples} +\textbf{Example:} arduino\_ex1\_push\_button\_status\\ + +The following example is to read the status of the pushbutton and display it on the serial monitor.\\ + +In this model, a BooleanValue block is used to show boolean value coming from the digital input pin of arduino on Simulation Output. The block BooleanValue can be found at Modelica.Blocks.Interaction.Show.BooleanValue.\\ + +Moreover, a print statement to print boolean value is written in the Text view of the model which can be seen in ~\ref{figure:23}.\\ + +Double clicking each block opens the parameter window for it. Change the parameters according to the following image. + +\begin{figure}[H] +\begin{subfigure}{.5\textwidth} +\centering +\includegraphics[width =\linewidth]{2} +\caption{Connections for push button} +\end{subfigure} +\begin{subfigure}{.5\textwidth} +\centering +\includegraphics[width =\linewidth]{pb_ex1} +\caption{Model for checking status of push button} +\end{subfigure} +\caption {Arduino Push Button Example} +\label{figure:15} +\end{figure} + +\begin{figure}[H] +\centering +\includegraphics[width =\textwidth]{pb_ex1_print} +\caption{Print Statement} +\label{figure:23} +\end{figure} + + +\subsection{LDR Examples} +\textbf{Example:} arduino\_ex2\_ldr\_read\\ + +Turning the blue LED on and off according to the values of LDR (Light Dependent Resistor).\\ + +In this model, 2 blocks have been used namely Less and Constant.\\ + +Less block takes 2 input and gives 1 output according to the values of input. For example in the case below, when value from pin 19 is less than k = 300, output is true (or 1) and when value from pin 19 is greater than equal to k=300, its output is false (or 0). The block can be found at Modelica.Blocks.Logical.Less.\\ + +Constant block provides with a constant value which can be set by user. The block can be found at Modelica.Blocks.Sources.Constant. + +\begin{figure}[H] +\begin{subfigure}{.5\textwidth} +\centering +\includegraphics[width =\linewidth]{3} +\caption{Connections for ldr} +\end{subfigure} +\begin{subfigure}{.5\textwidth} +\centering +\includegraphics[width =\linewidth]{ldr_ex2} +\caption{Model for switching led depending on ldr value} +\end{subfigure} +\caption {Arduino LDR Example} +\label{figure:16} +\end{figure} + +\subsection{DC Motor Examples} +\textbf{Example:} arduino\_ex2\_dcmotor\_both\\ + +The following example is of rotating the DC motor in both directions. As visible in the model below, 2 pulse blocks are used to manage this. \\ + +A pulse block generates pulse signals of real value. It’s amplitude, duty cycle, time period, start time can be varied through changing amplitude, width, period, startTime respectively in the parameter window of the pulse. The block can be found at Modelica.Blocks.Sources.Pulse.\\ + +Double clicking each block opens the parameter window for it. Change the parameters according to the following image. + +\begin{figure}[H] +\begin{subfigure}{.75\textwidth} +\centering +\includegraphics[width =\linewidth]{4} +\caption{Connections for dc motor} +\end{subfigure} +\begin{subfigure}{\textwidth} +\centering +\includegraphics[width =0.3\linewidth]{dc_ex2} +\includegraphics[width =0.3\linewidth]{dc_ex2_2} +\includegraphics[width =0.3\linewidth]{dc_ex2_3} +\caption{Model for rotating dc motor in both directions} +\end{subfigure} +\caption {Arduino DC Motor Example} +\label{figure:17} +\end{figure} + +\subsection{Potentiometer Examples} +\textbf{Example:} arduino\_ex1\_pot\_threshold\\ + +The following example is of turning on LEDs depending on the potentiometer threshold. As seen in the model below, we’ve used Xor and GreaterEqualThreshold blocks. \\ + +The GreaterEqualThreshold block has a parameter-threshold; if the input value to the block is greater than or equal to this threshold then the output is the same as input, otherwise 0.\\ + +This block can be found at Modelica.Blocks.Logical.GreaterEqualThreshold.\\ + +The other one is Xor block which simply xor’s ihe 2 input values it gets. This block can be found at Modelica.Blocks.Logical.Xor. + +\begin{figure}[H] +\begin{subfigure}{.5\textwidth} +\centering +\includegraphics[width =\linewidth]{5} +\caption{Connections for potentiometer} +\end{subfigure} +\begin{subfigure}{.5\textwidth} +\centering +\includegraphics[width =\linewidth]{potentio_ex1} +\caption{Model for potentiometer threshold ranges} +\end{subfigure} +\caption {Arduino Potentiometer Example} +\label{figure:18} +\end{figure} + +\subsection{Thermistor Examples} +\textbf{Example:} arduino\_ex1\_therm\_read\\ + +Turning the buzzer on and off using the thermistor values read by ADC. \\ + +It’s model has Greater block. Greater block takes 2 input and gives 1 output according to the values of input. For example in the case below, when value from pin 18 is greater than k = 500, output is true(or 1) and when value from pin 18 is less than equal to k=500, its output is false(or 0). The block can be found at Modelica.Blocks.Logical.Greater. + +\begin{figure}[H] +\begin{subfigure}{.5\textwidth} +\centering +\includegraphics[width =\linewidth]{6} +\caption{Connections for thermistor} +\end{subfigure} +\begin{subfigure}{.5\textwidth} +\centering +\includegraphics[width =\linewidth]{thermistor_ex1} +\caption{Model for checking value of thermistor} +\end{subfigure} +\caption {Arduino Thermistor Example} +\label{figure:19} +\end{figure} + +\subsection{Servo Motor Examples} +\textbf{Example:} arduino\_ex3\_servo\_loop\\ + +Rotating the servo in increments. \\ + +The model contains blocks like Product, RealToInteger, IntegerToReal, Constant and Ramp. The Ramp block gives a strictly increasing value. On using RealToInteger block on the output, it converts it to step function. Now as the Product block accepts 2 input in real format only, there was a need to convert the value back to real using IntegerToReal block.\\ + +In Servo pin, set InputUnit to OpenModelicaEmbedded.Internal.Types.ServoUnit.None. \\ + +As can be seen from data sheet (Figure:~\ref{figure:27}) SG90 has a duty cycle of 5-10\% where if it is 5\%, the position of motor is -90 degrees and if 10\%, it is +90 degrees. So as we were simulating for 10 seconds, MinPulse was 0.5 sec and MaxPulse was 1sec in Servo pin Parameters. + +\begin{figure}[H] +\centering +\includegraphics[width =\textwidth]{servo_datasheet} +\caption{Data Sheet for Servo Motor SG90} +\label{figure:27} +\end{figure} + +\begin{figure}[H] +\begin{subfigure}{.5\textwidth} +\centering +\includegraphics[width =\linewidth]{7} +\caption{Connections for Servo Motor} +\end{subfigure} +\begin{subfigure}{.5\textwidth} +\centering +\includegraphics[width =\linewidth]{servo_ex3} +\caption{Model for working with Servo Motor} +\end{subfigure} +\caption {Arduino Servo Motor Example} +\label{figure:20} +\end{figure} + +\chapter{\textbf{Working with Tiva C Launchpad}} +The Tiva C series Launchpad Evaluation board (EK-TM4C123GXL) is low cost ARM-Cortex-M4F based microcontroller. The board contains 40 I/O pins, two user programmable push buttons, a RGB led and many more features. + +\begin{figure}[H] +\centering +\includegraphics[width =\textwidth]{tiva_c_launchpad_pinout} +\caption{Pin Diagram of Tiva C Launchpad} +\label{figure:21} +\end{figure} + +\section{Connecting and Configuring the Board} +\begin{enumerate} +\item Connect the Tiva C board to the computer using a USB cable. +\item Open Energia IDE. +\item In Tools Menu, select Board \textrightarrow Tiva C and Port as the available serial port to which Arduino is connected. +\item If Tiva C board is not present, then click on Board Manager, type Tiva C in search bar and then click on Install to install board library, then apply Step 3. +\item In Sketch menu, Select Include Library \textrightarrow Add .zip library and add the zip file provided in the Firmware folder. Then open StandardFirmata sketch: File \textrightarrow Examples \textrightarrow StandardFirmata.\\ +OR\\ +Click File \textrightarrow Open and browse OpenModelicaEmbedded \textrightarrow Firmware \textrightarrow Tiva C \textrightarrow StandardFirmata and open StandardFiramata.ino. +\item Upload the sketch to the board. +\end{enumerate} + +\section{Interfacing with OpenModelica} +\begin{enumerate} +\item Upload StandardFirmata sketch to the Tiva C board. +\item Open package.mo from OpenModelicaEmbedded package, also open package.mo file from Modelica\_DeviceDrivers library. +\item In OpenModelicaEmbedded library, open TivaC\_Examples package. +\item In Diagram view, change the port name for the board component to the port to which board is connected by double-clicking on it. +\item Simulate the example model. +\end{enumerate} + +\section{Examples for Tiva C} +The examples explained in package for tiva-c are same as that for arduino board except that the pin configurations are different. The configuration can be seen from the pin diagram from Figure~\ref{figure:21}.\\ + +\textbf{Example:} tivac\_ex1\_led\_blue +\begin{figure}[H] +\centering +\includegraphics[width =0.75\textwidth]{tiva_led} +\caption{Tiva C Led Example} +\label{figure:22} +\end{figure} +The example Tiva-C Led works same as the one which is explained for arduino except for the fact that the pin configuration has been changed,for arduino it was pin number 9 while for tiva-c board it is pin number 40 as can be reffered from the pin diagram of tiva-c board (Figure: ~\ref{figure:21}). All other working remains same as already explained in case of Arduino.\\ + +For all other models also only pin number changes in case of Arduino rest they are similar to those present in ArduinoExamples package. + +\chapter{\textbf{Conclusion}} +\tab The project "Interfacing of Embedded Systems with OpenModelica", is based on implementing an example package for Arduino board as well as for tiva-C board.We implemented the same set of examples on both Arduino board as well as Tiva-c board because Tiva-c board targets industries.We implemented hardware in loop simulation and PID tuning was done. Indeed the same set of codes can be used for linux as well as for windows plateform. We also explored the embedded targets package of the Modelica\_DeviceDrivers library.\\ + +Although, there were many issues initially, most of them got resolved in the course of the project. While working on the project with OpenModelica we came to a conclusion that OpenModelica is an open source software based on Modelica language to design and simulate complex physical systems through code as well as graphical blocks which is also very useful for electronics prototyping and real time simulations. The main drawback of the library is its lack of appropriate documentation and various other hardware supports in the electronics hardware area. Such modules are open for modifications and can be extended by future developers. Therefore we have explored OpenModelica in detail and tried to provide a better insight in this open source software which will help developers in the future. + +\newpage +\title{\textbf{\textbf{\LARGE +\begin{flushleft} +\textbf{Reference} +\end{flushleft} +}}} +The following sources were referred to while working on this project: +\begin{itemize} +\item Peter Fritzson :Principles of Object-Oriented Modeling and Simulation with Modelica 3.3: A Cyber-Physical Approach +\item \url{ https://www.openmodelica.org/} +\item \url{ http://book.xogeny.com/} +\item \url{ https://build.openmodelica.org/Documentation/Modelica.html} +\item \url{ https://www.codeproject.com/Articles/84461/MinGW-Static-and-Dynamic-Libraries} +\item \url{https://stackoverflow.com/questions/10039401/use-32bit-shared-library-from-64bit-application} +\item \url{ https://stackoverflow.com/questions/142508/how-do-i-check-os-with-a-preprocessor-directive} +\item \url{https://en.wikipedia.org/wiki/PID_controller} +\item \url { https://openmodelica.org/doc/OpenModelicaUsersGuide/latest/interop_c_python.html} +\end{itemize} + +\end{document} + + diff --git a/Report/Final.tex~ b/Report/Final.tex~ new file mode 100644 index 0000000..872cd3e --- /dev/null +++ b/Report/Final.tex~ @@ -0,0 +1,591 @@ +\documentclass[12pt,a4paper]{report} +\usepackage[hmargin=3cm,vmargin=3cm]{geometry} +\usepackage{graphicx} +\usepackage{caption} +\usepackage{array} +\usepackage{listings} +\usepackage{hyperref} +\usepackage{float} +\usepackage{textcomp} +\usepackage{subcaption} +\newcommand\tab[1][0.5cm]{\hspace*{#1}} +\graphicspath{Images} + +\hypersetup{ + colorlinks=true, + linkcolor=black, + urlcolor=blue +} +\begin{document} + +\begin{figure} +\centering +\includegraphics[width = 0.3\textwidth]{iit} +\hspace{1cm} +\includegraphics[width = 0.4\textwidth]{fossee-logo} +\end{figure} + +\title{\textbf{\textbf{Developing a Generic Purpose OpenModelica Library for Embedded Applications}}\vspace{5mm}\\ +\vspace{5mm} \large Developer's Document - II\vspace{5mm} \\ \vspace{5mm}\small by\\ \vspace{1mm} \large \textbf{Manas Ranjan Das}\\ \vspace{5mm} +%\small Under the guidance of \\ \vspace{2mm} +%\large \textbf{Mentor: Mr. Manas Ranjan Das}\\ \vspace{3mm} +%\large \textbf{Prof. Kannan M. Moudgalya} \vspace{1mm}\\Department of Chemical Engineering \vspace{1mm} \\IIT Bombay +} +%\vspace{1cm} + +\maketitle + + +\newpage +\title{\textbf{\textbf{\LARGE +\begin{flushleft} +\textbf{Acknowledgment} +\end{flushleft} +}}} +%\begin{flushleft} +We are grateful to FOSSEE, IIT Bombay and our mentor Mr. Manas Ranjan Das for giving us the opportunity to work on the project Implementing an embedded package for OpenModelica. We express our sincere gratitude to our mentor Mr. Manas Ranjan Das for his support, help and encouragement throughout the project. We would also like to thank Professor Kannan M.Moudgalya who introduced us to FOSSEE, its projects and the significance of its work.we are grateful for we would not have worked on the open source software at this level of exposure without your guidance and support.\\ + + Also we would like to recognize the support and contribution of all the team members. +%\end{flushleft} + +\tableofcontents +\listoffigures + +\chapter{\textbf{Introduction}} +OpenModelica is a free and open source environment based on the Modelica modeling language for simulating, optimizing and analyzing complex dynamic systems. OpenModelica is used in academic and industrial environments. Industrial applications include the use of OpenModelica along with proprietary software in the fields of power plant optimization, automotive and water treatment. Models are either built through line by line code or graphical code in OpenModelica. OpenModelica can interact with C, Python languages and can call C, Python functions from within its models. OpenModelica is a powerful tool that can be used to design and simulate complete control systems. + +Our project was to implement model based design i.e. creating models for different embedded applications and generating C code that can be ported to the respective family of microcontrollers.We also worked towards Improving the Hardware In Loop (HIL) implementation on OpenModelica and microcontrollers like arduino and TivaC.The current implementation which is based on Inter Process Communication (IPC) needs to be made robust. Hence there is a need to come up with a less cumbersome IPC for HIL. + + +\chapter{\textbf{Implementation}} +\section{Algorithm} +\begin{enumerate} +\item Once you have installed OpenModelica, launch OMEdit and open the OpenModelicaEmbedded package. +\item To use the above package you will also need to load Modelica\_DeviceDrivers package. The ‘synchronizeRealtime’ block present in this package is used to make the simulation of models real-time. All it does is that, it maps the time interval provided by you before simulation with clock your PC. +\item The components provided in this package are: +\begin{enumerate} +\item Pins: It contains Analog input, Analog output, Digital input, Digital output and Servo pins to perform corresponding function in model. +\item Boards: Any of the provided board can be used depending the one you are using, else use the ‘customBoard’ provided and vary it’s parameters to match the configuration of the development board you are using. +\end{enumerate} +\item Take a look at the examples provided along with the package to understand the basics structure of a model. Each model has ‘Board’ block which represents the development board used. This block when added to a model, on simulation calls a couple of functions present in ‘Internal > ExternalFunctions’ which set the initialisation parameters for communication like PORT, BAUD rate, etc. +\item These modelica functions present in ‘ExternalFunctions’ then call external C functions which perform the actual task the function is supposed to do. +\item These external C functions are bundled together and provided in the form of libraries. The Libraries used will be ‘*.dll’ in case of WindowsOS and ‘*.so’ in case of Linux. +\item After adding a board to your model add pins using blocks provided for the same. If you want to send some data from OpenModelica to connected microcontroller the use Analog/Digital Output Pin, and vice versa. Use Analog Pin while working with real data and Digital pin while working with Boolean. +\item These pin blocks again call functions in similar manner to either send or receive data. +\item Once your model is ready and check is successful, upload appropriate Firmware on microcontroller board connected. +\item The Firmware’s for Arduino and Tiva C borads have been provided along with the package. Open Arduino IDE if using Arduino board and Energia IDE if using Tiva C board and upload corresponding firmware on board. +\item The Firmware implements Firmata protocol to establish communication with OpenModelica. +\item Now go back to OpenModelica and simulate your model. +\end{enumerate} + +\section{Making changes in source code} +\subsection{How to make changes to source code and make libraries} +{\textbf {Linux Operating System}}\\ + +Open the source codes by browsing to this location : OpenModelicaEmbedded \textrightarrow Source.After making changes to the source code files open Terminal.Browse to OpenModelicaEmbedded \textrightarrow Source folder using ‘cd’ command.Run command ‘make’ to generate shared object file('*.so').\\ +\\ +{\textbf {Windows Operating System}}\\ + +Open the source codes by browsing to this location : OpenModelicaEmbedded \textrightarrow Source. After making changes to the source code, open Command Prompt (cmd).Browse to OpenModelicaEmbedded \textrightarrow Source folder using ‘cd’ command.To compile the CPP files run the command: g++ -c modelPlugFirmata.cpp serial.cpp. To create a DLL from generated object files, run the command: g++ -shared -o modelPlugFirmata.dll modelPlugFirmata.o serial.o.Then copy the generated DLL file and paste it in folders: OpenModelicaEmbedded and Resources \textrightarrow Library \textrightarrow win64.\\ + +\subsection{Working with Arduino UNO [Atmega328p]} + Setting up firmware for Arduino board\\ + In Tools Menu, select appropriate Board (Arduino/Genuino UNO) and Port as the available serial port to which Arduino is connected.\\ + Open pidmata3 sketch: File \textrightarrow Open \textrightarrow OpenModelicaEmbedded \textrightarrow Firmware \textrightarrow Arduino \textrightarrow pidmata3 \textrightarrow pidmata3.ino. + Upload the sketch to the board.\\ + +\textbf{Simulating the Modelica model}\\ +Now open OMEdit window.\\ +Open ‘package.mo’ file OpenModelicaEmbedded folder.\\ +In OpenModelicaEmbedded package, open ArduinoExamples’ package which consists of examples for arduino board. Check and simulate the example models and verify the results. + +\subsection{Working with Tiva C [TM4C123G]} +In Energia, open the firmware for Tiva C provided in folder through path : File \textrightarrow Open \textrightarrow OpenModelicaEmbedded \textrightarrow Firmware \textrightarrow Tiva C \textrightarrow StandardFirmata \textrightarrow \\ StandardFirmata.ino or add zip file of this StandardFirmata as an external library in Energia from the same folder.\\ +Select appropriate Board (Tiva C) and Port (USB port where Tiva C is connected) in Tools menu.\\ +Then, upload the firmware on board.\\ + +\textbf{Simulate a model with Tiva C.}\\ +Now open OMEdit and Open the package.mo file from OpenModelicaEmbedded package\\ +Open an example provided in the OpenModelicaEmbedded package which includes a Tiva C board.\\ +Check and Simulate the model and verify the results in Plotting window.\\ + +\chapter{\textbf{Download and Installation}} +\section{OpenModelica} +OpenModelica can be downloaded online from \url{https://openmodelica.org}.\\ +\\ +For Linux:\\ +The Debian/Ubuntu package for OpenModelica can be downloaded and installed by following the instructions on \url{https://openmodelica.org/download/download-linux}. OMEdit can be launched by typing OMEdit in the Terminal.\\ +\\ +For Windows:\\ +The setup for OpenModelica on Windows can be downloaded from \url{https://openmodelica.org/download/download-windows}. After downloading and installation of the software, OMEdit or OpenModelica Connection Editor can be launched by clicking on its icon or by navigating through Start menu. + +\section{Arduino IDE} +The open source Arduino Software is used to write codes and upload them to the board. For the setup of Arduino IDE for both Windows and Linux go to \url{https://www.arduino.cc/en/Main/Software} and follow the download and install instructions. + +\section{Energia IDE} +Energia is a Arduino-like coding environment designed for Texas Instruments Launchpads. The setup for Energia can be downloaded from \url{http://energia.nu/download/}. The instructions for installation can be referred from - \\ +For Linux: \url{http://energia.nu/guide/guide_linux/} +For Windows: \url{http://energia.nu/guide/guide_windows/} + + +\chapter{\textbf{About OpenModelicaEmbedded package}} + +OpenModelicaEmbedded package is designed to interact between embedded systems and OpenModelica models using C/C++ functions. This package can work for both Atmega series (tested for Arduino UNO - Atmega328p) and Texas Instruments Tiva C series (tested for Tiva C EK-TM4C123GXL Launchpad).\\ +\\ +The package can be downloaded from the following link:\\ +\url{https://github.com/manasdas17/OpenModelicaEmbedded}\\ +This library requires Modelica\_DeviceDrivers library as a supporting library which can be downloaded from the following link:\\ +\url{https://github.com/modelica/Modelica_DeviceDrivers} + +\begin{figure}[H] +\centering +\includegraphics[width =0.5 \textwidth]{package_str} +\caption{Structure of OpenModelicaEmbedded package} +\label{figure:1} +\end{figure} + +\section{SynchronizeRealTime Block} +This block is a part of Modelica\_DeviceDrivers library used for real-time simulation of the model, i.e., this block synchronizes simulation time of the process to real- time clock of the operating system. Without this block, the models designed using this package will not be able to give proper real-time output. This block works at five different priorty levels which can be changed in Parameters dialog box by double-clicking the block. + +\begin{figure}[H] +\centering +\includegraphics[width = 0.3\textwidth]{realtime} +\includegraphics[width = 0.65\textwidth]{realtimepara} +\caption{SymchronizeRealTime block} +\label{figure:2} +\end{figure} + +\section{Pins} +This package contains blocks which define to input and output pins of the board to which our hardware can be connected. These pin components define the properties and working of the pins used in the hardware.\\ + +\begin{itemize} +\item \textbf{AnalogInput:} It reads an analog signal from the specified pin. This component uses the function ‘analogRead’ of Arduino. It takes minimum and maximum values of the signal as parameter (default values being 0 and 1 respectively) and gives output depending on the size of ADC (analog to digital convertor) which is 10-bit for Arduino UNO board and 12-bit for Tiva C series TM4C123G board. +\begin{figure}[H] +\centering +\includegraphics[width = 0.4\textwidth]{pin11} +\includegraphics[width = 0.55\textwidth]{pin12} +\caption{AnalogInput block} +\label{figure:3} +\end{figure} +\item \textbf{AnalogOutput:} It writes analog value (PWM wave) to the specified pin. This component uses the function ‘analogWrite’ of Arduino. It takes minimum and maximum values of the signal as parameter (default values being 0 and 1 respectively) and gives output depending on the size of ADC. +\begin{figure}[H] +\centering +\includegraphics[width = 0.4\textwidth]{pin21} +\includegraphics[width = 0.55\textwidth]{pin22} +\caption{AnalogOutput block} +\label{figure:4} +\end{figure} +\item \textbf{DigitalInput:} It reads an digital signal from the specified pin. This component uses the function ‘digitalRead’ of Arduino. It only takes boolean signals. +\begin{figure}[H] +\centering +\includegraphics[width = 0.4\textwidth]{pin31} +\includegraphics[width = 0.55\textwidth]{pin32} +\caption{DigitalInput block} +\label{figure:5} +\end{figure} +\item \textbf{DigitalOutput:} It writes digital value to the specified pin. This component uses the function ‘digitalWrite’ of Arduino. It only takes boolean signals. +\begin{figure}[H] +\centering +\includegraphics[width = 0.4\textwidth]{pin41} +\includegraphics[width = 0.55\textwidth]{pin42} +\caption{DigitalOutput block} +\label{figure:6} +\end{figure} +\item \textbf{Servo:} It controls a servo motor attached to the specified pin. This component uses the 'Servo' library of Arduino. By default, the range goes from 0 to 1, which corresponds to 0 to 180 degrees. If you want to input values in degrees or radians, you can change the parameter 'InputUnit' to 'Degrees' or 'Radians'. +\begin{figure}[H] +\centering +\includegraphics[width = 0.4\textwidth]{pin51} +\includegraphics[width = 0.55\textwidth]{pin52} +\caption{Servo block} +\label{figure:7} +\end{figure} +\end{itemize} + +\section{Boards} +This package contains block components which enable connection with different firmata boards. These components take serial port used for connection as parameter. +\begin{itemize} +\item \textbf{Arduino:} Used for connecting to Arduino boards, such as Arduino UNO, Arduino Mega 2500 and others having similar firmata. +\begin{figure}[H] +\centering +\includegraphics[width =0.25 \textwidth]{board1} +\caption{Arduino block} +\label{figure:8} +\end{figure} +\item \textbf{ArduinoLeonardo:} Supports Arduino Leonardo board and other boards using native USB. +\begin{figure}[H] +\centering +\includegraphics[width =0.25 \textwidth]{board2} +\caption{ArduinoLeonardo block} +\label{figure:9} +\end{figure} +\item \textbf{StandardFirmata:} Connects to Arduino compatible boards. +\begin{figure}[H] +\centering +\includegraphics[width =0.25 \textwidth]{board3} +\caption{StandardFirmata block} +\label{figure:10} +\end{figure} +\item \textbf{CustomFirmata:} Supports any board firmata. +\begin{figure}[H] +\centering +\includegraphics[width =0.25 \textwidth]{board4} +\caption{CustomFirmata block} +\label{figure:11} +\end{figure} +\item \textbf{customBoard:} Takes name of the board also as parameter and can be used to connect any board supporting firmata. +\begin{figure}[H] +\centering +\includegraphics[width =0.25 \textwidth]{board5} +\caption{customBoard block} +\label{figure:12} +\end{figure} +\end{itemize} + +\section{Examples} +The package contains example models to get introduced to the working of components of the package. These models accomplish different tasks using different blocks provided in Pins and Boards package. + +\section{ArduinoExamples} +The package contains example models specifc to Arduino UNO board. It can be used for other Arduino boards by change Pin Number parameter for the Pin blocks. Detailed description for the package is given in 'Working with Arduino'. + +\section{TivaC\_Examples} +The package contains example models specifc to Tiva C Launchpad TM4C123G board. It can be used for other similar boards by change Pin Number parameter for the Pin blocks. Detailed description for the package is given in 'Working with Tiva C'. + +\section{Internal} +The components of this package cannot be used directly in the models. This package consists of icons and connectors defined and used for block designing, new types defined and used for the blocks and functions designed using external C/C++ functions at backend. + +\chapter{\textbf{Hardware In Loop Simulation}} +\tab Hardware-in-the-loop (HIL) simulation, or HWIL, is a technique that is used in the development and test of complex real-time embedded systems. HIL simulation provides an effective platform by adding the complexity of the plant under control to the test platform. The complexity of the plant under control is included in test and development by adding a mathematical representation of all related dynamic systems. These mathematical representations are referred to as the “plant simulation”. The embedded system to be tested interacts with this plant simulation.\\ + +A HIL simulation must include electrical emulation of sensors and actuators. These electrical emulations act as the interface between the plant simulation and the embedded system under test. The value of each electrically emulated sensor is controlled by the plant simulation and is read by the embedded system under test (feedback). Likewise, the embedded system under test implements its control algorithms by outputting actuator control signals. Changes in the control signals result in changes to variable values in the plant simulation. + +\section{Implementation} +\tab The package developed (OpenModelicaEmbedded) has several components like micro-controller boards, Digital/Analog Pins, etc. which you will have to use in your model to make it interact with connected hardware device. These components make calls to external C functions present in the library provided in Library directory. Those functions using serial communication communicate with the connected device. This source file will remain same irrespective of the connected hardware device and platform used (Windows, Linux, Mac).\\ + +The connected hardware device uses Firmata protocol to communicate with OpenModelica. The source code implementing Firmata protocol on hardware will vary depending on the language/ IDE used by that hardware/microcontroller, but the underlying protocol remains the same. + +\chapter{\textbf{PID Controller}} +A \textbf{proportional - integral - derivative controller} (\textbf{PID controller} or \textbf{three term controller}) is a control loop feedback mechanism widely used in industrial control systems and a variety of other applications requiring continuously modulated control. A PID controller continuously calculates an error value e(t) as the difference between a desired setpoint (SP) and a measured process variable (PV) and applies a correction based on proportional, integral, and derivative terms (denoted P, I, and D respectively) which give the controller its name. + +\section{Implementation} +The PID is implemented in the Firmware present on the hardware device using ‘AutoPID’ Library. To use the hardware for PID you will have to change the Firmware (Arduino source code) a bit by following the instructions mentioned in the Firmware itself. The only thing you have to do is just comment/uncomment a few macros depending on your application. + +\begin{figure}[H] +\centering +\includegraphics[width =0.9\textwidth]{pid} +\caption{Firmata to work with PID Controller} +\label{figure:24} +\end{figure} + +\section{Example for PID} +\textbf{Example:} DCMotorWithPID (from Examples package) +\begin{figure}[H] +\centering +\includegraphics[width =0.9\textwidth]{pid_ex} +\caption{Model for PID Controller with DC Motor} +\label{figure:25} +\end{figure} +\begin{figure}[H] +\centering +\includegraphics[width = 0.9\textwidth]{pid_graph} +\caption{Plot for PID Controller with DC Motor} +\label{figure:26} +\end{figure} + +\chapter{\textbf{Working with Arduino UNO}} +The Arduino UNO is a widely used microcontroller board based of ATmega328P microcontroller IC and is developed by Arduino.cc. It operates at a voltage of 5V. The board contains 14 Digital and 6 Analog input/output (I/O) pins, a 10-bit ADC (Analog to Digital Convertor), 8-bit DAC, a in-built LED connected to digital pin no. 13 and many other features. + +\begin{figure}[H] +\centering +\includegraphics[width =0.75 \textwidth]{arduino_uno_pinout} +\caption{Pin Diagram of Arduino UNO} +\label{figure:13} +\end{figure} + +\section{Connecting and Configuring the Board} +\begin{enumerate} +\item Connect the Arduino UNO board to the computer using a USB cable. +\item Open Arduino IDE. +\item In Tools Menu, select Board \textrightarrow Arduino/Genuino UNO and Port as the available serial port to which Arduino is connected. +\item The serial port can be identified by:\\ +For Linux:\\ +Type the command \textbf{ls -l /dev/ttyACM*} in the terminal and the output it returns gives the port to which Arduino is connected, for example \textbf{/dev/ttyACM0}.\\ +For Windows:\\ +Open \textbf{Device Manager} and check for the name of connected port which will be in the form, for example, \textbf{COM5}. +\item Click Sketch \textrightarrow Include libraries and select Manage libraries, type AutoPID in the search bar and install the library. +\item Click File \textrightarrow Open and browse OpenModelicaEmbedded \textrightarrow Firmware \textrightarrow Arduino \textrightarrow pidmata3 and open pidmata3.ino.\\ +OR\\ +Open StandardFirmata sketch: File \textrightarrow Examples \textrightarrow StandardFirmata , if not working with PID.\\ +\item Upload the sketch to the board. +\end{enumerate} + +\section{Interfacing with OpenModelica} +\begin{enumerate} +\item Upload StandardFirmata sketch to the Arduino board. +\item Open package.mo from OpenModelicaEmbedded package, also open package.mo file from Modelica\_DeviceDrivers library. +\item In OpenModelicaEmbedded package, open ArduinoExamples package. +\item In Diagram view, change the port name for the board component to the port to which board is connected by double-clicking on it. +\item Simulate the example model. +\end{enumerate} + +\section{Examples for Arduino} +ArduinoExamples package consists of example models designed for specificly to work with Arduino UNO board. In order to work with these examples, double-click of board block in the Diagram view and change port name to the port to which board is connected. If working with any other similar Arduino board, double-click the pin blocks and change pin number as per the used board. + +\subsection{LED Examples} +\textbf{Example:} arduino\_ex1\_led\_blue\\ + +The following is an example to turn on the blue led indefinitely. Double clicking each block opens the parameter window for it. Change the parameters according to the following image. + +\begin{figure}[H] +\begin{subfigure}{.5\textwidth} +\centering +\includegraphics[width =\linewidth]{1} +\caption{Connections for lighting up blue led} +\end{subfigure} +\begin{subfigure}{.5\textwidth} +\centering +\includegraphics[width =\linewidth]{led_ex1} +\caption{Model for lighting up blue led} +\end{subfigure} +\caption {Arduino Led Example} +\label{figure:14} +\end{figure} + +\subsection{Push Button Examples} +\textbf{Example:} arduino\_ex1\_push\_button\_status\\ + +The following example is to read the status of the pushbutton and display it on the serial monitor.\\ + +In this model, a BooleanValue block is used to show boolean value coming from the digital input pin of arduino on Simulation Output. The block BooleanValue can be found at Modelica.Blocks.Interaction.Show.BooleanValue.\\ + +Moreover, a print statement to print boolean value is written in the Text view of the model which can be seen in ~\ref{figure:23}.\\ + +Double clicking each block opens the parameter window for it. Change the parameters according to the following image. + +\begin{figure}[H] +\begin{subfigure}{.5\textwidth} +\centering +\includegraphics[width =\linewidth]{2} +\caption{Connections for push button} +\end{subfigure} +\begin{subfigure}{.5\textwidth} +\centering +\includegraphics[width =\linewidth]{pb_ex1} +\caption{Model for checking status of push button} +\end{subfigure} +\caption {Arduino Push Button Example} +\label{figure:15} +\end{figure} + +\begin{figure}[H] +\centering +\includegraphics[width =\textwidth]{pb_ex1_print} +\caption{Print Statement} +\label{figure:23} +\end{figure} + + +\subsection{LDR Examples} +\textbf{Example:} arduino\_ex2\_ldr\_read\\ + +Turning the blue LED on and off according to the values of LDR (Light Dependent Resistor).\\ + +In this model, 2 blocks have been used namely Less and Constant.\\ + +Less block takes 2 input and gives 1 output according to the values of input. For example in the case below, when value from pin 19 is less than k = 300, output is true (or 1) and when value from pin 19 is greater than equal to k=300, its output is false (or 0). The block can be found at Modelica.Blocks.Logical.Less.\\ + +Constant block provides with a constant value which can be set by user. The block can be found at Modelica.Blocks.Sources.Constant. + +\begin{figure}[H] +\begin{subfigure}{.5\textwidth} +\centering +\includegraphics[width =\linewidth]{3} +\caption{Connections for ldr} +\end{subfigure} +\begin{subfigure}{.5\textwidth} +\centering +\includegraphics[width =\linewidth]{ldr_ex2} +\caption{Model for switching led depending on ldr value} +\end{subfigure} +\caption {Arduino LDR Example} +\label{figure:16} +\end{figure} + +\subsection{DC Motor Examples} +\textbf{Example:} arduino\_ex2\_dcmotor\_both\\ + +The following example is of rotating the DC motor in both directions. As visible in the model below, 2 pulse blocks are used to manage this. \\ + +A pulse block generates pulse signals of real value. It’s amplitude, duty cycle, time period, start time can be varied through changing amplitude, width, period, startTime respectively in the parameter window of the pulse. The block can be found at Modelica.Blocks.Sources.Pulse.\\ + +Double clicking each block opens the parameter window for it. Change the parameters according to the following image. + +\begin{figure}[H] +\begin{subfigure}{.75\textwidth} +\centering +\includegraphics[width =\linewidth]{4} +\caption{Connections for dc motor} +\end{subfigure} +\begin{subfigure}{\textwidth} +\centering +\includegraphics[width =0.3\linewidth]{dc_ex2} +\includegraphics[width =0.3\linewidth]{dc_ex2_2} +\includegraphics[width =0.3\linewidth]{dc_ex2_3} +\caption{Model for rotating dc motor in both directions} +\end{subfigure} +\caption {Arduino DC Motor Example} +\label{figure:17} +\end{figure} + +\subsection{Potentiometer Examples} +\textbf{Example:} arduino\_ex1\_pot\_threshold\\ + +The following example is of turning on LEDs depending on the potentiometer threshold. As seen in the model below, we’ve used Xor and GreaterEqualThreshold blocks. \\ + +The GreaterEqualThreshold block has a parameter-threshold; if the input value to the block is greater than or equal to this threshold then the output is the same as input, otherwise 0.\\ + +This block can be found at Modelica.Blocks.Logical.GreaterEqualThreshold.\\ + +The other one is Xor block which simply xor’s ihe 2 input values it gets. This block can be found at Modelica.Blocks.Logical.Xor. + +\begin{figure}[H] +\begin{subfigure}{.5\textwidth} +\centering +\includegraphics[width =\linewidth]{5} +\caption{Connections for potentiometer} +\end{subfigure} +\begin{subfigure}{.5\textwidth} +\centering +\includegraphics[width =\linewidth]{potentio_ex1} +\caption{Model for potentiometer threshold ranges} +\end{subfigure} +\caption {Arduino Potentiometer Example} +\label{figure:18} +\end{figure} + +\subsection{Thermistor Examples} +\textbf{Example:} arduino\_ex1\_therm\_read\\ + +Turning the buzzer on and off using the thermistor values read by ADC. \\ + +It’s model has Greater block. Greater block takes 2 input and gives 1 output according to the values of input. For example in the case below, when value from pin 18 is greater than k = 500, output is true(or 1) and when value from pin 18 is less than equal to k=500, its output is false(or 0). The block can be found at Modelica.Blocks.Logical.Greater. + +\begin{figure}[H] +\begin{subfigure}{.5\textwidth} +\centering +\includegraphics[width =\linewidth]{6} +\caption{Connections for thermistor} +\end{subfigure} +\begin{subfigure}{.5\textwidth} +\centering +\includegraphics[width =\linewidth]{thermistor_ex1} +\caption{Model for checking value of thermistor} +\end{subfigure} +\caption {Arduino Thermistor Example} +\label{figure:19} +\end{figure} + +\subsection{Servo Motor Examples} +\textbf{Example:} arduino\_ex3\_servo\_loop\\ + +Rotating the servo in increments. \\ + +The model contains blocks like Product, RealToInteger, IntegerToReal, Constant and Ramp. The Ramp block gives a strictly increasing value. On using RealToInteger block on the output, it converts it to step function. Now as the Product block accepts 2 input in real format only, there was a need to convert the value back to real using IntegerToReal block.\\ + +In Servo pin, set InputUnit to OpenModelicaEmbedded.Internal.Types.ServoUnit.None. \\ + +As can be seen from data sheet (Figure:~\ref{figure:27}) SG90 has a duty cycle of 5-10\% where if it is 5\%, the position of motor is -90 degrees and if 10\%, it is +90 degrees. So as we were simulating for 10 seconds, MinPulse was 0.5 sec and MaxPulse was 1sec in Servo pin Parameters. + +\begin{figure}[H] +\centering +\includegraphics[width =\textwidth]{servo_datasheet} +\caption{Data Sheet for Servo Motor SG90} +\label{figure:27} +\end{figure} + +\begin{figure}[H] +\begin{subfigure}{.5\textwidth} +\centering +\includegraphics[width =\linewidth]{7} +\caption{Connections for Servo Motor} +\end{subfigure} +\begin{subfigure}{.5\textwidth} +\centering +\includegraphics[width =\linewidth]{servo_ex3} +\caption{Model for working with Servo Motor} +\end{subfigure} +\caption {Arduino Servo Motor Example} +\label{figure:20} +\end{figure} + +\chapter{\textbf{Working with Tiva C Launchpad}} +The Tiva C series Launchpad Evaluation board (EK-TM4C123GXL) is low cost ARM-Cortex-M4F based microcontroller. The board contains 40 I/O pins, two user programmable push buttons, a RGB led and many more features. + +\begin{figure}[H] +\centering +\includegraphics[width =\textwidth]{tiva_c_launchpad_pinout} +\caption{Pin Diagram of Tiva C Launchpad} +\label{figure:21} +\end{figure} + +\section{Connecting and Configuring the Board} +\begin{enumerate} +\item Connect the Tiva C board to the computer using a USB cable. +\item Open Energia IDE. +\item In Tools Menu, select Board \textrightarrow Tiva C and Port as the available serial port to which Arduino is connected. +\item If Tiva C board is not present, then click on Board Manager, type Tiva C in search bar and then click on Install to install board library, then apply Step 3. +\item In Sketch menu, Select Include Library \textrightarrow Add .zip library and add the zip file provided in the Firmware folder. Then open StandardFirmata sketch: File \textrightarrow Examples \textrightarrow StandardFirmata.\\ +OR\\ +Click File \textrightarrow Open and browse OpenModelicaEmbedded \textrightarrow Firmware \textrightarrow Tiva C \textrightarrow StandardFirmata and open StandardFiramata.ino. +\item Upload the sketch to the board. +\end{enumerate} + +\section{Interfacing with OpenModelica} +\begin{enumerate} +\item Upload StandardFirmata sketch to the Tiva C board. +\item Open package.mo from OpenModelicaEmbedded package, also open package.mo file from Modelica\_DeviceDrivers library. +\item In OpenModelicaEmbedded library, open TivaC\_Examples package. +\item In Diagram view, change the port name for the board component to the port to which board is connected by double-clicking on it. +\item Simulate the example model. +\end{enumerate} + +\section{Examples for Tiva C} +The examples explained in package for tiva-c are same as that for arduino board except that the pin configurations are different. The configuration can be seen from the pin diagram from Figure~\ref{figure:21}.\\ + +\textbf{Example:} tivac\_ex1\_led\_blue +\begin{figure}[H] +\centering +\includegraphics[width =0.75\textwidth]{tiva_led} +\caption{Tiva C Led Example} +\label{figure:22} +\end{figure} +The example Tiva-C Led works same as the one which is explained for arduino except for the fact that the pin configuration has been changed,for arduino it was pin number 9 while for tiva-c board it is pin number 40 as can be reffered from the pin diagram of tiva-c board (Figure: ~\ref{figure:21}). All other working remains same as already explained in case of Arduino.\\ + +For all other models also only pin number changes in case of Arduino rest they are similar to those present in ArduinoExamples package. + +\chapter{\textbf{Conclusion}} +\tab The project "Interfacing of Embedded Systems with OpenModelica", is based on implementing an example package for Arduino board as well as for tiva-C board.We implemented the same set of examples on both Arduino board as well as Tiva-c board because Tiva-c board targets industries.We implemented hardware in loop simulation and PID tuning was done. Indeed the same set of codes can be used for linux as well as for windows plateform. We also explored the embedded targets package of the Modelica\_DeviceDrivers library.\\ + +Although, there were many issues initially, most of them got resolved in the course of the project. While working on the project with OpenModelica we came to a conclusion that OpenModelica is an open source software based on Modelica language to design and simulate complex physical systems through code as well as graphical blocks which is also very useful for electronics prototyping and real time simulations. The main drawback of the library is its lack of appropriate documentation and various other hardware supports in the electronics hardware area. Such modules are open for modifications and can be extended by future developers. Therefore we have explored OpenModelica in detail and tried to provide a better insight in this open source software which will help developers in the future. + +\newpage +\title{\textbf{\textbf{\LARGE +\begin{flushleft} +\textbf{Reference} +\end{flushleft} +}}} +The following sources were referred to while working on this project: +\begin{itemize} +\item Peter Fritzson :Principles of Object-Oriented Modeling and Simulation with Modelica 3.3: A Cyber-Physical Approach +\item \url{ https://www.openmodelica.org/} +\item \url{ http://book.xogeny.com/} +\item \url{ https://build.openmodelica.org/Documentation/Modelica.html} +\item \url{ https://www.codeproject.com/Articles/84461/MinGW-Static-and-Dynamic-Libraries} +\item \url{https://stackoverflow.com/questions/10039401/use-32bit-shared-library-from-64bit-application} +\item \url{ https://stackoverflow.com/questions/142508/how-do-i-check-os-with-a-preprocessor-directive} +\item \url{https://en.wikipedia.org/wiki/PID_controller} +\item \url { https://openmodelica.org/doc/OpenModelicaUsersGuide/latest/interop_c_python.html} +\end{itemize} + +\end{document} + + diff --git a/Report/Final.toc b/Report/Final.toc new file mode 100644 index 0000000..bb465e8 --- /dev/null +++ b/Report/Final.toc @@ -0,0 +1,40 @@ +\contentsline {chapter}{\numberline {1}\textbf {Introduction}}{4}{chapter.1} +\contentsline {chapter}{\numberline {2}\textbf {Implementation}}{5}{chapter.2} +\contentsline {section}{\numberline {2.1}Algorithm}{5}{section.2.1} +\contentsline {section}{\numberline {2.2}Making changes in source code}{6}{section.2.2} +\contentsline {subsection}{\numberline {2.2.1}How to make changes to source code and make libraries}{6}{subsection.2.2.1} +\contentsline {subsection}{\numberline {2.2.2}Working with Arduino UNO [Atmega328p]}{6}{subsection.2.2.2} +\contentsline {subsection}{\numberline {2.2.3}Working with Tiva C [TM4C123G]}{7}{subsection.2.2.3} +\contentsline {chapter}{\numberline {3}\textbf {Download and Installation}}{8}{chapter.3} +\contentsline {section}{\numberline {3.1}OpenModelica}{8}{section.3.1} +\contentsline {section}{\numberline {3.2}Arduino IDE}{8}{section.3.2} +\contentsline {section}{\numberline {3.3}Energia IDE}{8}{section.3.3} +\contentsline {chapter}{\numberline {4}\textbf {About OpenModelicaEmbedded package}}{9}{chapter.4} +\contentsline {section}{\numberline {4.1}SynchronizeRealTime Block}{9}{section.4.1} +\contentsline {section}{\numberline {4.2}Pins}{10}{section.4.2} +\contentsline {section}{\numberline {4.3}Boards}{13}{section.4.3} +\contentsline {section}{\numberline {4.4}Examples}{14}{section.4.4} +\contentsline {section}{\numberline {4.5}ArduinoExamples}{14}{section.4.5} +\contentsline {section}{\numberline {4.6}TivaC\_Examples}{15}{section.4.6} +\contentsline {section}{\numberline {4.7}Internal}{15}{section.4.7} +\contentsline {chapter}{\numberline {5}\textbf {Hardware In Loop Simulation}}{16}{chapter.5} +\contentsline {section}{\numberline {5.1}Implementation}{16}{section.5.1} +\contentsline {chapter}{\numberline {6}\textbf {PID Controller}}{17}{chapter.6} +\contentsline {section}{\numberline {6.1}Implementation}{17}{section.6.1} +\contentsline {section}{\numberline {6.2}Example for PID}{18}{section.6.2} +\contentsline {chapter}{\numberline {7}\textbf {Working with Arduino UNO}}{19}{chapter.7} +\contentsline {section}{\numberline {7.1}Connecting and Configuring the Board}{20}{section.7.1} +\contentsline {section}{\numberline {7.2}Interfacing with OpenModelica}{20}{section.7.2} +\contentsline {section}{\numberline {7.3}Examples for Arduino}{20}{section.7.3} +\contentsline {subsection}{\numberline {7.3.1}LED Examples}{21}{subsection.7.3.1} +\contentsline {subsection}{\numberline {7.3.2}Push Button Examples}{21}{subsection.7.3.2} +\contentsline {subsection}{\numberline {7.3.3}LDR Examples}{22}{subsection.7.3.3} +\contentsline {subsection}{\numberline {7.3.4}DC Motor Examples}{23}{subsection.7.3.4} +\contentsline {subsection}{\numberline {7.3.5}Potentiometer Examples}{24}{subsection.7.3.5} +\contentsline {subsection}{\numberline {7.3.6}Thermistor Examples}{25}{subsection.7.3.6} +\contentsline {subsection}{\numberline {7.3.7}Servo Motor Examples}{26}{subsection.7.3.7} +\contentsline {chapter}{\numberline {8}\textbf {Working with Tiva C Launchpad}}{28}{chapter.8} +\contentsline {section}{\numberline {8.1}Connecting and Configuring the Board}{28}{section.8.1} +\contentsline {section}{\numberline {8.2}Interfacing with OpenModelica}{29}{section.8.2} +\contentsline {section}{\numberline {8.3}Examples for Tiva C}{29}{section.8.3} +\contentsline {chapter}{\numberline {9}\textbf {Conclusion}}{31}{chapter.9} diff --git a/Report/arduino_uno_pinout.png b/Report/arduino_uno_pinout.png Binary files differnew file mode 100644 index 0000000..dd8bf2f --- /dev/null +++ b/Report/arduino_uno_pinout.png diff --git a/Report/board1.PNG b/Report/board1.PNG Binary files differnew file mode 100644 index 0000000..35dfc72 --- /dev/null +++ b/Report/board1.PNG diff --git a/Report/board2.PNG b/Report/board2.PNG Binary files differnew file mode 100644 index 0000000..44b56a2 --- /dev/null +++ b/Report/board2.PNG diff --git a/Report/board3.PNG b/Report/board3.PNG Binary files differnew file mode 100644 index 0000000..2d2e7f5 --- /dev/null +++ b/Report/board3.PNG diff --git a/Report/board4.PNG b/Report/board4.PNG Binary files differnew file mode 100644 index 0000000..85654e8 --- /dev/null +++ b/Report/board4.PNG diff --git a/Report/board5.PNG b/Report/board5.PNG Binary files differnew file mode 100644 index 0000000..373221f --- /dev/null +++ b/Report/board5.PNG diff --git a/Report/dc_ex2.PNG b/Report/dc_ex2.PNG Binary files differnew file mode 100644 index 0000000..6a679eb --- /dev/null +++ b/Report/dc_ex2.PNG diff --git a/Report/dc_ex2_2.PNG b/Report/dc_ex2_2.PNG Binary files differnew file mode 100644 index 0000000..3dabc77 --- /dev/null +++ b/Report/dc_ex2_2.PNG diff --git a/Report/dc_ex2_3.PNG b/Report/dc_ex2_3.PNG Binary files differnew file mode 100644 index 0000000..0e2bd48 --- /dev/null +++ b/Report/dc_ex2_3.PNG diff --git a/Report/fossee-logo.png b/Report/fossee-logo.png Binary files differnew file mode 100644 index 0000000..6feda2d --- /dev/null +++ b/Report/fossee-logo.png diff --git a/Report/iit.png b/Report/iit.png Binary files differnew file mode 100644 index 0000000..15b0bf6 --- /dev/null +++ b/Report/iit.png diff --git a/Report/ldr_ex1.PNG b/Report/ldr_ex1.PNG Binary files differnew file mode 100644 index 0000000..868b758 --- /dev/null +++ b/Report/ldr_ex1.PNG diff --git a/Report/ldr_ex2.PNG b/Report/ldr_ex2.PNG Binary files differnew file mode 100644 index 0000000..98e1810 --- /dev/null +++ b/Report/ldr_ex2.PNG diff --git a/Report/led_ex1.PNG b/Report/led_ex1.PNG Binary files differnew file mode 100644 index 0000000..5b68afa --- /dev/null +++ b/Report/led_ex1.PNG diff --git a/Report/package_str.PNG b/Report/package_str.PNG Binary files differnew file mode 100644 index 0000000..815ad3b --- /dev/null +++ b/Report/package_str.PNG diff --git a/Report/pb_ex1.PNG b/Report/pb_ex1.PNG Binary files differnew file mode 100644 index 0000000..6622f48 --- /dev/null +++ b/Report/pb_ex1.PNG diff --git a/Report/pb_ex1_print.PNG b/Report/pb_ex1_print.PNG Binary files differnew file mode 100644 index 0000000..c6681e0 --- /dev/null +++ b/Report/pb_ex1_print.PNG diff --git a/Report/pid.png b/Report/pid.png Binary files differnew file mode 100644 index 0000000..9dec9b0 --- /dev/null +++ b/Report/pid.png diff --git a/Report/pid_ex.PNG b/Report/pid_ex.PNG Binary files differnew file mode 100644 index 0000000..9851a5f --- /dev/null +++ b/Report/pid_ex.PNG diff --git a/Report/pid_graph.PNG b/Report/pid_graph.PNG Binary files differnew file mode 100644 index 0000000..59c4938 --- /dev/null +++ b/Report/pid_graph.PNG diff --git a/Report/pin11.PNG b/Report/pin11.PNG Binary files differnew file mode 100644 index 0000000..1ad4831 --- /dev/null +++ b/Report/pin11.PNG diff --git a/Report/pin12.PNG b/Report/pin12.PNG Binary files differnew file mode 100644 index 0000000..454d38f --- /dev/null +++ b/Report/pin12.PNG diff --git a/Report/pin21.PNG b/Report/pin21.PNG Binary files differnew file mode 100644 index 0000000..24cd388 --- /dev/null +++ b/Report/pin21.PNG diff --git a/Report/pin22.PNG b/Report/pin22.PNG Binary files differnew file mode 100644 index 0000000..0fc26d8 --- /dev/null +++ b/Report/pin22.PNG diff --git a/Report/pin31.PNG b/Report/pin31.PNG Binary files differnew file mode 100644 index 0000000..1fdc019 --- /dev/null +++ b/Report/pin31.PNG diff --git a/Report/pin32.PNG b/Report/pin32.PNG Binary files differnew file mode 100644 index 0000000..27af782 --- /dev/null +++ b/Report/pin32.PNG diff --git a/Report/pin41.PNG b/Report/pin41.PNG Binary files differnew file mode 100644 index 0000000..ca1c573 --- /dev/null +++ b/Report/pin41.PNG diff --git a/Report/pin42.PNG b/Report/pin42.PNG Binary files differnew file mode 100644 index 0000000..1fa0997 --- /dev/null +++ b/Report/pin42.PNG diff --git a/Report/pin51.PNG b/Report/pin51.PNG Binary files differnew file mode 100644 index 0000000..fbb20d3 --- /dev/null +++ b/Report/pin51.PNG diff --git a/Report/pin52.PNG b/Report/pin52.PNG Binary files differnew file mode 100644 index 0000000..f578875 --- /dev/null +++ b/Report/pin52.PNG diff --git a/Report/potentio_ex1.PNG b/Report/potentio_ex1.PNG Binary files differnew file mode 100644 index 0000000..8838ff8 --- /dev/null +++ b/Report/potentio_ex1.PNG diff --git a/Report/realtime.PNG b/Report/realtime.PNG Binary files differnew file mode 100644 index 0000000..515cee5 --- /dev/null +++ b/Report/realtime.PNG diff --git a/Report/realtimepara.PNG b/Report/realtimepara.PNG Binary files differnew file mode 100644 index 0000000..54d8b64 --- /dev/null +++ b/Report/realtimepara.PNG diff --git a/Report/servo_datasheet.PNG b/Report/servo_datasheet.PNG Binary files differnew file mode 100644 index 0000000..a3d3b74 --- /dev/null +++ b/Report/servo_datasheet.PNG diff --git a/Report/servo_ex3.PNG b/Report/servo_ex3.PNG Binary files differnew file mode 100644 index 0000000..7e59d95 --- /dev/null +++ b/Report/servo_ex3.PNG diff --git a/Report/thermistor_ex1.PNG b/Report/thermistor_ex1.PNG Binary files differnew file mode 100644 index 0000000..e9a7066 --- /dev/null +++ b/Report/thermistor_ex1.PNG diff --git a/Report/tiva_c_launchpad_pinout.png b/Report/tiva_c_launchpad_pinout.png Binary files differnew file mode 100644 index 0000000..947fb60 --- /dev/null +++ b/Report/tiva_c_launchpad_pinout.png diff --git a/Report/tiva_c_launchpad_pinout_001b.jpg b/Report/tiva_c_launchpad_pinout_001b.jpg Binary files differnew file mode 100644 index 0000000..4c12430 --- /dev/null +++ b/Report/tiva_c_launchpad_pinout_001b.jpg diff --git a/Report/tiva_led.PNG b/Report/tiva_led.PNG Binary files differnew file mode 100644 index 0000000..6f0d8e3 --- /dev/null +++ b/Report/tiva_led.PNG |