A straight-forward code to navigate a differential drive mobile robot to a goal position in CoppeliaSim
This system was developed based on a course titled "Control of Mobile Robots" by Dr. Magnus Egerstedt from Georgia Institute of Technology. Instead of using Matlab Simulink, the model was implemented on Pioneer 3-DX mobile robotic platform simulation on CoppeliaSim Edu.
The code is simply navigating the robot by the following model
posPioneer=sim.getObjectPosition(pioneer,-1)
oriPioneer=sim.getObjectOrientation(pioneer,-1)
posTarget=sim.getObjectPosition(targetDummy,-1)
desiredTheta = math.atan2(posTarget[2]-posPioneer[2],posTarget[1]-posPioneer[1])
omega = (desiredTheta - oriPioneer[3])
vX = v0*math.cos(omega)
vY = v0*math.sin(omega)
print(posTarget[1]-posPioneer[1])
omega = omega*(1.2) --Change the value inside the parentheses to get a better K gain
vLeft=vX+vY-omega
vRight=vX+vY+omega
Here is the example demo video:
Reference : Egerstedt, M. (). Control of Mobile Robots Module 2 Mobile Robots [PowerPoint slides]. School of Electrical and Computer Engineering, Georgia Institute of Technology. www.coursera.org