forked from dash-rai/quadcopter-dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquadcopter_dashboard.rb
71 lines (56 loc) · 1.91 KB
/
quadcopter_dashboard.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
require 'fox16'
include Fox
require_relative 'serial_io'
require_relative 'pid_group'
require_relative 'flight_controls_group'
require_relative 'control_canvas'
require_relative 'config'
class DashboardWindow < FXMainWindow
attr_accessor :flight_controls
def initialize(app)
super(app, Config::WINDOW_TITLE,
width: Config::WINDOW_WIDTH, height: Config::WINDOW_HEIGHT)
self.padLeft, self.padRight = 10, 10
self.padTop, self.padBottom = 10, 10
begin
@arduino = SerialIO.new(app, self, 20)
rescue => e
puts e
@arduino = nil
end
@flight_controls = { yaw: FXDataTarget.new(0.0),
pitch: FXDataTarget.new(0.0),
roll: FXDataTarget.new(0.0),
throttle: FXDataTarget.new(0.0) }
flight_controls_group = FXGroupBox.new(self, "Flight Controls", FRAME_RIDGE)
flight_controls_group.setFont(FXFont.new(app, "Helvetica", 18,
FONTWEIGHT_BOLD))
stab_pid_group = FXGroupBox.new(self, "Stab", FRAME_RIDGE)
stab_pid_group.setFont(FXFont.new(app, "Helvetica", 18, FONTWEIGHT_BOLD))
rate_pid_group = FXGroupBox.new(self, "Rate", FRAME_RIDGE)
rate_pid_group.setFont(FXFont.new(app, "Helvetica", 18, FONTWEIGHT_BOLD))
@flight_controls.each do |name, target|
FlightControlsGroup.new(flight_controls_group, self, name, target)
end
[:yaw, :pitch, :roll].each do |control|
PIDGroup.new(stab_pid_group, self, :stab, control)
PIDGroup.new(rate_pid_group, self, :rate, control)
end
ControlCanvas.new(self, self)
end
def writeout(command, value)
@arduino.send_output("%s %.3f" % [command, value]) if @arduino
STDOUT.puts("%s %.3f" % [command, value])
end
def create
super
show(PLACEMENT_SCREEN)
end
end
if __FILE__ == $0
FXApp.new do |app|
DashboardWindow.new(app)
app.create
app.run
end
end