Class: Artoo::Drivers::Crazyflie

Inherits:
Driver
  • Object
show all
Defined in:
lib/artoo/drivers/crazyflie.rb

Overview

The crazyflie driver behaviors

Constant Summary collapse

COMMANDS =
[:start, :stop, :hover, :land, :take_off, :emergency, 
:up, :down, :left, :right, :forward, :backward, 
:turn_left, :turn_right, :power].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Crazyflie

Returns a new instance of Crazyflie.


14
15
16
17
18
19
20
21
22
# File 'lib/artoo/drivers/crazyflie.rb', line 14

def initialize(params={})
  @roll = 0
  @pitch = 0
  @yaw = 0
  @thrust = 0
  @xmode = false # TODO what is this?
  @hover_mode = 0
  super
end

Instance Attribute Details

#hover_modeObject (readonly)

Returns the value of attribute hover_mode


12
13
14
# File 'lib/artoo/drivers/crazyflie.rb', line 12

def hover_mode
  @hover_mode
end

#pitchObject (readonly)

Returns the value of attribute pitch


12
13
14
# File 'lib/artoo/drivers/crazyflie.rb', line 12

def pitch
  @pitch
end

#rollObject (readonly)

Returns the value of attribute roll


12
13
14
# File 'lib/artoo/drivers/crazyflie.rb', line 12

def roll
  @roll
end

#thrustObject (readonly)

Returns the value of attribute thrust


12
13
14
# File 'lib/artoo/drivers/crazyflie.rb', line 12

def thrust
  @thrust
end

#xmodeObject (readonly)

Returns the value of attribute xmode


12
13
14
# File 'lib/artoo/drivers/crazyflie.rb', line 12

def xmode
  @xmode
end

#yawObject (readonly)

Returns the value of attribute yaw


12
13
14
# File 'lib/artoo/drivers/crazyflie.rb', line 12

def yaw
  @yaw
end

Instance Method Details

#backward(deg) ⇒ Object


87
88
89
# File 'lib/artoo/drivers/crazyflie.rb', line 87

def backward(deg)
  @pitch = -deg
end

#forward(deg) ⇒ Object


83
84
85
# File 'lib/artoo/drivers/crazyflie.rb', line 83

def forward(deg)
  @pitch = deg
end

#hover(h = :start) ⇒ Object


51
52
53
54
55
56
57
58
59
# File 'lib/artoo/drivers/crazyflie.rb', line 51

def hover(h=:start)
  if h == :start
    @hover_mode = 1
    set_thrust_hover
  else
    @hover_mode = 0
    set_thrust_off
  end
end

#land(secs = 1) ⇒ Object


61
62
63
64
65
66
67
68
# File 'lib/artoo/drivers/crazyflie.rb', line 61

def land(secs=1)
  @hover_mode = 0
  power(32000)

  after(secs) {
    power(22000)
  }
end

#left(deg) ⇒ Object


91
92
93
# File 'lib/artoo/drivers/crazyflie.rb', line 91

def left(deg)
  @roll = -deg
end

#power(deg) ⇒ Object


79
80
81
# File 'lib/artoo/drivers/crazyflie.rb', line 79

def power(deg)
  @thrust = deg
end

#right(deg) ⇒ Object


95
96
97
# File 'lib/artoo/drivers/crazyflie.rb', line 95

def right(deg)
  @roll = deg
end

#set_thrust_hoverObject


115
116
117
# File 'lib/artoo/drivers/crazyflie.rb', line 115

def set_thrust_hover
  power(32597)
end

#set_thrust_offObject


111
112
113
# File 'lib/artoo/drivers/crazyflie.rb', line 111

def set_thrust_off
  power(0)
end

#set_thrust_onObject


107
108
109
# File 'lib/artoo/drivers/crazyflie.rb', line 107

def set_thrust_on
  power(40000)
end

#startObject


39
40
41
42
43
44
45
# File 'lib/artoo/drivers/crazyflie.rb', line 39

def start
  @hover_mode = 0
  @roll = 0
  @pitch = 0
  @yaw = 0
  power(10001)
end

#start_driverObject

Start driver and any required connections


25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/artoo/drivers/crazyflie.rb', line 25

def start_driver
  begin
    every(interval) do
      send_command
    end

    super
  rescue Exception => e
    Logger.error "Error starting Crazyflie driver!"
    Logger.error e.message
    Logger.error e.backtrace.inspect
  end
end

#stopObject


47
48
49
# File 'lib/artoo/drivers/crazyflie.rb', line 47

def stop
  set_thrust_off
end

#take_off(secs = 1) ⇒ Object


70
71
72
73
74
75
76
77
# File 'lib/artoo/drivers/crazyflie.rb', line 70

def take_off(secs=1)
  forward(0)
  set_thrust_on

  after(secs) {
    power(33000)
  }
end

#turn_left(deg) ⇒ Object


99
100
101
# File 'lib/artoo/drivers/crazyflie.rb', line 99

def turn_left(deg)
  @yaw = -deg
end

#turn_right(deg) ⇒ Object


103
104
105
# File 'lib/artoo/drivers/crazyflie.rb', line 103

def turn_right(deg)
  @yaw = deg
end