main content

pick-凯发k8网页登录

this example shows how to setup an end-to-end pick and place workflow for a robotic manipulator like the kinova® gen3 and simulate the robot in the gazebo physics simulator.

overview

this example identifies and recycles objects into two bins using a kinova gen3 manipulator. the example uses tools from five toolboxes:

  • robotics system toolbox™ is used to model and simulate the manipulator.

  • stateflow® is used to schedule the high-level tasks in the example and step from task to task.

  • ros toolbox™ is used for connecting matlab to gazebo.

  • computer vision toolbox™ and deep learning toolbox™ are used for object detection using simulated camera in gazebo.

this example builds on key concepts from the following related examples:

  • shows how to generate and simulate interpolated joint trajectories to move from an initial to a desired end-effector pose.

  • pick-and-place workflow using stateflow for matlab

  • computer vision toolbox example: (computer vision toolbox)

  • ros toolbox example: (ros toolbox)

robot simulation and control in gazebo

start a ros-based simulator for a kinova gen3 robot and configure the matlab® connection with the robot simulator.

this example uses a virtual machine (vm) containing ros melodic available for download . if you have never used it before, see (ros toolbox).

  • in vm settings, vm > settings > hardware > display, disable .

  • start the ubuntu® virtual machine desktop.

  • in the ubuntu desktop, click the gazebo recycling world icon to start the gazebo world built for this example.

  • specify the ip address and port number of the ros master in gazebo so that matlab® can communicate with the robot simulator. for this example, the ros master in gazebo uses the ip address of 192.168.203.131 displayed on the desktop. adjust the rosip variable based on your vm.

  • start the ros 1 network using rosinit.

rosip = '192.168.203.131';   % ip address of ros-enabled machine  
rosinit(rosip,11311); % initialize ros connection
the value of the ros_ip environment variable, 192.168.31.1, will be used to set the advertised address for the ros node.
initializing global node /matlab_global_node_36570 with nodeuri http://192.168.31.1:51073/

after initializing the gazebo world by click the icon, the vm loads a kinova gen3 robot arm on a table with one recycling bin on each side. to simulate and control the robot arm in gazebo, the vm contains the ros package, which are provided by kinova.

the packages use to control the joints to desired joint positions. for additional details on using the vm, refer to (ros toolbox)

stateflow chart

this example uses a stateflow chart to schedule tasks in the example. open the chart to examine the contents and follow state transitions during chart execution.

edit examplehelperflowchartpickplacerosgazebo.sfx

the chart dictates how the manipulator interacts with the objects, or parts. it consists of basic initialization steps, followed by two main sections:

  • identify parts and determine where to place them

  • execute pick-and-place workflow

for a high-level description of the pick-and-place steps, see pick-and-place workflow using stateflow for matlab.

opening and closing the gripper

the command for activating the gripper, examplecommandactivategripperrosgazebo, sends an action request to open and close the gripper implemented in gazebo. to send a request to open the gripper, the following code is used. note: the example code shown just illustrates what the command does. do not run.

[gripact,gripgoal] = rosactionclient('/my_gen3/custom_gripper_controller/gripper_cmd');
grippercommand = rosmessage('control_msgs/grippercommand');
grippercommand.position = 0.0;  
gripgoal.command = grippercommand;
sendgoal(gripact,gripgoal);

moving the manipulator to a specified pose

the examplecommandmovetotaskconfigrosgazebo command function is used to move the manipulator to specified poses.

planning

the path planning generates simple task-space trajectories from an initial to a desired task configuration using and . for more details on planning and executing trajectories, see .

joint trajectory controller in ros

after generating a joint trajectory for the robot to follow, examplecommandmovetotaskconfigrosgazebo samples the trajectory at the desired sample rate, packages it into joint-trajectory ros messages and sends an action request to the joint-trajectory controller implemented in the kinova ros package.

detecting and classifying objects in the scene

the functions examplecommanddetectpartsrosgazebo and examplecommandclassifypartsrosgazebo use the simulated end-effector camera feed from the robot and apply a pretrained deep-learning model to detect the recyclable parts. the model takes a camera frame as input and outputs the 2d location of the object (pixel position) and the type of recycling it requires (blue or green bin). the 2d location on the image frame is mapped to the robot base frame.

