Class: MSPhysics::Piston

Inherits:
Joint show all
Defined in:
RubyExtension/MSPhysics/joint_piston.rb

Overview

Since:

  • 1.0.0

Constant Summary collapse

DEFAULT_MIN =

Since:

  • 1.0.0

-10.0
DEFAULT_MAX =

Since:

  • 1.0.0

10.0
DEFAULT_LIMITS_ENABLED =

Since:

  • 1.0.0

false
DEFAULT_RATE =

Since:

  • 1.0.0

4.0
DEFAULT_POWER =

Since:

  • 1.0.0

0.0
DEFAULT_REDUCTION_RATIO =

Since:

  • 1.0.0

0.1
DEFAULT_CONTROLLER =

Since:

  • 1.0.0

nil
DEFAULT_CONTROLLER_MODE =

Since:

  • 1.0.0

0

Constants inherited from Joint

Joint::DEFAULT_BODIES_COLLIDABLE, Joint::DEFAULT_BREAKING_FORCE, Joint::DEFAULT_SOLVER_MODEL, Joint::DEFAULT_STIFFNESS

Instance Method Summary collapse

Methods inherited from Joint

#address, all_joints, #bodies_collidable=, #bodies_collidable?, #breaking_force, #breaking_force=, #child, #connect, #connected?, #destroy, #disconnect, #dof, #get_pin_matrix, #get_pin_matrix2, #get_tension1, #get_tension2, #group, joint_by_address, #name, #name=, #parent, #set_pin_matrix, #solver_model, #solver_model=, #stiffness, #stiffness=, #type, #valid?, validate, #world

Methods inherited from Entity

#inspect, #to_s

Constructor Details

#initialize(world, parent, pin_tra, group = nil) ⇒ Piston

Create a piston joint.

Parameters:

  • world (MSPhysics::World)
  • parent (MSPhysics::Body, nil)
  • pin_tra (Geom::Transformation, Array<Numeric>)

    Pin transformation in global space. Matrix origin is interpreted as the pin position. Matrix Z-axis is interpreted as the pin direction.

  • group (Sketchup::Group, Sketchup::ComponentInstance, nil) (defaults to: nil)

Since:

  • 1.0.0



22
23
24
25
26
27
28
29
30
31
32
33
# File 'RubyExtension/MSPhysics/joint_piston.rb', line 22

def initialize(world, parent, pin_tra, group = nil)
  super(world, parent, pin_tra, group)
  MSPhysics::Newton::Piston.create(@address)
  MSPhysics::Newton::Piston.set_min(@address, DEFAULT_MIN)
  MSPhysics::Newton::Piston.set_max(@address, DEFAULT_MAX)
  MSPhysics::Newton::Piston.enable_limits(@address, DEFAULT_LIMITS_ENABLED)
  MSPhysics::Newton::Piston.set_rate(@address, DEFAULT_RATE)
  MSPhysics::Newton::Piston.set_power(@address, DEFAULT_POWER)
  MSPhysics::Newton::Piston.set_reduction_ratio(@address, DEFAULT_REDUCTION_RATIO)
  MSPhysics::Newton::Piston.set_controller(@address, DEFAULT_CONTROLLER)
	  MSPhysics::Newton::Piston.set_controller_mode(@address, DEFAULT_CONTROLLER_MODE)
end

Instance Method Details

#controllerNumeric?

Get piston controller.

Returns:

  • (Numeric, nil)

    Returns one of the following values:

    • Desired position in meters if the controller mode is 0.

    • Magnitude and direction of the linear rate if controller mode is 1.

    • nil if piston is turned off.

Since:

  • 1.0.0



146
147
148
# File 'RubyExtension/MSPhysics/joint_piston.rb', line 146

def controller
  MSPhysics::Newton::Piston.get_controller(@address)
end

#controller=(value) ⇒ Object

Set piston controller.

Parameters:

  • value (Numeric, nil)

    Accepts one of the following values:

    • Desired position in meters if the controller mode is 0.

    • Magnitude and direction of the linear rate if controller mode is 1.

    • nil to turn off the piston.

Since:

  • 1.0.0



155
156
157
# File 'RubyExtension/MSPhysics/joint_piston.rb', line 155

def controller=(value)
  MSPhysics::Newton::Piston.set_controller(@address, value)
end

#controller_modeInteger

Get controller mode.

Returns:

  • (Integer)

    Returns one of the following values:

    • 0 to control piston by position.

    • 1 to control piston by speed.

Since:

  • 1.0.0



163
164
165
# File 'RubyExtension/MSPhysics/joint_piston.rb', line 163

def controller_mode
  MSPhysics::Newton::Piston.get_controller_mode(@address)
end

#controller_mode=(mode) ⇒ Object

Set controller mode.

Parameters:

  • mode (Integer)

    Pass one of the following values:

    • 0 to control piston by position.

    • 1 to control piston by speed.

Since:

  • 1.0.0



171
172
173
# File 'RubyExtension/MSPhysics/joint_piston.rb', line 171

def controller_mode=(mode)
  MSPhysics::Newton::Piston.set_controller_mode(@address, mode)
end

#cur_accelerationNumeric

Get current acceleration in meters per second per second.

Returns:

  • (Numeric)

Since:

  • 1.0.0



49
50
51
# File 'RubyExtension/MSPhysics/joint_piston.rb', line 49

def cur_acceleration
  MSPhysics::Newton::Piston.get_cur_acceleration(@address)
