主要内容

模拟超声波传感器安装在移动机器人

这个例子主要关注创建和安装一个超声波传感器在移动机器人robotScenario。自动驾驶的ultrasonicDetectionGenerator工具箱与robotScenario不能直接使用。我们将实现一个自定义传感器适配器的ultrasonicDetectionGenerator robotScenario兼容。传感器将用于正确位置移动机器人在充电站。

创建自定义传感器适配器

使用createCustomRobotSensorTemplate函数模板来生成一个传感器和更新它适应ultrasonicDetectionGenerator对象使用的机器人的场景。

createCustomRobotSensorTemplate

这个示例提供了适配器类CustomUltrasonicSensor,可以使用下面的命令查看。

编辑CustomUltrasonicSensor.m

使用机器人中的传感器适配器场景模拟

创建一个robotScenario对象的采样率10。

sampleRate = 10;场景= robotScenario (UpdateRate = sampleRate);

添加一个平面网格显示仓库地板上。

addMesh(场景中,“平面”位置=(5 0 0),大小= 20[12],颜色= [0.7 0.7 0.7]);

创建一个遍历一组waypointTrajectory wapoints充电站和使用lookupPose waypointTrajectory对象的方法获取机器人沿着轨迹的姿势。

起动位置= 3 [3];chargingPosition = [13 0];wpt =[(0.1起动位置);5 0 0.1;10 0 0.1;13.75 0 0.1];%充电站toa = [0 4 7 10];= wpt的traj = waypointTrajectory(锚点。TimeOfArrival = toa, ReferenceFrame =“ENU表示”,SampleRate = SampleRate);[pos,东方,或者,acc angvel] = traj.lookupPose (0:1 / sampleRate: 10);

添加一个robotPlatform到现场为我们的移动机器人。加载Clearpath robotPlatform rigidBodyTree沙哑的模型。也添加长方体网格来表示场景中的障碍。添加一个1 x1平面表示充电站的位置。

机器人= robotPlatform (“rst”场景,RigidBodyTree = loadrobot (“clearpathHusky”),InitialBasePosition = pos (1:), InitialBaseOrientation =紧凑(东方(1)));addMesh(场景中,“盒子”位置=(3 5 2),大小=(4 2 4),颜色= 0.5 - 0.25 [1],IsBinaryOccupied = true);addMesh(场景中,“盒子”位置=(3 5 2),大小=(4 2 4),颜色= 0.5 - 0.25 [1],IsBinaryOccupied = true);addMesh(场景中,“盒子”位置=[7 5 2],大小=(4 2 4),颜色= 0.5 - 0.25 [1],IsBinaryOccupied = true);addMesh(场景中,“盒子”位置=[7 5 2],大小=(4 2 4),颜色= 0.5 - 0.25 [1],IsBinaryOccupied = true);addMesh(场景中,“盒子”位置= 0.5[3 - 5],大小=(1 1 1),颜色= [0.1 0.1 0.1]);%平面表示充电站的位置addMesh(场景中,“平面”位置=[13 0 . 05],大小=[1],颜色= [0 1 0]);

创建使用robotPlatform充电站对象。robotPlatform允许我们获取traform之间的对象和传感器用于自定义传感器读取方法。在这里,使用一个长方体充电站可以建模。机器人已经达到5厘米内的表面开始充电的充电站。

chargeStation = robotPlatform (“chargeStation”场景,InitialBasePosition = [13.75 0 0]);chargeStation.updateMesh (“长方体”、大小=[0.5 - 1 1],颜色= [0 0.8 0]);

超声波传感器模型需要输入概要的障碍被检测出来。这个概要文件的尺寸结构包括信息障碍。

chargingStationProfile =结构(“长度”,0.5,“宽度”, 1“高度”, 1“OriginOffset”,0 0 0);

创建一个超声波传感器使用ultrasonicDetectionGenerator对象并设置其安装位置(0,0,0),检测范围(0.03 - 0.04 5)和视野(70,35)。也通过在前面创建的充电站的概要文件。

