CheckCollision sometimes misses intersections between the robot arm and the collision cylinders

I am attempting to visualize which collisionCylinder objects intersect with the robot arm using the checkCollision function. However, the collision detection behavior is highly inconsistent.
Out of approximately 10 repeated runs, checkCollision successfully detects the intersections only about twice. During the remaining runs, it returns a false negative (reporting no collision), even though the robot arm visually passes directly through the cylinders (see attached images).
The robot's collision meshes have been verified using the following code:
show(robot, randomConfig, 'Visuals','off', 'Collisions','on')
Why does it sometimes miss collisions with the robot? Since it successfully detected the collision twice before, it shouldn't be a problem with the robot mesh itself, as it has already successfully detected intersections twice right?
robot = loadrobot("abbIrb120T", DataFormat="column");
randomConfig = randomConfiguration(robot);
rod_orientation = 1;
zLimits = [0 0.695];
pointsPerDim = 30; % number of points along each axis, total points = pointsPerDim^2
if rod_orientation == 1
yLimits = [-1.0 1.0];
yCoords = linspace(yLimits(1), yLimits(2), pointsPerDim);
zCoords = linspace(zLimits(1), zLimits(2), pointsPerDim);
[Ygrid, Zgrid] = meshgrid(yCoords, zCoords);
midpoints = [zeros(numel(Ygrid),1), Ygrid(:), Zgrid(:)]; % [0, y, z]
% Rotation: 90° around Y-axis maps Z to X direction
rotationTransform = axang2tform([0 1 0 pi/2]);
else
xLimits = [-1.0 1.0];
xCoords = linspace(xLimits(1), xLimits(2), pointsPerDim);
zCoords = linspace(zLimits(1), zLimits(2), pointsPerDim);
[Xgrid, Zgrid] = meshgrid(xCoords, zCoords);
midpoints = [Xgrid(:), zeros(numel(Xgrid),1), Zgrid(:)]; % [x, 0, z]
% Rotation: 90° around X-axis maps Z to X direction
rotationTransform = axang2tform([1 0 0 pi/2]);
end
totalCylinders = pointsPerDim^2;
cylinders = cell(totalCylinders, 1);
radius = 0.01;
length = 2.0;
for idx = 1:totalCylinders
cyl = collisionCylinder(radius, length);
cyl.Pose = trvec2tform(midpoints(idx,:)) * rotationTransform;
cylinders{idx} = cyl;
end
figure
show(robot, randomConfig, 'Visuals','off', 'Collisions','on')
hold off
figure
show(robot,randomConfig)
hold on
for k = 1:totalCylinders
isColliding = checkCollision(robot, randomConfig, cylinders(k), SkippedSelfCollisions="parent");
[~, patchObj] = show(cylinders{k});
if isColliding
patchObj.FaceColor = [1 0 0]; % red for collision
disp(['Cylinder ' num2str(k) ' has collided']);
else
patchObj.FaceColor = [0 1 0]; % green if no collision
disp(['Cylinder ' num2str(k) ' has not collided']);
end
patchObj.FaceAlpha = 0.2;
end
Cylinder 1 has not collided Cylinder 2 has not collided Cylinder 3 has not collided Cylinder 4 has not collided Cylinder 5 has not collided Cylinder 6 has not collided Cylinder 7 has not collided Cylinder 8 has not collided Cylinder 9 has not collided Cylinder 10 has not collided Cylinder 11 has not collided Cylinder 12 has not collided Cylinder 13 has not collided Cylinder 14 has not collided Cylinder 15 has not collided Cylinder 16 has not collided Cylinder 17 has not collided Cylinder 18 has not collided Cylinder 19 has not collided Cylinder 20 has not collided Cylinder 21 has not collided Cylinder 22 has not collided Cylinder 23 has not collided Cylinder 24 has not collided Cylinder 25 has not collided Cylinder 26 has not collided Cylinder 27 has not collided Cylinder 28 has not collided Cylinder 29 has not collided Cylinder 30 has not collided Cylinder 31 has not collided Cylinder 32 has not collided Cylinder 33 has not collided Cylinder 34 has not collided Cylinder 35 has not collided Cylinder 36 has not collided Cylinder 37 has not collided Cylinder 38 has not collided Cylinder 39 has not collided Cylinder 40 has not collided Cylinder 41 has not collided Cylinder 42 has not collided Cylinder 43 has not collided Cylinder 44 has not collided Cylinder 45 has not collided Cylinder 46 has not collided Cylinder 47 has not collided Cylinder 48 has not collided Cylinder 49 has not collided Cylinder 50 has not collided Cylinder 51 has not collided Cylinder 52 has not collided Cylinder 53 has not collided Cylinder 54 has not collided Cylinder 55 has not collided Cylinder 56 has not collided Cylinder 57 has not collided Cylinder 58 has not collided Cylinder 59 has not collided Cylinder 60 has not collided Cylinder 61 has not collided Cylinder 62 has not collided Cylinder 63 has not collided Cylinder 64 has not collided Cylinder 65 has not collided Cylinder 66 has not collided Cylinder 67 has not collided Cylinder 68 has not collided Cylinder 69 has not collided Cylinder 70 has not collided Cylinder 71 has not collided Cylinder 72 has not collided Cylinder 73 has not collided Cylinder 74 has not collided Cylinder 75 has not collided Cylinder 76 has not collided Cylinder 77 has not collided Cylinder 78 has not collided Cylinder 79 has not collided Cylinder 80 has not collided Cylinder 81 has not collided Cylinder 82 has not collided Cylinder 83 has not collided Cylinder 84 has not collided Cylinder 85 has not collided Cylinder 86 has not collided Cylinder 87 has not collided Cylinder 88 has not collided Cylinder 89 has not collided Cylinder 90 has not collided Cylinder 91 has not collided Cylinder 92 has not collided Cylinder 93 has not collided Cylinder 94 has not collided Cylinder 95 has not collided Cylinder 96 has not collided Cylinder 97 has not collided Cylinder 98 has not collided Cylinder 99 has not collided Cylinder 100 has not collided Cylinder 101 has not collided Cylinder 102 has not collided Cylinder 103 has not collided Cylinder 104 has not collided Cylinder 105 has not collided Cylinder 106 has not collided Cylinder 107 has not collided Cylinder 108 has not collided Cylinder 109 has not collided Cylinder 110 has not collided Cylinder 111 has not collided Cylinder 112 has not collided Cylinder 113 has not collided Cylinder 114 has not collided Cylinder 115 has not collided Cylinder 116 has not collided Cylinder 117 has not collided Cylinder 118 has not collided Cylinder 119 has not collided Cylinder 120 has not collided Cylinder 121 has not collided Cylinder 122 has not collided Cylinder 123 has not collided Cylinder 124 has not collided Cylinder 125 has not collided Cylinder 126 has not collided Cylinder 127 has not collided Cylinder 128 has not collided Cylinder 129 has not collided Cylinder 130 has not collided Cylinder 131 has not collided Cylinder 132 has not collided Cylinder 133 has not collided Cylinder 134 has not collided Cylinder 135 has not collided Cylinder 136 has not collided Cylinder 137 has not collided Cylinder 138 has not collided Cylinder 139 has not collided Cylinder 140 has not collided Cylinder 141 has not collided Cylinder 142 has not collided Cylinder 143 has not collided Cylinder 144 has not collided Cylinder 145 has not collided Cylinder 146 has not collided Cylinder 147 has not collided Cylinder 148 has not collided Cylinder 149 has not collided Cylinder 150 has not collided Cylinder 151 has not collided Cylinder 152 has not collided Cylinder 153 has not collided Cylinder 154 has not collided Cylinder 155 has not collided Cylinder 156 has not collided Cylinder 157 has not collided Cylinder 158 has not collided Cylinder 159 has not collided Cylinder 160 has not collided Cylinder 161 has not collided Cylinder 162 has not collided Cylinder 163 has not collided Cylinder 164 has not collided Cylinder 165 has not collided Cylinder 166 has not collided Cylinder 167 has not collided Cylinder 168 has not collided Cylinder 169 has not collided Cylinder 170 has not collided Cylinder 171 has not collided Cylinder 172 has not collided Cylinder 173 has not collided Cylinder 174 has not collided Cylinder 175 has not collided Cylinder 176 has not collided Cylinder 177 has not collided Cylinder 178 has not collided Cylinder 179 has not collided Cylinder 180 has not collided Cylinder 181 has not collided Cylinder 182 has not collided Cylinder 183 has not collided Cylinder 184 has not collided Cylinder 185 has not collided Cylinder 186 has not collided Cylinder 187 has not collided Cylinder 188 has not collided Cylinder 189 has not collided Cylinder 190 has not collided Cylinder 191 has not collided Cylinder 192 has not collided Cylinder 193 has not collided Cylinder 194 has not collided Cylinder 195 has not collided Cylinder 196 has not collided Cylinder 197 has not collided Cylinder 198 has not collided Cylinder 199 has not collided Cylinder 200 has not collided Cylinder 201 has not collided Cylinder 202 has not collided Cylinder 203 has not collided Cylinder 204 has not collided Cylinder 205 has not collided Cylinder 206 has not collided Cylinder 207 has not collided Cylinder 208 has not collided Cylinder 209 has not collided Cylinder 210 has not collided Cylinder 211 has not collided Cylinder 212 has not collided Cylinder 213 has not collided Cylinder 214 has not collided Cylinder 215 has not collided Cylinder 216 has not collided Cylinder 217 has not collided Cylinder 218 has not collided Cylinder 219 has not collided Cylinder 220 has not collided Cylinder 221 has not collided Cylinder 222 has not collided Cylinder 223 has not collided Cylinder 224 has not collided Cylinder 225 has not collided Cylinder 226 has not collided Cylinder 227 has not collided Cylinder 228 has not collided Cylinder 229 has not collided Cylinder 230 has not collided Cylinder 231 has not collided Cylinder 232 has not collided Cylinder 233 has not collided Cylinder 234 has not collided Cylinder 235 has not collided Cylinder 236 has not collided Cylinder 237 has not collided Cylinder 238 has not collided Cylinder 239 has not collided Cylinder 240 has not collided Cylinder 241 has not collided Cylinder 242 has not collided Cylinder 243 has not collided Cylinder 244 has not collided Cylinder 245 has not collided Cylinder 246 has not collided Cylinder 247 has not collided Cylinder 248 has not collided Cylinder 249 has not collided Cylinder 250 has not collided Cylinder 251 has not collided Cylinder 252 has not collided Cylinder 253 has not collided Cylinder 254 has not collided Cylinder 255 has not collided Cylinder 256 has not collided Cylinder 257 has not collided Cylinder 258 has not collided Cylinder 259 has not collided Cylinder 260 has not collided Cylinder 261 has not collided Cylinder 262 has not collided Cylinder 263 has not collided Cylinder 264 has not collided Cylinder 265 has not collided Cylinder 266 has not collided Cylinder 267 has not collided Cylinder 268 has not collided Cylinder 269 has not collided Cylinder 270 has not collided Cylinder 271 has not collided Cylinder 272 has not collided Cylinder 273 has not collided Cylinder 274 has not collided Cylinder 275 has not collided Cylinder 276 has not collided Cylinder 277 has not collided Cylinder 278 has not collided Cylinder 279 has not collided Cylinder 280 has not collided Cylinder 281 has not collided Cylinder 282 has not collided Cylinder 283 has not collided Cylinder 284 has not collided Cylinder 285 has not collided Cylinder 286 has not collided Cylinder 287 has not collided Cylinder 288 has not collided Cylinder 289 has not collided Cylinder 290 has not collided Cylinder 291 has not collided Cylinder 292 has not collided Cylinder 293 has not collided Cylinder 294 has not collided Cylinder 295 has not collided Cylinder 296 has not collided Cylinder 297 has not collided Cylinder 298 has not collided Cylinder 299 has not collided Cylinder 300 has not collided Cylinder 301 has not collided Cylinder 302 has not collided Cylinder 303 has not collided Cylinder 304 has not collided Cylinder 305 has not collided Cylinder 306 has not collided Cylinder 307 has not collided Cylinder 308 has not collided Cylinder 309 has not collided Cylinder 310 has not collided Cylinder 311 has not collided Cylinder 312 has not collided Cylinder 313 has not collided Cylinder 314 has not collided Cylinder 315 has not collided Cylinder 316 has not collided Cylinder 317 has not collided Cylinder 318 has not collided Cylinder 319 has not collided Cylinder 320 has not collided Cylinder 321 has not collided Cylinder 322 has not collided Cylinder 323 has not collided Cylinder 324 has not collided Cylinder 325 has not collided Cylinder 326 has not collided Cylinder 327 has not collided Cylinder 328 has not collided Cylinder 329 has not collided Cylinder 330 has not collided Cylinder 331 has not collided Cylinder 332 has not collided Cylinder 333 has not collided Cylinder 334 has not collided Cylinder 335 has not collided Cylinder 336 has not collided Cylinder 337 has not collided Cylinder 338 has not collided Cylinder 339 has not collided Cylinder 340 has not collided Cylinder 341 has not collided Cylinder 342 has not collided Cylinder 343 has not collided Cylinder 344 has not collided Cylinder 345 has not collided Cylinder 346 has not collided Cylinder 347 has not collided Cylinder 348 has not collided Cylinder 349 has not collided Cylinder 350 has not collided Cylinder 351 has not collided Cylinder 352 has not collided Cylinder 353 has not collided Cylinder 354 has not collided Cylinder 355 has not collided Cylinder 356 has not collided Cylinder 357 has not collided Cylinder 358 has not collided Cylinder 359 has not collided Cylinder 360 has not collided Cylinder 361 has not collided Cylinder 362 has not collided Cylinder 363 has not collided Cylinder 364 has not collided Cylinder 365 has not collided Cylinder 366 has not collided Cylinder 367 has not collided Cylinder 368 has not collided Cylinder 369 has not collided Cylinder 370 has not collided Cylinder 371 has not collided Cylinder 372 has not collided Cylinder 373 has not collided Cylinder 374 has not collided Cylinder 375 has not collided Cylinder 376 has not collided Cylinder 377 has not collided Cylinder 378 has not collided Cylinder 379 has not collided Cylinder 380 has not collided Cylinder 381 has not collided Cylinder 382 has not collided Cylinder 383 has not collided Cylinder 384 has not collided Cylinder 385 has not collided Cylinder 386 has not collided Cylinder 387 has not collided Cylinder 388 has not collided Cylinder 389 has not collided Cylinder 390 has not collided Cylinder 391 has not collided Cylinder 392 has not collided Cylinder 393 has not collided Cylinder 394 has not collided Cylinder 395 has not collided Cylinder 396 has not collided Cylinder 397 has not collided Cylinder 398 has not collided Cylinder 399 has not collided Cylinder 400 has not collided Cylinder 401 has not collided Cylinder 402 has not collided Cylinder 403 has not collided Cylinder 404 has not collided Cylinder 405 has not collided Cylinder 406 has not collided Cylinder 407 has not collided Cylinder 408 has not collided Cylinder 409 has not collided Cylinder 410 has not collided Cylinder 411 has not collided Cylinder 412 has not collided Cylinder 413 has not collided Cylinder 414 has not collided Cylinder 415 has not collided Cylinder 416 has not collided Cylinder 417 has not collided Cylinder 418 has not collided Cylinder 419 has not collided Cylinder 420 has not collided Cylinder 421 has not collided Cylinder 422 has not collided Cylinder 423 has not collided Cylinder 424 has not collided Cylinder 425 has not collided Cylinder 426 has not collided Cylinder 427 has not collided Cylinder 428 has not collided Cylinder 429 has not collided Cylinder 430 has not collided Cylinder 431 has not collided Cylinder 432 has not collided Cylinder 433 has not collided Cylinder 434 has not collided Cylinder 435 has not collided Cylinder 436 has not collided Cylinder 437 has not collided Cylinder 438 has not collided Cylinder 439 has not collided Cylinder 440 has not collided Cylinder 441 has not collided Cylinder 442 has not collided Cylinder 443 has not collided Cylinder 444 has not collided Cylinder 445 has not collided Cylinder 446 has not collided Cylinder 447 has not collided Cylinder 448 has not collided Cylinder 449 has not collided Cylinder 450 has not collided Cylinder 451 has not collided Cylinder 452 has not collided Cylinder 453 has not collided Cylinder 454 has not collided Cylinder 455 has not collided Cylinder 456 has not collided Cylinder 457 has not collided Cylinder 458 has not collided Cylinder 459 has not collided Cylinder 460 has not collided Cylinder 461 has not collided Cylinder 462 has not collided Cylinder 463 has not collided Cylinder 464 has not collided Cylinder 465 has not collided Cylinder 466 has not collided Cylinder 467 has not collided Cylinder 468 has not collided Cylinder 469 has not collided Cylinder 470 has not collided Cylinder 471 has not collided Cylinder 472 has not collided Cylinder 473 has not collided Cylinder 474 has not collided Cylinder 475 has not collided Cylinder 476 has not collided Cylinder 477 has not collided Cylinder 478 has not collided Cylinder 479 has not collided Cylinder 480 has not collided Cylinder 481 has not collided Cylinder 482 has not collided Cylinder 483 has not collided Cylinder 484 has not collided Cylinder 485 has not collided Cylinder 486 has not collided Cylinder 487 has not collided Cylinder 488 has not collided Cylinder 489 has not collided Cylinder 490 has not collided Cylinder 491 has not collided Cylinder 492 has not collided Cylinder 493 has not collided Cylinder 494 has not collided Cylinder 495 has not collided Cylinder 496 has not collided Cylinder 497 has not collided Cylinder 498 has not collided Cylinder 499 has not collided Cylinder 500 has not collided Cylinder 501 has not collided Cylinder 502 has not collided Cylinder 503 has not collided Cylinder 504 has not collided Cylinder 505 has not collided Cylinder 506 has not collided Cylinder 507 has not collided Cylinder 508 has not collided Cylinder 509 has not collided Cylinder 510 has not collided Cylinder 511 has not collided Cylinder 512 has not collided Cylinder 513 has not collided Cylinder 514 has not collided Cylinder 515 has not collided Cylinder 516 has not collided Cylinder 517 has not collided Cylinder 518 has not collided Cylinder 519 has not collided Cylinder 520 has not collided Cylinder 521 has not collided Cylinder 522 has not collided Cylinder 523 has not collided Cylinder 524 has not collided Cylinder 525 has not collided Cylinder 526 has not collided Cylinder 527 has not collided Cylinder 528 has not collided Cylinder 529 has not collided Cylinder 530 has not collided Cylinder 531 has not collided Cylinder 532 has not collided Cylinder 533 has not collided Cylinder 534 has not collided Cylinder 535 has not collided Cylinder 536 has not collided Cylinder 537 has not collided Cylinder 538 has not collided Cylinder 539 has not collided Cylinder 540 has not collided Cylinder 541 has not collided Cylinder 542 has not collided Cylinder 543 has not collided Cylinder 544 has not collided Cylinder 545 has not collided Cylinder 546 has not collided Cylinder 547 has not collided Cylinder 548 has not collided Cylinder 549 has not collided Cylinder 550 has not collided Cylinder 551 has not collided Cylinder 552 has not collided Cylinder 553 has not collided Cylinder 554 has not collided Cylinder 555 has not collided Cylinder 556 has not collided Cylinder 557 has not collided Cylinder 558 has not collided Cylinder 559 has not collided Cylinder 560 has not collided Cylinder 561 has not collided Cylinder 562 has not collided Cylinder 563 has not collided Cylinder 564 has not collided Cylinder 565 has not collided Cylinder 566 has not collided Cylinder 567 has not collided Cylinder 568 has not collided Cylinder 569 has not collided Cylinder 570 has not collided Cylinder 571 has not collided Cylinder 572 has not collided Cylinder 573 has not collided Cylinder 574 has not collided Cylinder 575 has not collided Cylinder 576 has not collided Cylinder 577 has not collided Cylinder 578 has not collided Cylinder 579 has not collided Cylinder 580 has not collided Cylinder 581 has not collided Cylinder 582 has not collided Cylinder 583 has not collided Cylinder 584 has not collided Cylinder 585 has not collided Cylinder 586 has not collided Cylinder 587 has not collided Cylinder 588 has not collided Cylinder 589 has not collided Cylinder 590 has not collided Cylinder 591 has not collided Cylinder 592 has not collided Cylinder 593 has not collided Cylinder 594 has not collided Cylinder 595 has not collided Cylinder 596 has not collided Cylinder 597 has not collided Cylinder 598 has not collided Cylinder 599 has not collided Cylinder 600 has not collided Cylinder 601 has not collided Cylinder 602 has not collided Cylinder 603 has not collided Cylinder 604 has not collided Cylinder 605 has not collided Cylinder 606 has not collided Cylinder 607 has not collided Cylinder 608 has not collided Cylinder 609 has not collided Cylinder 610 has not collided Cylinder 611 has not collided Cylinder 612 has not collided Cylinder 613 has not collided Cylinder 614 has not collided Cylinder 615 has not collided Cylinder 616 has not collided Cylinder 617 has not collided Cylinder 618 has not collided Cylinder 619 has not collided Cylinder 620 has not collided Cylinder 621 has not collided Cylinder 622 has not collided Cylinder 623 has not collided Cylinder 624 has not collided Cylinder 625 has not collided Cylinder 626 has not collided Cylinder 627 has not collided Cylinder 628 has not collided Cylinder 629 has not collided Cylinder 630 has not collided Cylinder 631 has not collided Cylinder 632 has not collided Cylinder 633 has not collided Cylinder 634 has not collided Cylinder 635 has not collided Cylinder 636 has not collided Cylinder 637 has not collided Cylinder 638 has not collided Cylinder 639 has not collided Cylinder 640 has not collided Cylinder 641 has not collided Cylinder 642 has not collided Cylinder 643 has not collided Cylinder 644 has not collided Cylinder 645 has not collided Cylinder 646 has not collided Cylinder 647 has not collided Cylinder 648 has not collided Cylinder 649 has not collided Cylinder 650 has not collided Cylinder 651 has not collided Cylinder 652 has not collided Cylinder 653 has not collided Cylinder 654 has not collided Cylinder 655 has not collided Cylinder 656 has not collided Cylinder 657 has not collided Cylinder 658 has not collided Cylinder 659 has not collided Cylinder 660 has not collided Cylinder 661 has not collided Cylinder 662 has not collided Cylinder 663 has not collided Cylinder 664 has not collided Cylinder 665 has not collided Cylinder 666 has not collided Cylinder 667 has not collided Cylinder 668 has not collided Cylinder 669 has not collided Cylinder 670 has not collided Cylinder 671 has not collided Cylinder 672 has not collided Cylinder 673 has not collided Cylinder 674 has not collided Cylinder 675 has not collided Cylinder 676 has not collided Cylinder 677 has not collided Cylinder 678 has not collided Cylinder 679 has not collided Cylinder 680 has not collided Cylinder 681 has not collided Cylinder 682 has not collided Cylinder 683 has not collided Cylinder 684 has not collided Cylinder 685 has not collided Cylinder 686 has not collided Cylinder 687 has not collided Cylinder 688 has not collided Cylinder 689 has not collided Cylinder 690 has not collided Cylinder 691 has not collided Cylinder 692 has not collided Cylinder 693 has not collided Cylinder 694 has not collided Cylinder 695 has not collided Cylinder 696 has not collided Cylinder 697 has not collided Cylinder 698 has not collided Cylinder 699 has not collided Cylinder 700 has not collided Cylinder 701 has not collided Cylinder 702 has not collided Cylinder 703 has not collided Cylinder 704 has not collided Cylinder 705 has not collided Cylinder 706 has not collided Cylinder 707 has not collided Cylinder 708 has not collided Cylinder 709 has not collided Cylinder 710 has not collided Cylinder 711 has not collided Cylinder 712 has not collided Cylinder 713 has not collided Cylinder 714 has not collided Cylinder 715 has not collided Cylinder 716 has not collided Cylinder 717 has not collided Cylinder 718 has not collided Cylinder 719 has not collided Cylinder 720 has not collided Cylinder 721 has not collided Cylinder 722 has not collided Cylinder 723 has not collided Cylinder 724 has not collided Cylinder 725 has not collided Cylinder 726 has not collided Cylinder 727 has not collided Cylinder 728 has not collided Cylinder 729 has not collided Cylinder 730 has not collided Cylinder 731 has not collided Cylinder 732 has not collided Cylinder 733 has not collided Cylinder 734 has not collided Cylinder 735 has not collided Cylinder 736 has not collided Cylinder 737 has not collided Cylinder 738 has not collided Cylinder 739 has not collided Cylinder 740 has not collided Cylinder 741 has not collided Cylinder 742 has not collided Cylinder 743 has not collided Cylinder 744 has not collided Cylinder 745 has not collided Cylinder 746 has not collided Cylinder 747 has not collided Cylinder 748 has not collided Cylinder 749 has not collided Cylinder 750 has not collided Cylinder 751 has not collided Cylinder 752 has not collided Cylinder 753 has not collided Cylinder 754 has not collided Cylinder 755 has not collided Cylinder 756 has not collided Cylinder 757 has not collided Cylinder 758 has not collided Cylinder 759 has not collided Cylinder 760 has not collided Cylinder 761 has not collided Cylinder 762 has not collided Cylinder 763 has not collided Cylinder 764 has not collided Cylinder 765 has not collided Cylinder 766 has not collided Cylinder 767 has not collided Cylinder 768 has not collided Cylinder 769 has not collided Cylinder 770 has not collided Cylinder 771 has not collided Cylinder 772 has not collided Cylinder 773 has not collided Cylinder 774 has not collided Cylinder 775 has not collided Cylinder 776 has not collided Cylinder 777 has not collided Cylinder 778 has not collided Cylinder 779 has not collided Cylinder 780 has not collided Cylinder 781 has not collided Cylinder 782 has not collided Cylinder 783 has not collided Cylinder 784 has not collided Cylinder 785 has not collided Cylinder 786 has not collided Cylinder 787 has not collided Cylinder 788 has not collided Cylinder 789 has not collided Cylinder 790 has not collided Cylinder 791 has not collided Cylinder 792 has not collided Cylinder 793 has not collided Cylinder 794 has not collided Cylinder 795 has not collided Cylinder 796 has not collided Cylinder 797 has not collided Cylinder 798 has not collided Cylinder 799 has not collided Cylinder 800 has not collided Cylinder 801 has not collided Cylinder 802 has not collided Cylinder 803 has not collided Cylinder 804 has not collided Cylinder 805 has not collided Cylinder 806 has not collided Cylinder 807 has not collided Cylinder 808 has not collided Cylinder 809 has not collided Cylinder 810 has not collided Cylinder 811 has not collided Cylinder 812 has not collided Cylinder 813 has not collided Cylinder 814 has not collided Cylinder 815 has not collided Cylinder 816 has not collided Cylinder 817 has not collided Cylinder 818 has not collided Cylinder 819 has not collided Cylinder 820 has not collided Cylinder 821 has not collided Cylinder 822 has not collided Cylinder 823 has not collided Cylinder 824 has not collided Cylinder 825 has not collided Cylinder 826 has not collided Cylinder 827 has not collided Cylinder 828 has not collided Cylinder 829 has not collided Cylinder 830 has not collided Cylinder 831 has not collided Cylinder 832 has not collided Cylinder 833 has not collided Cylinder 834 has not collided Cylinder 835 has not collided Cylinder 836 has not collided Cylinder 837 has not collided Cylinder 838 has not collided Cylinder 839 has not collided Cylinder 840 has not collided Cylinder 841 has not collided Cylinder 842 has not collided Cylinder 843 has not collided Cylinder 844 has not collided Cylinder 845 has not collided Cylinder 846 has not collided Cylinder 847 has not collided Cylinder 848 has not collided Cylinder 849 has not collided Cylinder 850 has not collided Cylinder 851 has not collided Cylinder 852 has not collided Cylinder 853 has not collided Cylinder 854 has not collided Cylinder 855 has not collided Cylinder 856 has not collided Cylinder 857 has not collided Cylinder 858 has not collided Cylinder 859 has not collided Cylinder 860 has not collided Cylinder 861 has not collided Cylinder 862 has not collided Cylinder 863 has not collided Cylinder 864 has not collided Cylinder 865 has not collided Cylinder 866 has not collided Cylinder 867 has not collided Cylinder 868 has not collided Cylinder 869 has not collided Cylinder 870 has not collided Cylinder 871 has not collided Cylinder 872 has not collided Cylinder 873 has not collided Cylinder 874 has not collided Cylinder 875 has not collided Cylinder 876 has not collided Cylinder 877 has not collided Cylinder 878 has not collided Cylinder 879 has not collided Cylinder 880 has not collided Cylinder 881 has not collided Cylinder 882 has not collided Cylinder 883 has not collided Cylinder 884 has not collided Cylinder 885 has not collided Cylinder 886 has not collided Cylinder 887 has not collided Cylinder 888 has not collided Cylinder 889 has not collided Cylinder 890 has not collided Cylinder 891 has not collided Cylinder 892 has not collided Cylinder 893 has not collided Cylinder 894 has not collided Cylinder 895 has not collided Cylinder 896 has not collided Cylinder 897 has not collided Cylinder 898 has not collided Cylinder 899 has not collided Cylinder 900 has not collided
axis auto

 Accepted Answer

