Any pointers about gcode.ttt?

Typically: "How do I... ", "How can I... " questions
mohtashem
Posts: 15
Joined: 17 Apr 2017, 20:03

Any pointers about gcode.ttt?

Post by mohtashem »

Hello,

I was going through the scenes folder and observed a gCode.ttt. I wanted to see the scene in action, but apparently it seems a threaded child script attached to a dummy without any robots or anything. So I am confused. Any ideas/pointers on how to use it/where to start?

Cheers,
mohtashem

Mohamed Magdy
Posts: 43
Joined: 02 Sep 2019, 18:32

Re: Any pointers about gcode.ttt?

Post by Mohamed Magdy »

I remember that scene is drawing a lizard

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

Re: Any pointers about gcode.ttt?

Post by fferri »

It uses gcode.lua, a Gcode interpreter written for V-REP, which by default produces a path as the result of the execution of the program (you can then use V-REP facilities such as path following, trajectory tracking, inverse kinematics, ... to make the tool move along the path).

But the Gcode interpreter could be also customized to directly move your robot (now I forgot how... try reading the source code in gcode.lua).

mohtashem
Posts: 15
Joined: 17 Apr 2017, 20:03

Re: Any pointers about gcode.ttt?

Post by mohtashem »

Hello,

Thank you so much for the explanation. However, I have a question. As soon as I loaded the scene for the first time and played it for the first time, it returned an error as follows:

Lua runtime error: ...e/mrm/V-REP_PRO_EDU_V3_6_2_Ubuntu16_04/lua/gcode.lua:208: attempt to concatenate local 'valueNum' (a nil value)
stack traceback:
...e/mrm/V-REP_PRO_EDU_V3_6_2_Ubuntu16_04/lua/gcode.lua:208: in function 'handler'
...e/mrm/V-REP_PRO_EDU_V3_6_2_Ubuntu16_04/lua/gcode.lua:239: in function 'runLine'
...e/mrm/V-REP_PRO_EDU_V3_6_2_Ubuntu16_04/lua/gcode.lua:179: in function 'runProgram'
[string "CHILD SCRIPT GCODE"]:485: in function <[string "CHILD SCRIPT GCODE"]:3>

Kindly note that I had not many any changes in the child script or the gcode.lua file. After studying the code ( error pertaining to the lines mentioned above) and the gcode (in the threaded script), I realized that the function tonumber() in the following chunk (gcode.lua) is the source of error:

Code: Select all

 local handler=function(address,value)
	  print(value)
          print(type(value))
            self.wordNumber=self.wordNumber+1
           local valueNum=tonumber(value)
	  print(valueNum)
          print(type(valueNum))
            local f=address:upper()
--	print(f)
            local f1=f..valueNum
            print('f1= '..f1)
            if self[f1]~=nil then
                self[f1](self)
            elseif self[f]~=nil then
                self[f](self,valueNum)
            else
                log(LOG.WARN,'command '..address..valueNum..' not implemented')
            end
        end
To explain what I mean I am posting the begining and the ending of G-code for the circle:

Code: Select all

       G17 G20 G90 G94 G54
        G0 Z2.5
        ......
        G00 X0 Y0 Z2.5
The tonumber() works fine for the part from G17 to G0 i.e. type string is converted to number. However at Z2.5 it returns a nil value. To verify this, I changed Z2.5 to Z2 (in both the places)and the simulation ran alright (drawing a circle). Could you kindly advise, on how to tackle this issue?

Cheers,

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

Re: Any pointers about gcode.ttt?

Post by fferri »

What are the values of address and value?

You probably have to adjust how the runLine function parses the line to cover your case.

mohtashem
Posts: 15
Joined: 17 Apr 2017, 20:03

Re: Any pointers about gcode.ttt?

Post by mohtashem »

Hello,

Thank you so much for the reply. The values for address are the letters of the G-code (for example G from G17 or Z from Z2.5 of the type string). Similarly, the values for value are of type string for example ( 17 from G17 or 2.5 from Z2.5 )Here is the output, I obtained:
Simulation started.

Code: Select all

Simulation started.
address=G
address type=string
value=17
value type=string
valueNum=17
valueNumtype=number
...............
address=Z
address type=string
value=2.5
value type=string
Lua runtime error: ...e/mrm/V-REP_PRO_EDU_V3_6_2_Ubuntu16_04/lua/gcode.lua:212: attempt to concatenate local 'valueNum' (a nil value)
stack traceback:
	...e/mrm/V-REP_PRO_EDU_V3_6_2_Ubuntu16_04/lua/gcode.lua:212: in function 'handler'
	...e/mrm/V-REP_PRO_EDU_V3_6_2_Ubuntu16_04/lua/gcode.lua:249: in function 'runLine'
	...e/mrm/V-REP_PRO_EDU_V3_6_2_Ubuntu16_04/lua/gcode.lua:179: in function 'runProgram'
	[string "CHILD SCRIPT GCODE"]:485: in function <[string "CHILD SCRIPT GCODE"]:3>
It's just that the string resembling a number with a decimal i.e 2.5 or 0.2 etc is not converted by tonumber()

Cheers,

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

Re: Any pointers about gcode.ttt?

Post by fferri »

The string "2.5" doesn't seem to give a problem here:

Code: Select all

$ lua
Lua 5.1.5  Copyright (C) 1994-2012 Lua.org, PUC-Rio
> x=tonumber('2.5')
> print(x)
2.5
> print(type(x))
number
Tested also in the V-REP's Lua interpreter (LuaCommander plugin):

Code: Select all

Simulator launched, welcome!
> x=tonumber('2.5') 
> x 
2.5 
> type(x) 
"number" 

mohtashem
Posts: 15
Joined: 17 Apr 2017, 20:03

Re: Any pointers about gcode.ttt?

Post by mohtashem »

Hello,

Regarding this, there is no problem as I got similar output as yours:
$ lua
Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio
> x=tonumber('2.5')
> print(x)
2.5
> print(type(x))
number
However, in the V-REP's Lua interpreter (LuaCommander plugin), this is what I get:

Code: Select all

Simulator launched, welcome!
(for quick customizations, edit the sandbox script system/sndbxscpt.txt) 
> x = tonumber('2.5') 
> x 
nil 
> type(x) 
"nil"
 
Since you mentioned LuaCommander plugin, this is what I get on Starting V-REP in the Ubuntu terminal:

Code: Select all

Plugin 'LuaCommander': loading...
Plugin 'LuaCommander': warning: replaced variable 'simLuaCmd'
Plugin 'LuaCommander': load succeeded.
Forgive me for the stupid question, but could this warning have something to do with my LuaCommander plugin behaving as such? Any suggestions are welcome.

Cheers!

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

Re: Any pointers about gcode.ttt?

Post by fferri »

mohtashem wrote:
07 Oct 2019, 10:52
Forgive me for the stupid question, but could this warning have something to do with my LuaCommander plugin behaving as such?
no

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

Re: Any pointers about gcode.ttt?

Post by fferri »

Probably it's an issue with your locale.

Try executing os.setlocale'C' before anything else.

Post Reply