deep-learning model training: acquiring and labeling gazebo images

the detection model was trained using a set of images acquired in the simulated environment within the gazebo world with the two classes of objects (bottle, can) placed on different locations of the table. the images are acquired from the simulated camera on-board the robot, which is moved along the horizontal and vertical planes to get images of the objects from many different camera perspectives.

the images are then labeled using the image labeler (computer vision toolbox) app, creating the training dataset for the yolo v2 detection model. (computer vision toolbox) trains the model. to see how to train a yolo v2 network in matlab, see (computer vision toolbox).

the trained model is deployed for online inference on the single image acquired by the on-board camera when the robot is in the home position. the (computer vision toolbox) function returns the image position of the bounding boxes of the detected objects, along with their classes, that is then used to find the position of the center of the top part of the objects. using a simple camera projection approach, assuming the height of the objects is known, the object position is projected into the world and finally used as reference position for picking the object. the class associated with the bounding boxes decides which bin to place the object.

start the pick-and-place task

this simulation uses a kinova gen3 manipulator with a gripper attached. load the robot model from a .mat file as a rigidbodytree object.

load('examplehelperkinovagen3gripperrosgazebo.mat'); 

initialize the pick and place coordinator

set the initial robot configuration. create the coordinator, which handles the robot control, by giving the robot model, initial configuration, and end-effector name.

initialrobotjconfig =  [3.5797   -0.6562   -1.2507   -0.7008    0.7303   -2.0500   -1.9053];
endeffectorframe = "gripper";

initialize the coordinator by giving the robot model, initial configuration, and end-effector name.

coordinator = examplehelpercoordinatorpickplacerosgazebo(robot,initialrobotjconfig, endeffectorframe);

specify the home configuration and two poses for placing objects.

coordinator.homerobottaskconfig = gettransform(robot, initialrobotjconfig, endeffectorframe); 
coordinator.placingpose{1} = trvec2tform([[0.2 0.55 0.26]])*axang2tform([0 0 1 pi/2])*axang2tform([0 1 0 pi]);
coordinator.placingpose{2} = trvec2tform([[0.2 -0.55 0.26]])*axang2tform([0 0 1 pi/2])*axang2tform([0 1 0 pi]);

run and visualize the simulation

connect the coordinator to the stateflow chart. once started, the stateflow chart is responsible for continuously going through the states of detecting objects, picking them up and placing them in the correct staging area.

coordinator.flowchart = examplehelperflowchartpickplacerosgazebo('coordinator', coordinator); 

use a dialog to start the pick-and-place task execution. click yes in the dialog to begin the simulation.

answer = questdlg('do you want to start the pick-and-place job now?', ...
         'start job','yes','no', 'no');
switch answer
    case 'yes'
        % trigger event to start pick and place in the stateflow chart
        coordinator.flowchart.startpickplace;       
    case 'no'
        coordinator.flowchart.endpickplace;
        delete(coordinator.flowchart)
        delete(coordinator);
end

ending the pick-and-place task

the stateflow chart will finish executing automatically after 3 failed attempts to detect new objects. to end the pick-and-place task prematurely, uncomment and execute the following lines of code or press ctrl c in the command window.

% coordinator.flowchart.endpickplace;        
% delete(coordinator.flowchart);
% delete(coordinator);

observe the simulation states

during execution, the active states at each point in time are highlighted in blue in the stateflow chart. this helps keeping track of what the robot does and when. you can click through the subsystems to see the details of the state in action.

visualize the pick-and-place action in gazebo

the gazebo world shows the robot in the working area as it moves parts to the recycling bins. the robot continues working until all parts have been placed. when the detection step doesn't find any more parts four times, the stateflow chart exits.

if strcmp(answer,'yes')
    while  coordinator.numdetectionruns <  4
        % wait for no parts to be detected.
    end
end

shutdown the ros network after finishing the example.

rosshutdown
shutting down global node /matlab_global_node_36570 with nodeuri http://192.168.31.1:51073/

凯发官网入口首页 copyright 2020 the mathworks, inc.

网站地图