Line following BubbleRob tutorial dont work
Line following BubbleRob tutorial dont work
I followed the user's manual to the Line Following BubbleRob tutorial, but one of the things I made was spinning backwards in place for some reason!The code uses the official website——https://www.coppeliarobotics.com/helpFiles/index.html[img]C:\Users\风继续吹\Desktop\Line following BubbleRob tutorial [/img]
Re: Line following BubbleRob tutorial dont work
That's correct, but the tutorial scene should contain the working script. Here again for info (that's for CoppeliaSim V4.2.0):
Cheers
Code: Select all
function sysCall_init()
bubbleRobBase=sim.getObjectHandle(sim.handle_self)
leftMotor=sim.getObjectHandle("bubbleRob_leftMotor")
rightMotor=sim.getObjectHandle("bubbleRob_rightMotor")
noseSensor=sim.getObjectHandle("bubbleRob_sensingNose")
minMaxSpeed={50*math.pi/180,300*math.pi/180}
backUntilTime=-1 -- Tells whether bubbleRob is in forward or backward mode
floorSensorHandles={-1,-1,-1}
floorSensorHandles[1]=sim.getObjectHandle("bubbleRob_leftSensor")
floorSensorHandles[2]=sim.getObjectHandle("bubbleRob_middleSensor")
floorSensorHandles[3]=sim.getObjectHandle("bubbleRob_rightSensor")
robotTrace=sim.addDrawingObject(sim.drawing_linestrip+sim.drawing_cyclic,2,0,-1,200,{1,1,0},nil,nil,{1,1,0})
-- Create the custom UI:
xml = '<ui title="'..sim.getObjectName(bubbleRobBase)..' speed" closeable="false" resizeable="false" activate="false">'..[[
<hslider minimum="0" maximum="100" on-change="speedChange_callback" id="1"/>
<label text="" style="* {margin-left: 300px;}"/>
</ui>
]]
ui=simUI.create(xml)
speed=(minMaxSpeed[1]+minMaxSpeed[2])*0.5
simUI.setSliderValue(ui,1,100*(speed-minMaxSpeed[1])/(minMaxSpeed[2]-minMaxSpeed[1]))
end
function sysCall_sensing()
local p=sim.getObjectPosition(bubbleRobBase,-1)
sim.addDrawingObjectItem(robotTrace,p)
end
function speedChange_callback(ui,id,newVal)
speed=minMaxSpeed[1]+(minMaxSpeed[2]-minMaxSpeed[1])*newVal/100
end
function sysCall_actuation()
result=sim.readProximitySensor(noseSensor)
if (result>0) then backUntilTime=sim.getSimulationTime()+4 end
-- read the line detection sensors:
sensorReading={false,false,false}
for i=1,3,1 do
result,data=sim.readVisionSensor(floorSensorHandles[i])
if (result>=0) then
sensorReading[i]=(data[11]<0.5) -- data[11] is the average of intensity of the image
end
end
-- compute left and right velocities to follow the detected line:
rightV=speed
leftV=speed
if sensorReading[1] then
leftV=0.03*speed
end
if sensorReading[3] then
rightV=0.03*speed
end
if sensorReading[1] and sensorReading[3] then
backUntilTime=sim.getSimulationTime()+2
end
if (backUntilTime<sim.getSimulationTime()) then
-- When in forward mode, we simply move forward at the desired speed
sim.setJointTargetVelocity(leftMotor,leftV)
sim.setJointTargetVelocity(rightMotor,rightV)
else
-- When in backward mode, we simply backup in a curve at reduced speed
sim.setJointTargetVelocity(leftMotor,-speed/2)
sim.setJointTargetVelocity(rightMotor,-speed/8)
end
end
function sysCall_cleanup()
simUI.destroy(ui)
end
Re: Line following BubbleRob tutorial dont work
I tried putting your code into bubbleRob's Child script, but the results didn't change and my three visual sensors were black all the time as if they couldn't pick up the line![img]C:\Users\风继续吹\Desktop[/img]
Re: Line following BubbleRob tutorial dont work
So which version of CoppeliaSim are you running? And what platform?
Is there any error message?
Is there any error message?
Re: Line following BubbleRob tutorial dont work
Please post your scene. Something must be wrong.
Cheers
Cheers
Re: Line following BubbleRob tutorial dont work
You need to post the scene file, not the picture, if you want us to have a look at it!
Cheers
Cheers
Re: Line following BubbleRob tutorial dont work
Can I transfer files in this forum? How does it work?
Re: Line following BubbleRob tutorial dont work
Use any file sharing service that allows you sharing a public link, e.g. Google Drive, Dropbox, OneDrive, etc...