end

#cur_positionNumeric

Get current position in meters.

Returns:

  • (Numeric)

Since:

  • 1.0.0



37
38
39
# File 'RubyExtension/MSPhysics/joint_piston.rb', line 37

def cur_position
  MSPhysics::Newton::Piston.get_cur_position(@address)
end

#cur_velocityNumeric

Get current velocity in meters per second.

Returns:

  • (Numeric)

Since:

  • 1.0.0



43
44
45
# File 'RubyExtension/MSPhysics/joint_piston.rb', line 43

def cur_velocity
  MSPhysics::Newton::Piston.get_cur_velocity(@address)
end

#limits_enabled=(state) ⇒ Object

Enable/disable min & max position limits.

Parameters:

  • state (Boolean)

Since:

  • 1.0.0



85
86
87
# File 'RubyExtension/MSPhysics/joint_piston.rb', line 85

def limits_enabled=(state)
  MSPhysics::Newton::Piston.enable_limits(@address, state)
end

#limits_enabled?Boolean

Determine whether min & max position limits are enabled.

Returns:

  • (Boolean)

Since:

  • 1.0.0



79
80
81
# File 'RubyExtension/MSPhysics/joint_piston.rb', line 79

def limits_enabled?
  MSPhysics::Newton::Piston.limits_enabled?(@address)
end

#maxNumeric

Get maximum position in meters.

Returns:

  • (Numeric)

Since:

  • 1.0.0



67
68
69
# File 'RubyExtension/MSPhysics/joint_piston.rb', line 67

def max
  MSPhysics::Newton::Piston.get_max(@address)
end

#max=(value) ⇒ Object

Set maximum position in meters.

Parameters:

  • value (Numeric)

Since:

  • 1.0.0



73
74
75
# File 'RubyExtension/MSPhysics/joint_piston.rb', line 73

def max=(value)
  MSPhysics::Newton::Piston.set_max(@address, value)
end

#minNumeric

Get minimum position in meters.

Returns:

  • (Numeric)

Since:

  • 1.0.0



55
56
57
# File 'RubyExtension/MSPhysics/joint_piston.rb', line 55

def min
  MSPhysics::Newton::Piston.get_min(@address)
end

#min=(value) ⇒ Object

Set minimum position in meters.

Parameters:

  • value (Numeric)

Since:

  • 1.0.0



61
62
63
# File 'RubyExtension/MSPhysics/joint_piston.rb', line 61

def min=(value)
  MSPhysics::Newton::Piston.set_min(@address, value)
end

#powerNumeric

Note:

A power value of zero represents maximum power.

Get movement power in Watts.

Returns:

  • (Numeric)

    A value greater than or equal to zero.

Since:

  • 1.0.0



104
105
106
# File 'RubyExtension/MSPhysics/joint_piston.rb', line 104

def power
  MSPhysics::Newton::Piston.get_power(@address)
end

#power=(value) ⇒ Object

Note:

A power value of zero represents maximum power.

Set movement power in Watts.

Parameters:

  • value (Numeric)

    A value greater than or equal to zero.

Since:

  • 1.0.0



111
112
113
# File 'RubyExtension/MSPhysics/joint_piston.rb', line 111

def power=(value)
  MSPhysics::Newton::Piston.set_power(@address, value)
end

#rateNumeric

Get maximum linear rate in meters per second.

Returns:

  • (Numeric)

    A value greater than or equal to zero.

Since:

  • 1.0.0



91
92
93
# File 'RubyExtension/MSPhysics/joint_piston.rb', line 91

def rate
  MSPhysics::Newton::Piston.get_rate(@address)
end

#rate=(value) ⇒ Object

Set maximum linear rate in meters per second.

Parameters:

  • value (Numeric)

    A value greater than or equal to zero.

Since:

  • 1.0.0



97
98
99
# File 'RubyExtension/MSPhysics/joint_piston.rb', line 97

def rate=(value)
  MSPhysics::Newton::Piston.set_rate(@address, value)
end

#reduction_ratioNumeric

Note:

Reduction ratio is a feature that reduces linear rate of the joint when its current position nears its desired position. Linear reduction ratio starts acting upon the linear rate of the joint when the difference between the current position and the desired position of the joint is less than rate * reduction_ratio meters.

Note:

A reduction ratio of zero disables the reduction feature.

Note:

A typical reduction ratio value is 0.1.

Get linear reduction ratio.

Returns:

  • (Numeric)

    A value between 0.0 and 1.0.

Since:

  • 1.0.0



124
125
126
# File 'RubyExtension/MSPhysics/joint_piston.rb', line 124

def reduction_ratio
  MSPhysics::Newton::Piston.get_reduction_ratio(@address)
end

#reduction_ratio=(value) ⇒ Object

Note:

Reduction ratio is a feature that reduces linear rate of the joint when its current position nears its desired position. Linear reduction ratio starts acting upon the linear rate of the joint when the difference between the current position and the desired position of the joint is less than rate * reduction_ratio meters.

Note:

A reduction ratio of zero disables the reduction feature.

Note:

A typical reduction ratio value is 0.1.

Get linear reduction ratio.

Parameters:

  • value (Numeric)

    A value between 0.0 and 1.0.

Since:

  • 1.0.0



137
138
139
# File 'RubyExtension/MSPhysics/joint_piston.rb', line 137

def reduction_ratio=(value)
  MSPhysics::Newton::Piston.set_reduction_ratio(@address, value)
end