driveUntilBumpWithVelInput

Context and Summary

Modifies the basic driveUntilBump code making it a function and allowing the velocity to be specified as an input argument.

Source Code Listing

download source
function output = driveUntilBumpWithVelInput(v)
pub = rospublisher('/raw_vel');
sub_bump = rossubscriber('/bump');
msg = rosmessage(pub);

% get the robot moving
msg.Data = [v, v];
send(pub, msg);

while 1
    % wait for the next bump message
    bumpMessage = receive(sub_bump);
    % check if any of the bump sensors are set to 1 (meaning triggered)
    if any(bumpMessage.Data)
        msg.Data = [0.0, 0.0];
        send(pub, msg);
        break;
    end
end
end