我正在尝试运行一个Ruby文件,为sphero启用跳跃运动(版本2.0.0)。当我尝试从cmd运行时,我遇到了加载错误的麻烦。
ruby文件的代码:
require 'em-websocket'
require 'sphero'
Sphero.start "/dev/tty.Sphero-RWP-AMP-SPP" do |s|
puts "Connected to Sphero!"
sleep 1
3.times do
begin
s.color 'green'
rescue
end
end
keep_going 1
s.color 'black'
calibration = 0
EM.run {
EM::WebSocket.run(:host => "0.0.0.0", :port => 8080) do |ws|
mutex_sphero = Mutex.new
mutex_req = Mutex.new
req = nil
ws.onopen { |handshake|
puts "WebSocket connection open"
}
ws.onclose { puts "Connection closed" }
ws.onmessage { |msg|
puts "Recieved message: #{msg}"
if msg == 'start'
mutex_sphero.synchronize { s.color 'blue', true }
elsif msg == 'stop'
mutex_sphero.synchronize {
s.color 'black', true
stop
mutex_req.synchronize { req = nil }
}
elsif msg == 'calibrate+' or msg == 'calibrate-'
mutex_sphero.synchronize {
s.color 'black'
s.back_led_output = 0xff
calibration = (calibration + (msg == "calibrate+" ? 15 : 360-15)) % 360
puts "calibration = #{calibration}"
s.roll 0, calibration
}
EM.cancel_timer(@calib_timer) if @calib_timer
@calib_timer = EM.add_timer(3) do
mutex_sphero.synchronize { s.back_led_output = 0 }
end
else
data = msg.split(',').map {|d| d.to_i }
speed = [Math.sqrt(data[0]**2 + data[1]**2)*20, 0xff].min.to_i
deg = Math.atan2(data[0], data[1]) / Math::PI * 180
deg = (deg + calibration + 360) % 360
p [speed, deg.to_i]
mutex_req.synchronize { req = [speed, deg.to_i] }
EM.defer do
mutex_sphero.synchronize do
r = nil
mutex_req.synchronize { r, req = req, r }
s.roll *r if r
end
end
}
end
}
end
这是错误:
C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:53;in 'require' cannot load such file -- C:\Ruby200\lib\ruby\gems\2.0.0\gems\em-websocket.gem <LoadError>
from C:/Ruby200/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:53:in 'require'
from websocket-sphero.rb:3:in '<main>'
任何人都可以帮助我吗?
答案 0 :(得分:1)
I had the same issue and running this fixed it.
sudo gem install em-websocket