Page 1 of 1
Line following BubbleRob tutorial dont work
Posted: 15 Sep 2021, 16:11
by lyl
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
Posted: 16 Sep 2021, 07:15
by coppelia
That's correct, but the tutorial scene should contain the working script. Here again for info (that's for CoppeliaSim V4.2.0):
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
Cheers
Re: Line following BubbleRob tutorial dont work
Posted: 16 Sep 2021, 07:23
by lyl
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
Posted: 16 Sep 2021, 09:05
by coppelia
So which version of CoppeliaSim are you running? And what platform?
Is there any error message?
Re: Line following BubbleRob tutorial dont work
Posted: 16 Sep 2021, 09:09
by lyl
coppelia wrote: ↑16 Sep 2021, 09:05
So which version of CoppeliaSim are you running? And what platform?
Is there any error message?
version 4.2.0,. Just inside coopeliasim with the embedded script inside run, no error message.
Re: Line following BubbleRob tutorial dont work
Posted: 16 Sep 2021, 11:54
by coppelia
Please post your scene. Something must be wrong.
Cheers
Re: Line following BubbleRob tutorial dont work
Posted: 17 Sep 2021, 01:59
by lyl
soory!I have not inserted the picture, I wonder if you can see it, if not, please tell me!
Re: Line following BubbleRob tutorial dont work
Posted: 17 Sep 2021, 05:41
by coppelia
You need to post the scene file, not the picture, if you want us to have a look at it!
Cheers
Re: Line following BubbleRob tutorial dont work
Posted: 18 Sep 2021, 06:15
by lyl
Can I transfer files in this forum? How does it work?
Re: Line following BubbleRob tutorial dont work
Posted: 19 Sep 2021, 11:33
by fferri
Use any file sharing service that allows you sharing a public link, e.g.
Google Drive,
Dropbox,
OneDrive, etc...