Hint: Include all needed parameters with correct types and return value [OK]
Common Mistakes:
Missing dt parameter for time step
Using int instead of float for velocities
No return type annotation
3. Given the following code snippet for velocity smoothing, what will be the output if current_vel = 1.0, target_vel = 3.0, max_accel = 1.0, and dt = 1.0?
B. Remove the if-else and always set delta = max_change
C. Change 'elif delta < max_change' to 'elif delta < -max_change'
D. Add abs() around delta in the if condition
Solution
Step 1: Analyze the conditions for limiting delta
The function limits delta if it exceeds max_change positively or negatively.
Step 2: Identify incorrect condition
The condition 'elif delta < max_change' is wrong because it triggers for any delta less than max_change, including values that don't need limiting. It should check if delta is less than negative max_change.
Step 3: Correct the condition
Change 'elif delta < max_change' to 'elif delta < -max_change' to correctly limit negative large changes.
Final Answer:
Change 'elif delta < max_change' to 'elif delta < -max_change' -> Option C
Hint: Check negative limit uses -max_change, not max_change [OK]
Common Mistakes:
Using max_change instead of -max_change for negative check
Removing conditions and causing wrong velocity jumps
Incorrect calculation of max_change
5. You want to implement velocity smoothing for a robot that receives a list of target velocities every second: [0, 2, 5, 3, 0]. The robot's max acceleration is 1.5 m/s² and the time step is 1 second. Which sequence of smoothed velocities will correctly apply velocity smoothing starting from 0 m/s?