ultraSonicSensorModel = ultrasonicDetectionGenerator (MountingLocation = (0 0 0),DetectionRange = (0.03 - 0.04 5),FieldOfView = (70, 35),概要文件= chargingStationProfile);

创建一个使用自定义传感器适配器CustomUltrasonicSensor robotSensor对象。上面创建的适配器使用超声波传感器模型。安装位置将在机器人的前面。

= robotSensor(开证“超声波”,机器人,CustomUltrasonicSensor (ultraSonicSensorModel),MountingLocation = [0.5 0 0.05]);图(1);ax = show3D(场景);视图(-65,45)光网格

{“字符串”:“图包含一个坐标轴对象。坐标轴对象包含45块类型的对象,线。这些对象代表base_link, base_footprint、front_bumper_link front_left_wheel_link, front_right_wheel_link, imu_link, inertial_link, rear_bumper_link, rear_left_wheel_link, rear_right_wheel_link, top_chassis_link, top_plate_link, top_plate_front_link, top_plate_rear_link, user_rail_link, front_left_wheel_link_mesh, front_right_wheel_link_mesh, rear_left_wheel_link_mesh, rear_right_wheel_link_mesh, top_chassis_link_mesh, top_plate_link_mesh, user_rail_link_mesh base_link_mesh。“,”泰克斯”:[],“乳胶”:[]}

在这个场景中,移动机器人将遵循轨迹充电站。当超声波传感器在20厘米范围内的充电站,然后移动机器人推进1厘米以较慢的速度对充电站的每帧。当机器人在5厘米的充电站的表面,它停止和开始收费。仿真结束时开始收费。

isCharging = false;i = 1;设置(场景);~ isCharging [isUpdated t、侦破isValid] =阅读(开);图(1);show3D(场景);视图(-65,45)光网格%的运动矢量的机器人平台地面实况%这个运动向量将仅用于绘制图形元素构成= robot.read ();rotAngle = quat2eul(构成(13));持有如果~ isempty(依据)%距离对象距离=侦破{1}.Measurement;%画一个红色shpere的超声波传感器检测到一个对象中exampleHelperPlotDetectionPoint(场景中,侦破{1}.ObjectAttributes {1} .PointOnTarget,ult.Name,构成);displayText = [“距离= 'num2str(距离)];其他的距离=正;displayText =“未检测到对象!”;结束%画一个锥代表的视野和范围的超声波传感器exampleHelperPlotFOVCylinder(姿势,ultraSonicSensorModel.DetectionRange (3));持有如果距离< = 0.2%在步骤1厘米,当机器人在20厘米的充电站currentMotion = lastMotion;currentMotion (1) = currentMotion (1) + 0.01;(移动机器人,“基地”,currentMotion);lastMotion = currentMotion;displayText = [“发现充电器!距离= 'num2str(距离)];如果距离< = 0.05%机器人充电时在5厘米的充电站displayText = [“充电! !距离= 'num2str(距离)];isCharging = true;结束其他的%按照waypointTrajectory附近的充电站如果我< =长度(pos)运动= (pos(我:),或者(我,:),acc(我,:)(东方(i))紧凑,angvel(我:)];(移动机器人,“基地”、运动);lastMotion =运动;我=我+ 1;结束结束%显示距离充电站超声波传感器检测到的t =文本(15 0 displayText“写成BackgroundColor”,“黄色”);t (1)。颜色=“黑”;t (1)。字形大小= 10;推进(场景);updateSensors(场景);结束

{“字符串”:“图包含一个坐标轴对象。坐标轴对象包含48块类型的对象,表面上看,线,文本。这些对象代表base_link, base_footprint、front_bumper_link front_left_wheel_link, front_right_wheel_link, imu_link, inertial_link, rear_bumper_link, rear_left_wheel_link, rear_right_wheel_link, top_chassis_link, top_plate_link, top_plate_front_link, top_plate_rear_link, user_rail_link, front_left_wheel_link_mesh, front_right_wheel_link_mesh, rear_left_wheel_link_mesh, rear_right_wheel_link_mesh, top_chassis_link_mesh, top_plate_link_mesh, user_rail_link_mesh base_link_mesh。“,”泰克斯”:[],“乳胶”:[]}