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
# 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?
  super
end

Instance Attribute Details

#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



67
68
69
# File 'lib/artoo/drivers/crazyflie.rb', line 67

def backward(deg)
  @pitch = -deg
end

#forward(deg) ⇒ Object



63
64
65
# File 'lib/artoo/drivers/crazyflie.rb', line 63

def forward(deg)
  @pitch = deg
end

#hoverObject



49
50
51
# File 'lib/artoo/drivers/crazyflie.rb', line 49

def hover
  # TODO: call firmware that can do this?
end

#landObject



53
54
# File 'lib/artoo/drivers/crazyflie.rb', line 53

def land
end

#left(deg) ⇒ Object



71
72
73
# File 'lib/artoo/drivers/crazyflie.rb', line 71

def left(deg)
  @roll = -deg
end

#power(deg) ⇒ Object



59
60
61
# File 'lib/artoo/drivers/crazyflie.rb', line 59

def power(deg)
  @thrust = deg
end

#right(deg) ⇒ Object



75
76
77
# File 'lib/artoo/drivers/crazyflie.rb', line 75

def right(deg)
  @roll = deg
end

#set_thrust_offObject



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

def set_thrust_off
  @thrust = 0
end

#set_thrust_onObject



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

def set_thrust_on
  @thrust = 40000
end

#startObject



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

def start
  @roll = 0
  @pitch = 0
  @yaw = 0
  @thrust = 10001
end

#start_driverObject

Start driver and any required connections



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

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



45
46
47
# File 'lib/artoo/drivers/crazyflie.rb', line 45

def stop
  set_thrust_off
end

#take_offObject



56
57
# File 'lib/artoo/drivers/crazyflie.rb', line 56

def take_off
end

#turn_left(deg) ⇒ Object



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

def turn_left(deg)
  @yaw = -deg
end

#turn_right(deg) ⇒ Object



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

def turn_right(deg)
  @yaw = deg
end