Hi @Umar, thanks to your guidance, WE have solved the problem. I figured out that it has nothing to do with the gap between the rods. This is the only code I changed:
if any(isColliding, 'all') % instead of (if isColliding)
By changing this, it started working even with fewer rods (downside: it is less accurate).
robot = loadrobot("abbIrb120T", DataFormat="column");
randomConfig = randomConfiguration(robot);
rod_orientation = 1;
zLimits = [0 0.695];
pointsPerDim = 10; % number of points along each axis, total points = pointsPerDim^2
if rod_orientation == 1
yLimits = [-1.0 1.0];
yCoords = linspace(yLimits(1), yLimits(2), pointsPerDim);
zCoords = linspace(zLimits(1), zLimits(2), pointsPerDim);
[Ygrid, Zgrid] = meshgrid(yCoords, zCoords);
midpoints = [zeros(numel(Ygrid),1), Ygrid(:), Zgrid(:)]; % [0, y, z]
% Rotation: 90° around Y-axis maps Z to X direction
rotationTransform = axang2tform([0 1 0 pi/2]);
else
xLimits = [-1.0 1.0];
xCoords = linspace(xLimits(1), xLimits(2), pointsPerDim);
zCoords = linspace(zLimits(1), zLimits(2), pointsPerDim);
[Xgrid, Zgrid] = meshgrid(xCoords, zCoords);
midpoints = [Xgrid(:), zeros(numel(Xgrid),1), Zgrid(:)]; % [x, 0, z]
% Rotation: 90° around X-axis maps Z to X direction
rotationTransform = axang2tform([1 0 0 pi/2]);
end
totalCylinders = pointsPerDim^2;
cylinders = cell(totalCylinders, 1);
radius = 0.01;
length = 2.0;
for idx = 1:totalCylinders
cyl = collisionCylinder(radius, length);
cyl.Pose = trvec2tform(midpoints(idx,:)) * rotationTransform;
cylinders{idx} = cyl;
end
figure
show(robot, randomConfig, 'Visuals','off', 'Collisions','on')
hold off
figure
show(robot,randomConfig)
hold on
for k = 1:totalCylinders
isColliding = checkCollision(robot, randomConfig, cylinders(k), SkippedSelfCollisions="parent");
[~, patchObj] = show(cylinders{k});
if any(isColliding, 'all')
patchObj.FaceColor = [1 0 0]; % red for collision
else
patchObj.FaceColor = [0 1 0]; % green if no collision
end
patchObj.FaceAlpha = 0.2;
end
axis auto
Warning: Graphics acceleration hardware is unavailable. Graphics quality and performance might be diminished. See MATLAB System Requirements.

