TactivergeLite

Lite / Intelligent Robotic Systems / Term 1 worksheet

Worksheet: Intelligent Robotic Systems, term 1

Engineering Computation · Questions only. Check your answers in each Lite lesson, where they are graded on our server.

Name:   Date:

Week 1: One script is not a system

1. units.py defines cm_to_m. Which line lets another file call cm_to_m(250) with no prefix?

2. In a package with no circular imports, which module's changes need the MOST re-testing elsewhere?

3. grid.py imports planner.py so GridMap can call bfs, and planner.py imports grid.py. What is the best fix?

4. planner.py contains def _neighbours_in_bounds(...). What does the leading underscore tell other programmers?

5. io_csv.py ends with print(load_map('mars.csv')) at the top level. What happens when planner tests run 'import io_csv'?

Check these in the lesson

Week 1: Functions that keep their promises

1. Docstring: 'Returns the distance.' What is the most important thing missing for an engineer using it?

2. Using battery_runtime_h from the worked example, what does battery_runtime_h(3000, 750) return, in hours?

Answer: h

3. Which function design is best for a sensor-log tool?

4. wheel_rpm(speed_m_s, diameter_m) is called with diameter_m = -0.1. Which response best keeps the contract?

5. A function prints the average current instead of returning it. What can't you do?

Check these in the lesson

Week 1: Tests that catch you before the robot does

1. Which input is the best edge case for a function that returns the last reading of a sensor log?

2. Which test is safest for mean([0.1, 0.2]) (true answer 0.15)?

3. Why put demo code under if __name__ == "__main__":?

4. assert clamp(-5, 0, 100) == 0 fails with clamp returning 100. What is the most likely bug?

5. Which set of tests gives the most confidence for clamp(value, low, high)?

Check these in the lesson

Week 2: One blueprint, many sensors

1. Using RangeSensor from the worked example, s = RangeSensor('left', 3); s.record(40); s.record(46). What does s.mean() return?

Answer: cm

2. Inside record(self, raw_cm), what is self when you call rear.record(80)?

3. Which class definition gives each sensor its own readings list?

4. RangeSensor.unit = "cm" is a class attribute. After front = RangeSensor('front', 2), what is front.unit?

5. rear = RangeSensor('rear', -1); rear.mean() is called before any readings. With the worked example's code, what happens?

Check these in the lesson

Week 2: Objects that guard their own limits

1. With the worked example's Motor('arm', 2400), what does set_speed(2650) return?

Answer: rpm

2. Which is an invariant for an inventory Part object?

3. Motor defines rpm with @property and no setter. What does m.rpm = 3500 do?

4. part.withdraw(5) is called when quantity is 3. What should a well-designed method do?

5. Which test best checks Motor's invariant?

Check these in the lesson

Week 2: Object or function? Choosing the clearer design

1. mm_to_inches(mm) converts a length. Class or function?

2. Using the worked example's GridMap with rows ['..#', '...', '#..'], how many neighbours does cell (2, 2) have?

Answer: cells

3. A Robot holds two Motor objects and a RangeSensor. What is this design called?

4. Which situation most strongly suggests writing a class?

5. Why might bfs(grid, start, goal) be a function rather than a GridMap method?

Check these in the lesson

Week 3: Slice, filter, transform: lists at speed

1. A wheel encoder log is readings = [1, 53, 98, 96, 28, 61, 72, 43, 99]. What does sum(readings[3:4]) evaluate to?

Answer:

2. A log has 3,000 samples at 50 Hz. Which slice gives the last 10 seconds?

3. Which comprehension gives the masses (kg) of parts heavier than 0.5 kg, from masses_g in grams?

4. A wheel encoder log is readings = [67, 75, 95, 45, 62, 53, 2, 53]. What does len(readings[0:5:2]) evaluate to?

Answer:

5. path has 8 waypoints. Which expression raises IndexError?

Check these in the lesson

Week 3: From CSV file to records you can query

1. row = {'run': '4', 'current_a': '1.5'} from DictReader. What does row['run'] + 1 do?

2. In the worked example, if the empty current for run 4 is fixed to 1.75, what is motor B's average current (3 decimal places)?

Answer: A

3. Some rows have current 'n/a'. Which policy is best for an engineering report?

4. Which line adds current to a per-motor list, creating the list the first time a motor appears?

5. A log of motor temperature (°C) reads xs = [42, 50, 49, 47, 47, 44, 43, 44, 47]. What is the mean, statistics.mean(xs)? Give 2 decimal places.

Answer:

Check these in the lesson

Week 3: Module check: the stores audit

1. recorded has keys {A, B, C}; counted has keys {B, C, D}. What is recorded.keys() - counted.keys()?

2. In the worked example, how many M3 bolts are missing from the shelf compared with the record?

Answer: bolts

