Challenge - 5 Problems
Velocity Smoothing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ā component_behavior
intermediateWhat is the output velocity after smoothing?
Given a ROS node that applies a simple velocity smoothing algorithm by averaging the current and previous velocity commands, what will be the output velocity if the input velocities are [1.0, 3.0, 5.0] m/s in sequence?
ROS
prev_velocity = 0.0 input_velocities = [1.0, 3.0, 5.0] output_velocities = [] for v in input_velocities: smoothed = (prev_velocity + v) / 2 output_velocities.append(smoothed) prev_velocity = smoothed print(output_velocities)
Attempts:
2 left
š” Hint
Think about how averaging the previous output with the current input smooths sudden changes.
ā Incorrect
The smoothing averages the previous output velocity with the current input. Starting from 0.0, the first output is (0+1)/2=0.5, then (0.5+3)/2=1.75, then (1.75+5)/2=3.375.
š Syntax
intermediateIdentify the syntax error in this ROS velocity smoothing callback
Which option contains the syntax error in this ROS Python callback function that smooths velocity commands?
ROS
def velocity_callback(msg): global prev_vel smoothed_vel = (prev_vel + msg.data) / 2 prev_vel = smoothed_vel pub.publish(smoothed_vel) prev_vel = 0.0
Attempts:
2 left
š” Hint
Check the type of data being published in ROS topics.
ā Incorrect
ROS publishers expect a message type, not a raw float. Publishing smoothed_vel (a float) directly causes a type error, which is a runtime error but also a syntax misuse in ROS context.
ā state_output
advancedWhat is the final velocity state after applying exponential smoothing?
A ROS node applies exponential smoothing to velocity commands with alpha=0.3. Given input velocities [10, 20, 30] m/s and initial smoothed velocity 0, what is the final smoothed velocity?
ROS
alpha = 0.3 smoothed = 0 inputs = [10, 20, 30] for v in inputs: smoothed = alpha * v + (1 - alpha) * smoothed print(round(smoothed, 2))
Attempts:
2 left
š” Hint
Calculate step by step: new smoothed = 0.3 * current input + 0.7 * previous smoothed.
ā Incorrect
Step 1: 0.3*10 + 0.7*0 = 3.0
Step 2: 0.3*20 + 0.7*3 = 6 + 2.1 = 8.1
Step 3: 0.3*30 + 0.7*8.1 = 9 + 5.67 = 14.67
Rounded to 2 decimals: 14.67.
š§ Debug
advancedWhy does this velocity smoothing node publish zero velocity always?
This ROS node is supposed to smooth velocity commands but always publishes zero. What is the cause?
ROS
prev_vel = 0.0 def callback(msg): smoothed = (prev_vel + msg.data) / 2 prev_vel = smoothed pub.publish(smoothed) sub = rospy.Subscriber('input_vel', Float32, callback) pub = rospy.Publisher('smoothed_vel', Float32, queue_size=10) rospy.spin()
Attempts:
2 left
š” Hint
Check variable scope inside the callback function.
ā Incorrect
Inside callback, prev_vel is assigned but not declared global, so Python treats it as local. The global prev_vel remains 0.0, so smoothing always uses 0.0, resulting in zero output.
š§ Conceptual
expertWhich smoothing method best handles sudden velocity spikes in ROS?
You want to smooth velocity commands in ROS to avoid sudden spikes but still respond quickly to changes. Which method is best?
Attempts:
2 left
š” Hint
Consider which method reduces spikes without delaying response too much.
ā Incorrect
Median filter effectively removes sudden spikes by selecting the middle value, preserving edges better than moving average or exponential smoothing with low alpha, which can lag or smooth too much.
