How to set a rectangular workspace on a conveyer belt

Typically: "How do I... ", "How can I... " questions
Post Reply
alix
Posts: 62
Joined: 17 Sep 2019, 14:48

How to set a rectangular workspace on a conveyer belt

Post by alix »

Hi.
My question can be bit confusing, but please bear with me. I want to define a rectangular space on a conveyer belt. So the robot will try to reach target being within that rectangle. Not outside that rectangle. How can i define that rectangle in vrep through my code? Is there any way that the target automatically gets randomly positioned at any coordinates within that rectangle?

Thanks.
Regards,

fferri
Posts: 1193
Joined: 09 Sep 2013, 19:28

Re: How to set a rectangular workspace on a conveyer belt

Post by fferri »

Not sure I understand what you mean.

You can define a quadrilateral with 4 dummies, and sample a point inside it using math.random.

alix
Posts: 62
Joined: 17 Sep 2019, 14:48

Re: How to set a rectangular workspace on a conveyer belt

Post by alix »

fferri wrote: 03 Apr 2020, 09:53 Not sure I understand what you mean.

You can define a quadrilateral with 4 dummies, and sample a point inside it using math.random.
Hi fferi,

Thanks for the reply. This is exactly what i am trying to do. Can you please elaborate a bit about how to define the quadrilateral and sample point?
Thanks again

fferri
Posts: 1193
Joined: 09 Sep 2013, 19:28

Re: How to set a rectangular workspace on a conveyer belt

Post by fferri »

Image

Let \(\alpha,\beta\) two real numbers uniformly sampled from \([0,1]\) you can define your point as \(p=(1-\beta) ((1-\alpha) A + \alpha D) + \beta ((1-\alpha) B + \alpha C)\)

In Lua code:

Code: Select all

function interp(a,b,t)
    local r={}
    for i=1,#a do r[i]=(1-t)*a[i]+t*b[i] end
    return r
end

local alpha=math.random()
local beta=math.random()
local p=interp(interp(A,D,alpha),interp(B,C,alpha),beta)

alix
Posts: 62
Joined: 17 Sep 2019, 14:48

Re: How to set a rectangular workspace on a conveyer belt

Post by alix »

fferri wrote: 03 Apr 2020, 13:35 Image

Let \(\alpha,\beta\) two real numbers uniformly sampled from \([0,1]\) you can define your point as \(p=(1-\beta) ((1-\alpha) A + \alpha D) + \beta ((1-\alpha) B + \alpha C)\)

In Lua code:

Code: Select all

function interp(a,b,t)
    local r={}
    for i=1,#a do r[i]=(1-t)*a[i]+t*b[i] end
    return r
end

local alpha=math.random()
local beta=math.random()
local p=interp(interp(A,D,alpha),interp(B,C,alpha),beta)
Thankyou So much for your detailed help fferi... I'll try it now.
Thanks again

Post Reply