3. Which structure makes audit() easiest to test?

4. A log of motor temperature (°C) reads xs = [63, 66, 59, 62, 60, 54, 60]. What is the median, statistics.median(xs)? Give 2 decimal places.

Answer:

5. A wheel encoder log is readings = [45, 5, 63, 55, 46, 46, 16, 12, 19, 44]. What does readings[2] evaluate to?

Answer:

6. Which report line is most useful to the lab manager?

Check these in the lesson

Week 4: List, tuple, set or dict? Pick the right container

1. You need the stock quantity for any part number, looked up thousands of times. Which container?

2. visited = set(); visited.add([3, 7]). What happens?

3. A list holds 50,000 part numbers in random order. Checking a part that is NOT in the list: how many comparisons does 'p in parts' make?

Answer: comparisons

4. A planned path must keep its waypoints in order and may visit the same waypoint twice. Which container?

5. stock = {'M3-BOLT': 120}. What does stock.get('M4-BOLT', 0) return?

Check these in the lesson

Week 4: Stacks and queues: who goes next?

1. A robot cell queues jobs in arrival order: from collections import deque; q = deque(); q.append(27); q.append(49); q.popleft(); q.append(37); q.popleft(). What value does the final q.popleft() return?

Answer:

2. An editor's undo button should reverse the most recent change first. Which structure?

3. Why use deque.popleft() instead of list.pop(0) for a long job queue?

4. An editor keeps an undo stack of waypoint ids: s = []; s.append(38); s.append(23); s.append(27); s.pop(); s.append(33); s.pop(); s.append(3); s.pop(). What value does the final s.pop() return?

Answer:

5. What does 'while q:' do when q is an empty deque?

Check these in the lesson

Week 4: Breadth-first search: a queue explores a map

1. On an open 6-row × 9-column grid, BFS plans from (0, 0) to (5, 8). How many moves are in its path?

Answer: moves

2. What would change if BFS used a stack (pop the newest cell) instead of a queue?

3. Why mark a cell visited when it is ADDED to the queue, rather than when it is taken out?

4. The goal is completely surrounded by walls. What does BFS do?

5. A robot cell queues jobs in arrival order: from collections import deque; q = deque(); q.append(3); q.append(28); q.append(23); q.popleft(); q.popleft(); q.popleft(); q.append(23); q.popleft(). What value does the final q.popleft() return?

Answer:

Check these in the lesson

Week 5: Halve it again: binary search

1. A sorted list holds 500 part numbers. Binary search compares the target with one middle element per loop and halves the range each time. In the worst case (including a target that is not there), how many elements does it compare with the target?

Answer: comparisons

2. Binary search runs on the unsorted list [40, 10, 30, 20] looking for 40. What happens?

3. A sorted list holds 50 calibration points. Binary search compares the target with one middle element per loop and halves the range each time. In the worst case (including a target that is not there), how many elements does it compare with the target?

Answer: comparisons

4. Linear search on an unsorted list of 4,096 sensor ids, looking for one that is absent. How many comparisons?

Answer: comparisons

5. A student writes 'while lo < hi:' instead of 'while lo <= hi:'. What goes wrong?

Check these in the lesson

Week 5: Insertion sort: tidy as you go

1. Part masses (g) arrive as a = [32, 59, 17, 37, 44, 26]. They are sorted with insertion sort, where each new key moves left while j >= 0 and a[j] > key. Counting every evaluation of a[j] > key, how many comparisons are made?

Answer: comparisons

2. How many comparisons does insertion sort make on a reversed list of 10 items?

Answer: comparisons

3. Part masses (g) arrive as a = [36, 35, 27, 11, 5]. They are sorted with insertion sort, where each new key moves left while j >= 0 and a[j] > key. Counting every evaluation of a[j] > key, how many comparisons are made?

Answer: comparisons

4. A 1,000-item log is sorted except for two neighbouring entries that are swapped. Roughly how many comparisons does insertion sort make?

5. Two runs both drew 1.5 A; run 4 is listed before run 9. After a stable sort by current, which comes first?

Check these in the lesson

Week 5: Sort once, search many: when sorting pays

1. Linear search averages n/2 comparisons. For n = 2,000 items and k = 30 lookups, about how many comparisons in total?

Answer: comparisons

2. You must repeatedly list every part number between 2000 and 2100. Which preparation is best?

3. A sorted list holds 50 calibration points. Binary search compares the target with one middle element per loop and halves the range each time. In the worst case (including a target that is not there), how many elements does it compare with the target?

Answer: comparisons

4. You need to check ONE part number in an unsorted list of 50,000, once. Best plan?

5. Using cost models linear = k·n/2 and sorted = n·log₂n + k·log₂n, with n = 256, what is the smallest whole number of searches k for which sorting first is cheaper?

Answer: searches

Check these in the lesson

