tp_plus 0.0.77 → 0.0.87
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +87 -84
- data/Rakefile +35 -35
- data/bin/tpp +92 -92
- data/lib/tp_plus/interpreter.rb +152 -152
- data/lib/tp_plus/namespace.rb +66 -66
- data/lib/tp_plus/nodes/abort_node.rb +9 -9
- data/lib/tp_plus/nodes/acc_node.rb +19 -19
- data/lib/tp_plus/nodes/address_node.rb +22 -22
- data/lib/tp_plus/nodes/argument_node.rb +20 -20
- data/lib/tp_plus/nodes/assignment_node.rb +52 -45
- data/lib/tp_plus/nodes/base_node.rb +9 -0
- data/lib/tp_plus/nodes/call_node.rb +34 -34
- data/lib/tp_plus/nodes/case_condition_node.rb +26 -26
- data/lib/tp_plus/nodes/case_node.rb +33 -33
- data/lib/tp_plus/nodes/comment_node.rb +18 -22
- data/lib/tp_plus/nodes/conditional_node.rb +60 -60
- data/lib/tp_plus/nodes/definition_node.rb +22 -22
- data/lib/tp_plus/nodes/digit_node.rb +22 -22
- data/lib/tp_plus/nodes/empty_stmt_node.rb +9 -9
- data/lib/tp_plus/nodes/eval_node.rb +13 -13
- data/lib/tp_plus/nodes/expression_node.rb +68 -68
- data/lib/tp_plus/nodes/for_node.rb +20 -20
- data/lib/tp_plus/nodes/header_node.rb +27 -27
- data/lib/tp_plus/nodes/indirect_node.rb +27 -51
- data/lib/tp_plus/nodes/inline_conditional_node.rb +36 -40
- data/lib/tp_plus/nodes/io_method_node.rb +55 -55
- data/lib/tp_plus/nodes/io_node.rb +31 -31
- data/lib/tp_plus/nodes/jpos_node.rb +13 -0
- data/lib/tp_plus/nodes/jump_node.rb +23 -23
- data/lib/tp_plus/nodes/label_definition_node.rb +21 -21
- data/lib/tp_plus/nodes/lpos_node.rb +13 -0
- data/lib/tp_plus/nodes/motion_node.rb +62 -62
- data/lib/tp_plus/nodes/namespace_node.rb +16 -16
- data/lib/tp_plus/nodes/namespaced_var_node.rb +38 -38
- data/lib/tp_plus/nodes/numreg_node.rb +26 -26
- data/lib/tp_plus/nodes/offset_node.rb +27 -27
- data/lib/tp_plus/nodes/operator_node.rb +80 -78
- data/lib/tp_plus/nodes/paren_expression_node.rb +17 -17
- data/lib/tp_plus/nodes/pause_node.rb +9 -9
- data/lib/tp_plus/nodes/position_data_node.rb +66 -66
- data/lib/tp_plus/nodes/position_node.rb +26 -26
- data/lib/tp_plus/nodes/posreg_node.rb +64 -64
- data/lib/tp_plus/nodes/raise_node.rb +13 -13
- data/lib/tp_plus/nodes/real_node.rb +27 -27
- data/lib/tp_plus/nodes/return_node.rb +9 -0
- data/lib/tp_plus/nodes/set_skip_node.rb +14 -14
- data/lib/tp_plus/nodes/skip_node.rb +22 -22
- data/lib/tp_plus/nodes/speed_node.rb +29 -29
- data/lib/tp_plus/nodes/string_node.rb +13 -13
- data/lib/tp_plus/nodes/string_register_node.rb +26 -26
- data/lib/tp_plus/nodes/termination_node.rb +23 -23
- data/lib/tp_plus/nodes/terminator_node.rb +16 -16
- data/lib/tp_plus/nodes/time_node.rb +24 -24
- data/lib/tp_plus/nodes/timer_method_node.rb +33 -37
- data/lib/tp_plus/nodes/timer_node.rb +16 -16
- data/lib/tp_plus/nodes/unary_expression_node.rb +39 -0
- data/lib/tp_plus/nodes/units_node.rb +20 -20
- data/lib/tp_plus/nodes/use_node.rb +21 -21
- data/lib/tp_plus/nodes/user_alarm_node.rb +16 -16
- data/lib/tp_plus/nodes/var_method_node.rb +23 -23
- data/lib/tp_plus/nodes/var_node.rb +39 -39
- data/lib/tp_plus/nodes/vision_register_node.rb +22 -22
- data/lib/tp_plus/nodes/wait_for_node.rb +50 -54
- data/lib/tp_plus/nodes/wait_until_node.rb +61 -65
- data/lib/tp_plus/nodes/while_node.rb +40 -42
- data/lib/tp_plus/parser.rb +1749 -1697
- data/lib/tp_plus/scanner.rb +295 -295
- data/lib/tp_plus/token.rb +101 -98
- data/lib/tp_plus/version.rb +3 -3
- data/lib/tp_plus.rb +72 -67
- data/test/test_helper.rb +5 -5
- data/test/tp_plus/test_interpreter.rb +1372 -1329
- data/test/tp_plus/test_parser.rb +502 -502
- data/test/tp_plus/test_scanner.rb +591 -577
- data/tp_plus.gemspec +31 -31
- metadata +8 -3
@@ -1,20 +1,20 @@
|
|
1
|
-
module TPPlus
|
2
|
-
module Nodes
|
3
|
-
class ForNode
|
4
|
-
def initialize(var_node, initial_value_node, final_value_node, block)
|
5
|
-
@var_node = var_node
|
6
|
-
@initial_value_node = initial_value_node
|
7
|
-
@final_value_node = final_value_node
|
8
|
-
@block = block.flatten.reject {|n| n.is_a?(TerminatorNode) }
|
9
|
-
end
|
10
|
-
|
11
|
-
def block(context)
|
12
|
-
@s ||= @block.inject("") {|s,n| s << "#{n.eval(context)} ;\n" }
|
13
|
-
end
|
14
|
-
|
15
|
-
def eval(context)
|
16
|
-
"FOR #{@var_node.eval(context)}=#{@initial_value_node.eval(context)} TO #{@final_value_node.eval(context)} ;\n#{block(context)}ENDFOR"
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
1
|
+
module TPPlus
|
2
|
+
module Nodes
|
3
|
+
class ForNode < BaseNode
|
4
|
+
def initialize(var_node, initial_value_node, final_value_node, block)
|
5
|
+
@var_node = var_node
|
6
|
+
@initial_value_node = initial_value_node
|
7
|
+
@final_value_node = final_value_node
|
8
|
+
@block = block.flatten.reject {|n| n.is_a?(TerminatorNode) }
|
9
|
+
end
|
10
|
+
|
11
|
+
def block(context)
|
12
|
+
@s ||= @block.inject("") {|s,n| s << "#{n.eval(context)} ;\n" }
|
13
|
+
end
|
14
|
+
|
15
|
+
def eval(context)
|
16
|
+
"FOR #{@var_node.eval(context)}=#{@initial_value_node.eval(context)} TO #{@final_value_node.eval(context)} ;\n#{block(context)}ENDFOR"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -1,27 +1,27 @@
|
|
1
|
-
module TPPlus
|
2
|
-
module Nodes
|
3
|
-
class HeaderNode
|
4
|
-
def initialize(type, value)
|
5
|
-
@type = type
|
6
|
-
@value = value
|
7
|
-
end
|
8
|
-
|
9
|
-
def eval(context, options={})
|
10
|
-
case @type
|
11
|
-
when "TP_IGNORE_PAUSE"
|
12
|
-
context.header_data[:ignore_pause] = @value
|
13
|
-
when "TP_COMMENT"
|
14
|
-
context.header_data[:comment] = @value
|
15
|
-
when "TP_GROUPMASK"
|
16
|
-
context.header_data[:group_mask] = @value
|
17
|
-
when "TP_SUBTYPE"
|
18
|
-
context.header_data[:subtype] = @value.to_sym
|
19
|
-
else
|
20
|
-
raise "Unsupported TP Header value (#{@type})"
|
21
|
-
end
|
22
|
-
|
23
|
-
nil
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
1
|
+
module TPPlus
|
2
|
+
module Nodes
|
3
|
+
class HeaderNode < BaseNode
|
4
|
+
def initialize(type, value)
|
5
|
+
@type = type
|
6
|
+
@value = value
|
7
|
+
end
|
8
|
+
|
9
|
+
def eval(context, options={})
|
10
|
+
case @type
|
11
|
+
when "TP_IGNORE_PAUSE"
|
12
|
+
context.header_data[:ignore_pause] = @value
|
13
|
+
when "TP_COMMENT"
|
14
|
+
context.header_data[:comment] = @value
|
15
|
+
when "TP_GROUPMASK"
|
16
|
+
context.header_data[:group_mask] = @value
|
17
|
+
when "TP_SUBTYPE"
|
18
|
+
context.header_data[:subtype] = @value.to_sym
|
19
|
+
else
|
20
|
+
raise "Unsupported TP Header value (#{@type})"
|
21
|
+
end
|
22
|
+
|
23
|
+
nil
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -1,51 +1,27 @@
|
|
1
|
-
module TPPlus
|
2
|
-
module Nodes
|
3
|
-
class IndirectNode
|
4
|
-
def initialize(type, target)
|
5
|
-
@type
|
6
|
-
@target = target
|
7
|
-
end
|
8
|
-
|
9
|
-
def
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
"
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
def requires_mixed_logic?(context)
|
31
|
-
case @type
|
32
|
-
when :flag#, :timer
|
33
|
-
true
|
34
|
-
else
|
35
|
-
false
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def eval(context,options={})
|
40
|
-
s = "#{string}[#{@target.eval(context)}]"
|
41
|
-
if options[:opposite]
|
42
|
-
s = "!#{s}"
|
43
|
-
end
|
44
|
-
if options[:as_condition]
|
45
|
-
s = "(#{s})"
|
46
|
-
end
|
47
|
-
s
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
1
|
+
module TPPlus
|
2
|
+
module Nodes
|
3
|
+
class IndirectNode < BaseNode
|
4
|
+
def initialize(type, target)
|
5
|
+
@type = type
|
6
|
+
@target = target
|
7
|
+
end
|
8
|
+
|
9
|
+
def requires_mixed_logic?(context)
|
10
|
+
return true if @type == :f
|
11
|
+
|
12
|
+
false
|
13
|
+
end
|
14
|
+
|
15
|
+
def eval(context,options={})
|
16
|
+
s = "#{@type.upcase}[#{@target.eval(context)}]"
|
17
|
+
if options[:opposite]
|
18
|
+
s = "!#{s}"
|
19
|
+
end
|
20
|
+
if options[:as_condition]
|
21
|
+
s = "(#{s})"
|
22
|
+
end
|
23
|
+
s
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -1,40 +1,36 @@
|
|
1
|
-
module TPPlus
|
2
|
-
module Nodes
|
3
|
-
class InlineConditionalNode
|
4
|
-
attr_reader :condition_node
|
5
|
-
def initialize(type, condition, block)
|
6
|
-
@type = type
|
7
|
-
@condition_node = condition
|
8
|
-
@block = block
|
9
|
-
end
|
10
|
-
|
11
|
-
def condition_requires_mixed_logic?(context)
|
12
|
-
@condition_node.is_a?(VarNode) ||
|
13
|
-
@condition_node.is_a?(NamespacedVarNode) ||
|
14
|
-
@condition_node.requires_mixed_logic?(context)
|
15
|
-
end
|
16
|
-
|
17
|
-
def block_requires_mixed_logic?(context)
|
18
|
-
@block.requires_mixed_logic?(context)
|
19
|
-
end
|
20
|
-
|
21
|
-
def
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
1
|
+
module TPPlus
|
2
|
+
module Nodes
|
3
|
+
class InlineConditionalNode < BaseNode
|
4
|
+
attr_reader :condition_node
|
5
|
+
def initialize(type, condition, block)
|
6
|
+
@type = type
|
7
|
+
@condition_node = condition
|
8
|
+
@block = block
|
9
|
+
end
|
10
|
+
|
11
|
+
def condition_requires_mixed_logic?(context)
|
12
|
+
@condition_node.is_a?(VarNode) ||
|
13
|
+
@condition_node.is_a?(NamespacedVarNode) ||
|
14
|
+
@condition_node.requires_mixed_logic?(context)
|
15
|
+
end
|
16
|
+
|
17
|
+
def block_requires_mixed_logic?(context)
|
18
|
+
@block.requires_mixed_logic?(context)
|
19
|
+
end
|
20
|
+
|
21
|
+
def condition(context,options={})
|
22
|
+
options[:opposite] ||= @type == "unless"
|
23
|
+
|
24
|
+
if condition_requires_mixed_logic?(context) || block_requires_mixed_logic?(context)
|
25
|
+
"(#{@condition_node.eval(context, options)})"
|
26
|
+
else
|
27
|
+
@condition_node.eval(context, options)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def eval(context)
|
32
|
+
"IF #{condition(context)},#{@block.eval(context,mixed_logic:true)}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -1,55 +1,55 @@
|
|
1
|
-
module TPPlus
|
2
|
-
module Nodes
|
3
|
-
class IOMethodNode
|
4
|
-
def initialize(method, target,options={})
|
5
|
-
@method = method
|
6
|
-
@target = target
|
7
|
-
@init_options = options
|
8
|
-
end
|
9
|
-
|
10
|
-
def requires_mixed_logic?(context)
|
11
|
-
true
|
12
|
-
end
|
13
|
-
|
14
|
-
def can_be_inlined?
|
15
|
-
true
|
16
|
-
end
|
17
|
-
|
18
|
-
def on_off(value,options={})
|
19
|
-
options[:mixed_logic] ? "(#{value})" : value
|
20
|
-
end
|
21
|
-
|
22
|
-
def pulse_time(context)
|
23
|
-
"%.1f" % case @init_options[:pulse_units]
|
24
|
-
when "s"
|
25
|
-
@init_options[:pulse_time].eval(context)
|
26
|
-
when "ms"
|
27
|
-
@init_options[:pulse_time].eval(context).to_f / 1000
|
28
|
-
else
|
29
|
-
raise "Invalid pulse units"
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def pulse_extra(context)
|
34
|
-
return "" if @init_options[:pulse_time].nil?
|
35
|
-
|
36
|
-
",#{pulse_time(context)}sec"
|
37
|
-
end
|
38
|
-
|
39
|
-
def eval(context,options={})
|
40
|
-
options[:mixed_logic] = true if @target.requires_mixed_logic?(context)
|
41
|
-
|
42
|
-
case @method
|
43
|
-
when "turn_on"
|
44
|
-
"#{@target.eval(context)}=#{on_off("ON",options)}"
|
45
|
-
when "turn_off"
|
46
|
-
"#{@target.eval(context)}=#{on_off("OFF",options)}"
|
47
|
-
when "toggle"
|
48
|
-
"#{@target.eval(context)}=(!#{@target.eval(context)})"
|
49
|
-
when "pulse"
|
50
|
-
"#{@target.eval(context)}=PULSE#{pulse_extra(context)}"
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
1
|
+
module TPPlus
|
2
|
+
module Nodes
|
3
|
+
class IOMethodNode < BaseNode
|
4
|
+
def initialize(method, target,options={})
|
5
|
+
@method = method
|
6
|
+
@target = target
|
7
|
+
@init_options = options
|
8
|
+
end
|
9
|
+
|
10
|
+
def requires_mixed_logic?(context)
|
11
|
+
true
|
12
|
+
end
|
13
|
+
|
14
|
+
def can_be_inlined?
|
15
|
+
true
|
16
|
+
end
|
17
|
+
|
18
|
+
def on_off(value,options={})
|
19
|
+
options[:mixed_logic] ? "(#{value})" : value
|
20
|
+
end
|
21
|
+
|
22
|
+
def pulse_time(context)
|
23
|
+
"%.1f" % case @init_options[:pulse_units]
|
24
|
+
when "s"
|
25
|
+
@init_options[:pulse_time].eval(context)
|
26
|
+
when "ms"
|
27
|
+
@init_options[:pulse_time].eval(context).to_f / 1000
|
28
|
+
else
|
29
|
+
raise "Invalid pulse units"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def pulse_extra(context)
|
34
|
+
return "" if @init_options[:pulse_time].nil?
|
35
|
+
|
36
|
+
",#{pulse_time(context)}sec"
|
37
|
+
end
|
38
|
+
|
39
|
+
def eval(context,options={})
|
40
|
+
options[:mixed_logic] = true if @target.requires_mixed_logic?(context)
|
41
|
+
|
42
|
+
case @method
|
43
|
+
when "turn_on"
|
44
|
+
"#{@target.eval(context)}=#{on_off("ON",options)}"
|
45
|
+
when "turn_off"
|
46
|
+
"#{@target.eval(context)}=#{on_off("OFF",options)}"
|
47
|
+
when "toggle"
|
48
|
+
"#{@target.eval(context)}=(!#{@target.eval(context)})"
|
49
|
+
when "pulse"
|
50
|
+
"#{@target.eval(context)}=PULSE#{pulse_extra(context)}"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -1,31 +1,31 @@
|
|
1
|
-
module TPPlus
|
2
|
-
module Nodes
|
3
|
-
class IONode
|
4
|
-
attr_accessor :comment
|
5
|
-
attr_reader :id
|
6
|
-
def initialize(type, id)
|
7
|
-
@type = type
|
8
|
-
@id = id.to_i
|
9
|
-
@comment = ""
|
10
|
-
end
|
11
|
-
|
12
|
-
def requires_mixed_logic?(context)
|
13
|
-
["F","SO","SI","DI"].include?(@type) ? true : false
|
14
|
-
end
|
15
|
-
|
16
|
-
def result
|
17
|
-
"#{@type}[#{@id}:#{@comment}]"
|
18
|
-
end
|
19
|
-
|
20
|
-
def eval(context, options={})
|
21
|
-
s = result
|
22
|
-
|
23
|
-
if options[:disable_mixed_logic]
|
24
|
-
s = "#{s}=ON"
|
25
|
-
end
|
26
|
-
|
27
|
-
options[:force_parens] ? "(#{s})" : s
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
1
|
+
module TPPlus
|
2
|
+
module Nodes
|
3
|
+
class IONode < BaseNode
|
4
|
+
attr_accessor :comment
|
5
|
+
attr_reader :id
|
6
|
+
def initialize(type, id)
|
7
|
+
@type = type
|
8
|
+
@id = id.to_i
|
9
|
+
@comment = ""
|
10
|
+
end
|
11
|
+
|
12
|
+
def requires_mixed_logic?(context)
|
13
|
+
["F","SO","SI","DI"].include?(@type) ? true : false
|
14
|
+
end
|
15
|
+
|
16
|
+
def result
|
17
|
+
"#{@type}[#{@id}:#{@comment}]"
|
18
|
+
end
|
19
|
+
|
20
|
+
def eval(context, options={})
|
21
|
+
s = result
|
22
|
+
|
23
|
+
if options[:disable_mixed_logic]
|
24
|
+
s = "#{s}=ON"
|
25
|
+
end
|
26
|
+
|
27
|
+
options[:force_parens] ? "(#{s})" : s
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -1,23 +1,23 @@
|
|
1
|
-
module TPPlus
|
2
|
-
module Nodes
|
3
|
-
class JumpNode
|
4
|
-
def initialize(identifier)
|
5
|
-
@identifier = identifier
|
6
|
-
end
|
7
|
-
|
8
|
-
def requires_mixed_logic?(context)
|
9
|
-
false
|
10
|
-
end
|
11
|
-
|
12
|
-
def can_be_inlined?
|
13
|
-
true
|
14
|
-
end
|
15
|
-
|
16
|
-
def eval(context,options={})
|
17
|
-
raise "Label (#{@identifier}) not found" if context.labels[@identifier.to_sym].nil?
|
18
|
-
|
19
|
-
"JMP LBL[#{context.labels[@identifier.to_sym]}]"
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
1
|
+
module TPPlus
|
2
|
+
module Nodes
|
3
|
+
class JumpNode < BaseNode
|
4
|
+
def initialize(identifier)
|
5
|
+
@identifier = identifier
|
6
|
+
end
|
7
|
+
|
8
|
+
def requires_mixed_logic?(context)
|
9
|
+
false
|
10
|
+
end
|
11
|
+
|
12
|
+
def can_be_inlined?
|
13
|
+
true
|
14
|
+
end
|
15
|
+
|
16
|
+
def eval(context,options={})
|
17
|
+
raise "Label (#{@identifier}) not found" if context.labels[@identifier.to_sym].nil?
|
18
|
+
|
19
|
+
"JMP LBL[#{context.labels[@identifier.to_sym]}]"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -1,21 +1,21 @@
|
|
1
|
-
module TPPlus
|
2
|
-
module Nodes
|
3
|
-
class LabelDefinitionNode
|
4
|
-
attr_reader :identifier
|
5
|
-
def initialize(identifier)
|
6
|
-
@identifier = identifier
|
7
|
-
end
|
8
|
-
|
9
|
-
def long_identifier_comment(context)
|
10
|
-
return "" unless @identifier.length > 16
|
11
|
-
|
12
|
-
" ;\n! #{@identifier}"
|
13
|
-
end
|
14
|
-
|
15
|
-
def eval(context)
|
16
|
-
#context.add_label(@identifier)
|
17
|
-
"LBL[#{context.labels[@identifier.to_sym]}:#{@identifier[0,16]}]#{long_identifier_comment(context)}"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
1
|
+
module TPPlus
|
2
|
+
module Nodes
|
3
|
+
class LabelDefinitionNode < BaseNode
|
4
|
+
attr_reader :identifier
|
5
|
+
def initialize(identifier)
|
6
|
+
@identifier = identifier
|
7
|
+
end
|
8
|
+
|
9
|
+
def long_identifier_comment(context)
|
10
|
+
return "" unless @identifier.length > 16
|
11
|
+
|
12
|
+
" ;\n! #{@identifier}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def eval(context)
|
16
|
+
#context.add_label(@identifier)
|
17
|
+
"LBL[#{context.labels[@identifier.to_sym]}:#{@identifier[0,16]}]#{long_identifier_comment(context)}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -1,62 +1,62 @@
|
|
1
|
-
module TPPlus
|
2
|
-
module Nodes
|
3
|
-
class MotionNode
|
4
|
-
def initialize(type, destination, modifiers)
|
5
|
-
@type = type
|
6
|
-
@destination = destination
|
7
|
-
@modifiers = modifiers
|
8
|
-
end
|
9
|
-
|
10
|
-
def prefix
|
11
|
-
case @type
|
12
|
-
when "linear_move"
|
13
|
-
"L"
|
14
|
-
when "joint_move"
|
15
|
-
"J"
|
16
|
-
when "circular_move"
|
17
|
-
"C"
|
18
|
-
else
|
19
|
-
raise "Unsupported motion"
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def speed_node
|
24
|
-
@speed_node ||= @modifiers.select {|m| m.is_a? SpeedNode }.first
|
25
|
-
end
|
26
|
-
|
27
|
-
def termination_node
|
28
|
-
@termination_node ||= @modifiers.select {|m| m.is_a? TerminationNode }.first
|
29
|
-
end
|
30
|
-
|
31
|
-
def actual_modifiers
|
32
|
-
@actual_modifiers ||= @modifiers.reject {|m| m.is_a? SpeedNode}.reject {|m| m.is_a? TerminationNode }
|
33
|
-
end
|
34
|
-
|
35
|
-
def modifiers_string(context)
|
36
|
-
return "" unless actual_modifiers.any?
|
37
|
-
|
38
|
-
strings_array = [""] << actual_modifiers.map { |m| m.eval(context) }
|
39
|
-
@modifiers_string = strings_array.join(" ")
|
40
|
-
end
|
41
|
-
|
42
|
-
def speed_valid?(context)
|
43
|
-
case @type
|
44
|
-
when "linear_move"
|
45
|
-
return true if speed_node.eval(context) == "max_speed"
|
46
|
-
|
47
|
-
["mm/sec"].include? speed_node.units
|
48
|
-
when "joint_move"
|
49
|
-
return false if speed_node.eval(context) == "max_speed"
|
50
|
-
|
51
|
-
["%"].include? speed_node.units
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def eval(context)
|
56
|
-
raise "Speed is invalid for motion type" unless speed_valid?(context)
|
57
|
-
|
58
|
-
"#{prefix} #{@destination.eval(context)} #{speed_node.eval(context)} #{termination_node.eval(context)}#{modifiers_string(context)}"
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
1
|
+
module TPPlus
|
2
|
+
module Nodes
|
3
|
+
class MotionNode < BaseNode
|
4
|
+
def initialize(type, destination, modifiers)
|
5
|
+
@type = type
|
6
|
+
@destination = destination
|
7
|
+
@modifiers = modifiers
|
8
|
+
end
|
9
|
+
|
10
|
+
def prefix
|
11
|
+
case @type
|
12
|
+
when "linear_move"
|
13
|
+
"L"
|
14
|
+
when "joint_move"
|
15
|
+
"J"
|
16
|
+
when "circular_move"
|
17
|
+
"C"
|
18
|
+
else
|
19
|
+
raise "Unsupported motion"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def speed_node
|
24
|
+
@speed_node ||= @modifiers.select {|m| m.is_a? SpeedNode }.first
|
25
|
+
end
|
26
|
+
|
27
|
+
def termination_node
|
28
|
+
@termination_node ||= @modifiers.select {|m| m.is_a? TerminationNode }.first
|
29
|
+
end
|
30
|
+
|
31
|
+
def actual_modifiers
|
32
|
+
@actual_modifiers ||= @modifiers.reject {|m| m.is_a? SpeedNode}.reject {|m| m.is_a? TerminationNode }
|
33
|
+
end
|
34
|
+
|
35
|
+
def modifiers_string(context)
|
36
|
+
return "" unless actual_modifiers.any?
|
37
|
+
|
38
|
+
strings_array = [""] << actual_modifiers.map { |m| m.eval(context) }
|
39
|
+
@modifiers_string = strings_array.join(" ")
|
40
|
+
end
|
41
|
+
|
42
|
+
def speed_valid?(context)
|
43
|
+
case @type
|
44
|
+
when "linear_move"
|
45
|
+
return true if speed_node.eval(context) == "max_speed"
|
46
|
+
|
47
|
+
["mm/sec"].include? speed_node.units
|
48
|
+
when "joint_move"
|
49
|
+
return false if speed_node.eval(context) == "max_speed"
|
50
|
+
|
51
|
+
["%"].include? speed_node.units
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def eval(context)
|
56
|
+
raise "Speed is invalid for motion type" unless speed_valid?(context)
|
57
|
+
|
58
|
+
"#{prefix} #{@destination.eval(context)} #{speed_node.eval(context)} #{termination_node.eval(context)}#{modifiers_string(context)}"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|