-- This is a very simple EXAMPLE navigation program, which avoids obstacles using the Braitenberg algorithm if (sim_call_type==sim_childscriptcall_initialization) then motorLeft=simGetObjectHandle("Pioneer_p3dx_leftMotor") motorRight=simGetObjectHandle("Pioneer_p3dx_rightMotor") noDetectionDist=0.5 maxDetectionDist=0.5 v0=2.0 v1=0.5 vLeft=v0 vRight=v0 laserScannerHandle=simGetObjectHandle("LaserScanner_2D") laserScannerObjectName=simGetObjectName(laserScannerHandle) -- is not necessarily "LaserScanner_2D"!!! communicationTube=simTubeOpen(0,laserScannerObjectName..'_2D_SCANNER_DATA',1) end if (sim_call_type==sim_childscriptcall_cleanup) then end if (sim_call_type==sim_childscriptcall_actuation) then vLeft=2.0 -- Move Forward vRight=2.0 -- READ THE DATA: valordist=simGetFloatSignal("LaserFrontal") -- Read Signal if (valordist) then if (valordist < 0.5) then vLeft=-2.0 -- Turn Left vRight=2.0 end end simSetJointTargetVelocity(motorLeft,vLeft) simSetJointTargetVelocity(motorRight,vRight) end