Week 6: Count the steps before you time them

1. A program is comparing every pair of waypoints. Its step count is measured with: count = sum(1 for i in range(0, 266, 10)). What value does count hold?

Answer: steps

2. A program is filling a cost table for a route planner. Its step count is measured with: count = sum(1 for i in range(10) for j in range(6)). What value does count hold?

Answer: steps

3. A program is scanning a sensor log. Its step count is measured with: count = sum(1 for i in range(36) for j in range(i)). What value does count hold?

Answer: steps

4. pair_checks(1000) is 499,500. About how big is pair_checks(2000)?

5. One loop over n readings filters spikes; a second loop over n readings averages them. How many loop passes in total?

Check these in the lesson

Week 6: Big-O: the shape of growth

1. An exact count is T(n) = 7n + 3n·log₂n + 12. What is its big-O?

2. Timing tests show a collision checker grows like n and takes 5 ms for n = 4096. Assuming that growth holds, predict its time for n = 8192, in ms.

Answer: ms

3. Timing tests show a parts-matching script grows like n² and takes 12 ms for n = 1024. Assuming that growth holds, predict its time for n = 4096, in ms.

Answer: ms

4. Which list is in order from slowest-growing to fastest-growing?

5. Algorithm X is O(n log n) and Y is O(n²). Which statement is true?

Check these in the lesson

Week 6: Module check: measure growth, then explain it

1. Times: 30 ms at n = 5,000 and 240 ms at n = 10,000. Estimate the exponent p in T ≈ c·n^p.

Answer:

2. Which timing method is most trustworthy?

3. Timing tests show a parts-matching script grows like n² and takes 12 ms for n = 1024. Assuming that growth holds, predict its time for n = 4096, in ms.

Answer: ms

4. A program is scanning a sensor log. Its step count is measured with: count = sum(1 for i in range(46) for j in range(i, 46)). What value does count hold?

Answer: steps

5. Big-O predicts O(n), but doubling n multiplies your measured time by 4. What is the best next step?

6. Which of these does big-O NOT tell you?

Check these in the lesson

Week 7: Bisection: trap the answer, halve the trap

1. A cable tension must satisfy f(x) = x**2 - 11 = 0. Bisection starts on [1, 4] (f(1) < 0 < f(4)), tests the midpoint each step and keeps the half where the sign changes. What midpoint is tested in step 2? Give 4 decimal places.

Answer:

2. Bisection starts from the bracket [0, 2] and stops once the bracket width is at most 0.05. What is the smallest number of steps that guarantees this?

Answer: steps

3. Bisection starts from the bracket [1, 3] and stops once the bracket width is at most 0.001. What is the smallest number of steps that guarantees this?

Answer: steps

4. A cable tension must satisfy f(x) = x**2 - 7 = 0. Bisection starts on [1, 4] (f(1) < 0 < f(4)), tests the midpoint each step and keeps the half where the sign changes. What midpoint is tested in step 4? Give 4 decimal places.

Answer:

5. f(x) = (x − 1)² on [0, 3]. Why can't bisection start?

Check these in the lesson

Week 7: Newton's method: ride the tangent

1. A microcontroller finds a vector length L = √12 with Newton's method on f(x) = x**2 - 12, using x = x - (x**2 - 12) / (2*x). Starting from x0 = 1, what is x after 2 iterations? Give 4 decimal places.

Answer:

2. A microcontroller finds a vector length L = √3 with Newton's method on f(x) = x**2 - 3, using x = x - (x**2 - 3) / (2*x). Starting from x0 = 5, what is x after 1 iteration? Give 4 decimal places.

Answer:

3. Newton's method on f(x) = x² − 4 starts at x₀ = 0. What happens?

4. Which statement compares bisection and Newton fairly?

5. Newton's method on f(x) = x³ − 2x − 5 from x₀ = 2. What is x₁ (4 decimal places)?

Answer:

Check these in the lesson

Week 7: Speed from position, distance from speed: calculus on samples

1. A linear-axis encoder logs position every 0.1 s: x = [11, 20, 29, 32, 38, 45] mm. Estimate the speed at sample index 4 using a forward difference (x[i+1] - x[i]) / h, in mm/s.

Answer: mm/s

2. A rover logs wheel speed every 2 s: v = [1, 1, 5, 5.5] m/s. Using the trapezium rule, how far did it travel between the first and last sample, in metres?

Answer: m

3. A rover logs wheel speed every 1 s: v = [3.5, 3.5, 2.5, 1, 0] m/s. Using the trapezium rule, how far did it travel between the first and last sample, in metres?

Answer: m

4. A linear-axis encoder logs position every 0.5 s: x = [15, 24, 29, 35, 40, 41] mm. Estimate the speed at sample index 3 using a central difference (x[i+1] - x[i-1]) / (2*h), in mm/s.

