ev3dev / ev3dev-lang

(deprecated) language bindings for ev3dev sensors, motors, LEDs, etc.
GNU General Public License v2.0
56 stars 39 forks source link

Send commands to outA or outB #116

Closed jabrena closed 8 years ago

jabrena commented 8 years ago

Hi,

I am using some motors connecting and disconnecting from motor port 1 and 2 and now, I have 2 NXT motors in motor port A y B. Reading values from sysfs:

root@ev3dev:~# ls /sys/class/tacho-motor/
motor2  motor4

I observe this answer. If I use this way:

root@ev3dev:~# for f in /sys/class/tacho-motor/*; do echo -n "$f: "; cat $f/port_name; done
/sys/class/tacho-motor/motor2: outB
/sys/class/tacho-motor/motor4: outA

I see an absolute reference, because motor2 is connected in port B and motor4 is connected in port A.

How to send commands to motor port A & B?

http://www.ev3dev.org/docs/tutorials/tacho-motors/

ddemidov commented 8 years ago

I am not sure what is the problem here. Is this not what you would expect?

jabrena commented 8 years ago

imagine that I write a program which the robot has 2 motors connected to motor port A & B.

in the preliminary tests, I have connected 2 motors, but the reference is motor2 & 4 but they are connected to port A & B.

I would like to send:

root@ev3dev:~# echo 50 > /sys/class/tacho-motor/outA/duty_cycle_sp
root@ev3dev:~# echo run-forever > /sys/class/tacho-motor/outA/command
root@ev3dev:~# echo 50 > /sys/class/tacho-motor/outB/duty_cycle_sp
root@ev3dev:~# echo run-forever > /sys/class/tacho-motor/outB/command

does exist some way to make reference for motor port based on the position where user connected?

ddemidov commented 8 years ago

If you look at how Device is initialized in python now, it tries to connect to any device by default, but if user provides port_name (well, any attribute value), it tries to match that.

ddemidov commented 8 years ago

So you just iterate over devices until you find the one you need.

jabrena commented 8 years ago

Oki, I understand the idea.

When you init a Motor object, you search the element in "/sys/class/tacho-motor" and you fix the object with that element.

Thanks