Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the velocity smoothing node in ROS.
ROS
ros::init(argc, argv, [1]);Attempts:
3 left
š” Hint
Common Mistakes
Using a generic node name that does not reflect velocity smoothing.
Forgetting to include quotes around the node name.
ā Incorrect
The node name must be "velocity_smoothing_node" to match the intended functionality.
2fill in blank
mediumComplete the code to declare a publisher for smoothed velocity commands.
ROS
ros::Publisher vel_pub = nh.advertise<geometry_msgs::Twist>([1], 10);
Attempts:
3 left
š” Hint
Common Mistakes
Publishing on the raw velocity topic instead of the smoothed one.
Using a topic name that does not match the smoothing purpose.
ā Incorrect
The publisher should advertise on "/cmd_vel_smooth" to publish smoothed velocity commands.
3fill in blank
hardFix the error in the velocity smoothing function signature.
ROS
geometry_msgs::Twist [1](const geometry_msgs::Twist& input_vel) {Attempts:
3 left
š” Hint
Common Mistakes
Using underscores in function names instead of camelCase.
Using variable-like names instead of function names.
ā Incorrect
The function name should be 'smoothVelocity' following camelCase naming conventions.
4fill in blank
hardFill both blanks to complete the velocity smoothing condition and update.
ROS
if (std::abs(input_vel.linear.x - last_vel.linear.x) > [1]) { smoothed_vel.linear.x = last_vel.linear.x + [2] * (input_vel.linear.x - last_vel.linear.x); }
Attempts:
3 left
š” Hint
Common Mistakes
Using max_speed instead of max_acceleration for the threshold.
Using delta_time instead of smoothing_factor for the update.
ā Incorrect
The condition compares the difference to max_acceleration, and smoothing_factor controls the update step.
5fill in blank
hardFill all three blanks to complete the velocity smoothing loop with publishing.
ROS
ros::Rate loop_rate([1]); while (ros::ok()) { ros::spinOnce(); geometry_msgs::Twist smoothed = [2](current_vel); [3].publish(smoothed); loop_rate.sleep(); }
Attempts:
3 left
š” Hint
Common Mistakes
Using too low or too high loop rate values.
Calling a non-existent smoothing function.
Publishing with the wrong publisher variable.
ā Incorrect
The loop rate is set to 20 Hz, smoothVelocity is called to smooth current_vel, and vel_pub publishes the result.
