gpt4 book ai didi

ruby - 在 'require' 加载错误

转载 作者:太空宇宙 更新时间:2023-11-03 16:28:10 25 4
gpt4 key购买 nike

我正在尝试运行一个为 sphero(版本 2.0.0)启用跳跃运动的 Ruby 文件。当我尝试从 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>'

谁能帮帮我?

最佳答案

我遇到了同样的问题并运行它修复了它。

sudo gem install em-websocket

关于ruby - 在 'require' 加载错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20879318/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com