Class: Crubyflie::Commander

Inherits:
Object
  • Object
show all
Defined in:
lib/crubyflie/crazyflie/commander.rb

Overview

The Commander facility is used to send control information to the Crazyflie. You want to use this class to fly your Crazyflie

Instance Method Summary collapse

Constructor Details

#initialize(crazyflie) ⇒ Commander

Initialize the facility


24
25
26
# File 'lib/crubyflie/crazyflie/commander.rb', line 24

def initialize(crazyflie)
    @crazyflie = crazyflie
end

Instance Method Details

#send_setpoint(roll, pitch, yaw, thrust, xmode = false) ⇒ Object

Send a setpoint to the Crazyflie

The roll, pitch, yaw values are floats with positive or negative values. The range should be the value read from the controller ([-1,1]) multiplied by the maximum angle change rate

Parameters:

  • roll (float)

    the roll value

  • pitch (float)

    the pitch value

  • yaw (float)

    the yaw value

  • thrust (Integer)

    thrust is an integer value ranging from 10001 (next to no power) to 60000 (full power)


39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/crubyflie/crazyflie/commander.rb', line 39

def send_setpoint(roll, pitch, yaw, thrust, xmode=false)
    if xmode
        roll = 0.707 * (roll - pitch)
        pitch = 0.707 * (roll + pitch)
    end

    packet = CRTPPacket.new()
    packet.modify_header(nil, Crazyflie::CRTP_PORTS[:commander], nil)
    data = [roll, -pitch, yaw, thrust]
    # send 3 floats and one unsigned short (16 bits) (all little endian)
    data = data.pack('eeeS<')
    packet.data = data.unpack('C*')
    @crazyflie.send_packet(packet, false)
end