Class: Motel::MovementStrategies::Rotate

Inherits:
Motel::MovementStrategy show all
Includes:
Rotatable
Defined in:
lib/motel/movement_strategies/rotate.rb

Overview

Rotates a location around its own access at a specified speed.

Instance Attribute Summary

Attributes included from Rotatable

#rot_theta, #rot_x, #rot_y, #rot_z, #stop_angle

Attributes inherited from Motel::MovementStrategy

#step_delay

Instance Method Summary collapse

Methods included from Rotatable

#change_due_to_rotation?, #init_rotation, #rot_to_s, #rotate, #rotation_json, #valid_rotation?

Methods inherited from Motel::MovementStrategy

json_create

Constructor Details

#initialize(args = {}) ⇒ Rotate


79
80
81
82
# File 'lib/motel/movement_strategies/rotate.rb', line 79

def initialize(args = {})
  init_rotation(args)
  super(args)
end

Instance Method Details

#change?(loc) ⇒ Boolean

Return true if we should change ms due to rotation


90
91
92
# File 'lib/motel/movement_strategies/rotate.rb', line 90

def change?(loc)
  change_due_to_rotation?(loc)
end

#move(loc, elapsed_seconds) ⇒ Object

Implementation of Motel::MovementStrategy#move


95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/motel/movement_strategies/rotate.rb', line 95

def move(loc, elapsed_seconds)
  unless valid?
    ::RJR::Logger.warn \
      "rotate movement strategy (#{rot_to_s}) not valid, not proceeding with move"
    return
  end

  ::RJR::Logger.debug \
    "moving location #{loc.id} via rotate movement strategy #{rot_to_s}"

  rotate(loc, elapsed_seconds)
end

#to_json(*a) ⇒ Object

Convert movement strategy to json representation and return it


109
110
111
112
113
# File 'lib/motel/movement_strategies/rotate.rb', line 109

def to_json(*a)
  { 'json_class' => self.class.name,
    'data'       => { :step_delay => step_delay}.merge(rotation_json)
  }.to_json(*a)
end

#to_sObject

Convert movement strategy to human readable string and return it


116
117
118
# File 'lib/motel/movement_strategies/rotate.rb', line 116

def to_s
  "rotate-(#{rot_to_s})"
end

#valid?Boolean

Return boolean indicating if this movement strategy is valid


85
86
87
# File 'lib/motel/movement_strategies/rotate.rb', line 85

def valid?
  valid_rotation?
end