ev3dev_ruby is a gem to controll sensors and motors on EV3 using Ruby on ev3dev OS.
ev3dev OS is a Debian Linux-based operating system for LEGO Mindstroms EV3.
- ev3dev OS version; ev3dev-stretch
SSH remote access to the EV3 from PC
(default ev3dev user; robot, password; maker)
$ ssh [email protected]
then
robot@ev3dev:~$ sudo apt-get update
robot@ev3dev:~$ sudo gem install ev3dev_ruby
(for OS X user; )
$ scp -r /Users/xxx/Downloads/ev3dev_ruby-master/examples [email protected]:/home/robot
There are two different ways to run the program.
robot@ev3dev:~$ cd /home/robot/examples
robot@ev3dev:~$ cd motor
robot@ev3dev:~$ ruby midiummotor.rb
robot@ev3dev:~$ cd /home/robot/examples
robot@ev3dev:~$ cd motor
robot@ev3dev:~$ ls -l
...
-rw-r--r-- 1 robot robot 474 Jan 18 16:18 midiummotor.rb
...
robot@ev3dev:~$ chmod +x midiummotor.rb
robot@ev3dev:~$ ls -l
...
-rwxr-xr-x 1 robot robot 474 Jan 18 16:18 midiummotor.rb
...
Select the program and push the center button on EV3.
You can also run programs using irb.
robot@ev3dev:~$ irb
irb(main):001:0> require 'ev3dev'
=> true
irb(main):002:0> mm = Ev3dev::Motor.new 'B'
=> #<Ev3dev::Motor:0x193890 @device_path="/sys/class/tacho-motor/motor0">
irb(main):003:0> mm.device_path
=> "/sys/class/tacho-motor/motor0"
irb(main):004:0> mm.driver_name
=> "lego-ev3-l-motor"
irb(main):005:0> mm.address
=> "outB"
irb(main):006:0> mm.commands
=> "run-forever run-to-abs-pos run-to-rel-pos run-timed run-direct stop reset"
irb(main):007:0> mm.stop_commands
=> "coast brake hold"
irb(main):008:0> mm.duty_cycle_sp 100
=> #<Ev3dev::Motor:0x193890 @device_path="/sys/class/tacho-motor/motor0">
irb(main):009:0> mm.command 'run-forever'
=> #<Ev3dev::Motor:0x193890 @device_path="/sys/class/tacho-motor/motor0">
irb(main):010:0> sleep 3
=> 3
irb(main):011:0> mm.command 'stop'
=> #<Ev3dev::Motor:0x193890 @device_path="/sys/class/tacho-motor/motor0">
irb(main):012:0>
(Also checkout examples)