You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p>This is an assessed Exercise. When you have completed the <debugHL><ahref="#PiEncEx">Assessed Exercise</a></debugHL>, you should show your work to a <abbrtitle="Graduate Teaching Assistant">GTA</abbr> to get marked.</p>
925
+
<p>This is an assessed Exercise. When you have completed the <debughl><ahref="#PiEncEx">Assessed Exercise</a></debughl>, you should show your work to a <abbrtitle="Graduate Teaching Assistant">GTA</abbr> to get marked.</p>
926
926
</div>
927
927
<divclass="admonition note">
928
928
<pclass="admonition-title">Before Continuing</p>
929
-
<p>Before starting these exercises, you should ensure that you have completed all the <debugHL><ahref="../../BasicExercises/">Basic Exercises</a></debugHL> and have fully constructed the robot chassis, as described in the <debugHL><ahref="../../RobotBuild/">Building the Robot</a></debugHL> document.</p>
929
+
<p>Before starting these exercises, you should ensure that you have completed all the <debughl><ahref="../../BasicExercises/">Basic Exercises</a></debughl> and have fully constructed the robot chassis, as described in the <debughl><ahref="../../RobotBuild/">Building the Robot</a></debughl> document.</p>
930
930
</div>
931
931
<h2id="introduction">Introduction</h2>
932
932
<p>During this exercise you will write a program to move the robot chassis forwards and backwards through a sequence of set distances. The robot must be controlled in closed loop, using a <abbrtitle="Proportional and Integral Controller">PI</abbr> controller, and using the motor encoder as the feedback sensor.</p>
933
933
<p>Your code should use a simple finite state machine to control the sequences of operation.</p>
934
934
<p>The following video is a quick demonstration of the final outcome from this exercise:</p>
<figcaption>Video demonstrating the expected outcome from this exercise</figcaption>
940
940
</figure>
941
941
942
942
<h3id="a-simple-finite-state-machine">A Simple Finite State Machine</h3>
943
943
<p>In simple terms, finite state machines are a design methodology for designing and implementing a program to a system that is triggered by events that occur. We will only consider their use in the most simple form. </p>
944
944
<p>A simple state machine can define the operation of a system in terms of the “states” of the system and the triggers, (or events), that decide when to transition between one state and another: “state transition conditions”. The system can only transition from one state and another when state transition conditions are satisfied</p>
945
-
<p>Let us consider a very simple system: a system consisting of a light bulb and an on/off switch. The light can only be on or off, therefore we can define two-states to describe this behaviour. The state transition condition to transition between state 1, (on), to state 2, (off), is for the switch to be moved to the off position. Similarly, to transition from state 2 to state 1, the switch must be moved to the on position. This operation is summarised on the state transition diagram, shown in <debugHL><ahref="#onOffStateMachine">Fig. 2</a></debugHL>:</p>
945
+
<p>Let us consider a very simple system: a system consisting of a light bulb and an on/off switch. The light can only be on or off, therefore we can define two-states to describe this behaviour. The state transition condition to transition between state 1, (on), to state 2, (off), is for the switch to be moved to the off position. Similarly, to transition from state 2 to state 1, the switch must be moved to the on position. This operation is summarised on the state transition diagram, shown in <debughl><ahref="#onOffStateMachine">Fig. 2</a></debughl>:</p>
946
946
<figure>
947
947
<aname="onOffStateMachine"></a>
948
-
<aclass="glightbox" href="../../Images/OnOffStateMachine.png" data-type="image" data-width="auto" data-height="auto" data-desc-position="bottom"><imgalt="A state transition diagram for the on/off light bulb/switch system." src="../../Images/OnOffStateMachine.png"/></a>
948
+
<aclass="glightbox" href="../../Images/OnOffStateMachine.png" data-type="image" data-width="auto" data-height="auto" data-desc-position="bottom"><imgalt="A state transition diagram for the on/off light bulb/switch system." src="../../Images/OnOffStateMachine.png"></a>
949
949
<figcaption>A state transition diagram for the on/off light bulb/switch system.</figcaption>
950
950
</figure>
951
-
<p>This is a very simple state machine example for a 2 state system. We can extend this idea to a system which varies the light level output between: off, dimmed, medium and bright, with state transitions defined by two buttons: on and off. <aname="lightDimmer"></a>When the system starts, the system automatically switches to state 1: off. The on button is used to switch the light on and toggle the system states between states 2, 3 and 4, to adjust the brightness, whereas if the off button is pressed, the system will always return to the off state. This operation is summarised on the state transition diagram, <debugHL><ahref="#dimmerStateMachine">Fig. 3</a></debugHL>:</p>
951
+
<p>This is a very simple state machine example for a 2 state system. We can extend this idea to a system which varies the light level output between: off, dimmed, medium and bright, with state transitions defined by two buttons: on and off. <aname="lightDimmer"></a>When the system starts, the system automatically switches to state 1: off. The on button is used to switch the light on and toggle the system states between states 2, 3 and 4, to adjust the brightness, whereas if the off button is pressed, the system will always return to the off state. This operation is summarised on the state transition diagram, <debughl><ahref="#dimmerStateMachine">Fig. 3</a></debughl>:</p>
952
952
<figure>
953
953
<aname="dimmerStateMachine"></a>
954
-
<aclass="glightbox" href="../../Images/DimmerState.png" data-type="image" data-width="auto" data-height="auto" data-desc-position="bottom"><imgalt="A state transition diagram for the light dimmer system." src="../../Images/DimmerState.png"/></a>
954
+
<aclass="glightbox" href="../../Images/DimmerState.png" data-type="image" data-width="auto" data-height="auto" data-desc-position="bottom"><imgalt="A state transition diagram for the light dimmer system." src="../../Images/DimmerState.png"></a>
955
955
<figcaption>A state transition diagram for the light dimmer system.</figcaption>
956
956
</figure>
957
-
<p>To implement the <debugHL><ahref="#lightDimmer">light dimmer system state machine</a></debugHL>, we can use a <code>switch</code> statement, where each <code>case</code> statement defines the state behaviour of the system, such that:</p>
957
+
<p>To implement the <debughl><ahref="#lightDimmer">light dimmer system state machine</a></debughl>, we can use a <code>switch</code> statement, where each <code>case</code> statement defines the state behaviour of the system, such that:</p>
958
958
<divclass="language-Arduino highlight"><spanclass="filename">Arduino code describing the light dimmer system state machine</span><pre><span></span><code><spanid="__span-0-1"><aid="__codelineno-0-1" name="__codelineno-0-1" href="#__codelineno-0-1"></a><spanclass="cp">#define onPin 1 </span><spanclass="c1">// On button pin</span>
959
959
</span><spanid="__span-0-2"><aid="__codelineno-0-2" name="__codelineno-0-2" href="#__codelineno-0-2"></a><spanclass="cp">#define offPin 2 </span><spanclass="c1">// Of button pin</span>
960
960
</span><spanid="__span-0-3"><aid="__codelineno-0-3" name="__codelineno-0-3" href="#__codelineno-0-3"></a><spanclass="cp">#define outputPin 13 </span><spanclass="c1">// LED output Pin</span>
<p><problemHL>The state transition conditions are </problemHL></p>
1052
+
<p><problemhl>The state transition conditions are </problemhl></p>
1053
1053
<p>The system states are a position demand reference value for the <abbrtitle="Proportional and Integral Controller">PI</abbr> controller. Process the position controller within the case statements.</p>
1054
1054
<p>The sampling time for the <abbrtitle="Proportional and Integral Controller">PI</abbr> controller should be set to 10ms.</p>
1055
1055
<p>We recommend using the following controller gains: Kp = 4.0, Ki = 0.0. These controller values should give an oscillatory response.</p>
@@ -1075,7 +1075,7 @@ <h3 id="what-do-we-expect-to-see-from-the-demonstration">What do we expect to se
1075
1075
<divclass="admonition success">
1076
1076
<pclass="admonition-title">Now Get Your Work Marked by a <abbrtitle="Graduate Teaching Assistant">GTA</abbr></p>
1077
1077
<p>Once you have completed your code and are satisfied with its operation, you should show your work to a <abbrtitle="Graduate Teaching Assistant">GTA</abbr> for marking.</p>
0 commit comments