1 Comment

Hi @Urinder, Appreciate you following up with the fix. The real bug was simpler: isColliding returns one logical value per robot body, not a single true/false, and MATLAB's if isColliding implicitly does all(isColliding) — so it only branched "true" when every single body collided with the cylinder at once, instead of when any one did. Switching to if any(isColliding, 'all')fixes exactly that, which is also why it started working even with a coarser grid — that wouldn't make sense if it were really a sampling-density problem. Good call sticking with it instead of settling for "just add more rods." Thanks for posting the fix back — this'll save the next person who hits the same thing a lot of head-scratching.

Sign in to comment.

More Answers (2)

Hi @Urinder, Your robot already ships with collision meshes built in, so that's not the gap. Looking at your grid math instead: with 30 points over a 2m span, your rods are ~6.9 cm apart but only 2 cm thick, so roughly 70% of the space between columns is empty gap. The green wall looks solid in the render because hundreds of transparent rods overlap visually from one angle, but the arm can easily slip through a gap without touching any rod's centerline. That'd explain the ~2-in-10 hit rate. Try checking sepDist (3-output form of checkCollision) on a "miss" frame — if it's a few cm, that confirms it's a real gap, not a bug. Otherwise, denser grid or a solid collisionBox instead of the rod lattice should fix it.
The "checkCollision" function's "isCollidingStatus" when world objects are provided (a non-empty cell-array) is a two-element logical vector. You can read here that the first element indicates whether the robot is in self-collision, and the second element indicates whether the robot collides with any of the world objects. Self-collision check is a pair-wise collision check over the body sets of collision geometries on the robot while the world-collision check is a pair-wise check between body sets of collision geometries on the robot and every collision object in the "worldObjects" cell-array.
Can you clarify what do you mean by "less accurate"?
Karsh

1 Comment

Hi Harsh,
To clarify my master's thesis scope, I need to determine the optimal pose of the robot for manual guidance. The operator will manually move the mobile manipulator by converting Force/Torque (F/T) sensor values into wheel commands. To determine this optimal pose, I am using manipulability indices.
Since the robot is positioned directly in front of the operator, I developed a custom visibility index. This index utilizes a grid of collision cylinders to evaluate line-of-sight. A higher density of collision cylinders yields a more accurate index. For each unique robot configuration, the visibility index is calculated using the formula: visibility = 1 - (collisionCount / totalCylinders). A higher value indicates better visibility. Finally, these visibility index values are normalized within an array for comparison.
Urinder

Sign in to comment.

Products

Release

R2025b

Asked:

on 4 Jul 2026

Commented:

on 15 Jul 2026 at 13:35

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!