Answer: mm/s

5. Readings have noise up to ±0.2 mm and are 0.004 s apart. What is the largest possible noise in a forward-difference speed, in mm/s?

Answer: mm/s

6. Speed from a noisy encoder is too jumpy. Which change helps most without new hardware?

Check these in the lesson

Week 8: Choose the plot that answers the question

1. Does a servo's current draw rise with the load on its arm? You have 40 (load, current) pairs. Which plot?

2. How noisy is a gyro at rest? You have 5,000 readings. Which plot shows the spread best?

3. Which y-axis label is best?

4. A log of motor temperature (°C) reads xs = [63, 66, 59, 62, 60, 54, 60]. What is the median, statistics.median(xs)? Give 2 decimal places.

Answer:

Check these in the lesson

Week 8: Charts that lie without a single false number

1. Bars show 50 and 40 on an axis starting at 30. What is the lie factor? (Data change = (50 − 40)/40; visual change = (50 − 40)/(40 − 30).)

Answer:

2. A chart of battery life shows only months 4–6 of a 12-month trial, the months with the best results. What is the problem?

3. When is a y-axis that doesn't start at zero acceptable?

4. Before/after means are 41.8 and 39.2 jams a day, with day-to-day spread of ±4.2. Which caption is honest?

5. A log of motor temperature (°C) reads xs = [42, 50, 49, 47, 47, 44, 43, 44, 47]. What is the mean, statistics.mean(xs)? Give 2 decimal places.

Answer:

Check these in the lesson

Week 8: Mean, median and spread: summarising a log honestly

1. A log of battery current (A) reads xs = [20, 26, 26, 17, 21, 23, 19, 26]. What is the median, statistics.median(xs)? Give 2 decimal places.

Answer:

2. A log of motor temperature (°C) reads xs = [68, 68, 76, 77, 66]. What is the sample standard deviation, statistics.stdev(xs)? Give 2 decimal places.

Answer:

3. A log of ultrasonic range (cm) reads xs = [49, 49, 47, 44, 42, 51]. What is the sample standard deviation, statistics.stdev(xs)? Give 2 decimal places.

Answer:

4. Which report line is most honest and useful?

5. Why does statistics.stdev divide by n − 1?

Check these in the lesson

Week 9: Project: plan a path that counts the cost

1. A path enters cells with costs 1, 1, 5, 5, 1, 1 (the start cell is free). What is its total cost?

Answer:

2. pq holds (7, A), (3, B), (5, C) via heapq. What does heapq.heappop(pq) return?

3. On a map where every free cell costs 1, how do BFS and Dijkstra compare?

4. An editor keeps an undo stack of waypoint ids: s = []; s.append(38); s.append(23); s.append(27); s.pop(); s.append(33); s.pop(); s.append(3); s.pop(). What value does the final s.pop() return?

Answer:

5. Why must Dijkstra's step costs be non-negative?

Check these in the lesson

Week 9: Project: measure the cost, plot it honestly

1. BFS expands all 3,600 cells of a 60 × 60 open map. How many cells would it expand on a 120 × 120 open map, corner to corner?

Answer: cells

2. Timing tests show a collision checker grows like n and takes 5 ms for n = 4096. Assuming that growth holds, predict its time for n = 8192, in ms.

Answer: ms

3. A program is scanning a sensor log. Its step count is measured with: count = sum(1 for i in range(36) for j in range(i)). What value does count hold?

Answer: steps

4. You plot time against map side length and see a curve bending upwards for BFS. What is the clearest honest fix?

5. Which is the best 'limitations' sentence for your report?

Check these in the lesson

Week 9: Term assessment: engineering computation, end to end

1. A program is comparing every pair of waypoints. Its step count is measured with: count = sum(1 for i in range(0, 266, 10)). What value does count hold?

Answer: steps

2. A sorted list holds 8 waypoint ids. Binary search compares the target with one middle element per loop and halves the range each time. In the worst case (including a target that is not there), how many elements does it compare with the target?

Answer: comparisons

3. Bisection starts from the bracket [1, 3] and stops once the bracket width is at most 0.001. What is the smallest number of steps that guarantees this?

Answer: steps

4. Part masses (g) arrive as a = [58, 46, 38, 32, 28]. They are sorted with insertion sort, where each new key moves left while j >= 0 and a[j] > key. Counting every evaluation of a[j] > key, how many comparisons are made?

Answer: comparisons

5. A log of motor temperature (°C) reads xs = [42, 50, 49, 47, 47, 44, 43, 44, 47]. What is the mean, statistics.mean(xs)? Give 2 decimal places.

Answer:

6. Which line inside a loop over n items makes the whole loop O(n²)?

7. You need a root of a smooth f on [1, 2] (with a sign change) to 10⁻¹² quickly and safely. Best approach?

Check these in the lesson