Roboclaw 2x7a Read Error Python

General discussion of using Roboclaw motor controllers
Post Reply
notcosmo
Posts: 2
Joined: Fri Jul 15, 2016 7:53 am
Roboclaw 2x7a Read Error Python

Post by notcosmo »

Hello,

I have 2 Roboclaw 2x7a motor controllers connected to the UART Rx/Tx port of a BeagleBone Black running Debian Jessie 8.4 attempting to read any values from the MC's. I am using the provided python libraries and have no luck in being able to read the encoder values, version number, or anything. I am however able to send motor commands to move to a certain position after configuring the PID Values with UART.

Since the Beaglebone has only 1 USB port, I have to use a USB hub. However the Motor controllers do not show up on lsusb (it seems that they keep switching Device ID numbers). I am able to read and send commands if I connect the MC directly into the BeagleBone via USB. However this is not a viable option since I need to talk to 2 MC's + Other devices, thus I need to use a USB hub. Since I can not talk to the MC's via USB Hub (since /dev/ttyACM0 doesn't show up), I have to use UART (/dev/ttyO4). I desperately need help to read the Encoder values with this UART port of both MC's

I have already configured both MC's with Ion Motin on windows with the follow configs:
Packet Serial, Locked Antiphase, [Checked] Enable Multi-unit, Packer Serial Address: 128 and 129, Baudrate: 115200, Enc mode 1 and 2: Quadrature

The following is test code I wrote to read and go to positions. The function roboclaw.SpeedAccelDeccelPositionM1M2M3M4() is one I added myself but it works and is not part of the problem.
For all the print values, I ether get a None or (0,0)

Code: Select all

#***Before using this example the motor/controller combination must be
#***tuned and the settings saved to the Roboclaw using IonMotion.
#***The Min and Max Positions must be at least 0 and 50000

import time
import roboclaw
import Adafruit_BBIO.UART as UART
import serial 

def displayspeed(address):
	enc1 = roboclaw.ReadEncM1(address)
	enc2 = roboclaw.ReadEncM2(address)
	speed1 = roboclaw.ReadSpeedM1(address)
	speed2 = roboclaw.ReadSpeedM2(address)

	print("Encoder1:"),
	if(enc1[0]==1):
		print enc1[1],
		print format(enc1[2],'02x'),
	else:
		print "failed",
	print "Encoder2:",
	if(enc2[0]==1):
		print enc2[1],
		print format(enc2[2],'02x'),
	else:
		print "failed " ,
	print "Speed1:",
	if(speed1[0]):
		print speed1[1],
	else:
		print "failed",
	print("Speed2:"),
	if(speed2[0]):
		print speed2[1]
	else:
		print "failed "


#Windows comport name
#roboclaw.Open("COM3",38400)
#Linux comport name
#UART.setup("UART2")
#roboclaw.Open("/dev/ttyACM0",115200)
roboclaw.Open("/dev/ttyS4",57600)
address1 = 0x80
address2 = 0x81

while(1):
	print roboclaw.ReadVersion(address1)
	print roboclaw.ReadVersion(address2)
	displayspeed(address1)
	print "-------"
	displayspeed(address2)
	pos = input("Position?: ")
	roboclaw.SpeedAccelDeccelPositionM1M2M3M4(address1,address2,3200,1200,3200,pos,3200,1200,3200,pos,0)
	print "************"
	print roboclaw.ReadEncM1(address1)
	print "-------"
	print roboclaw.ReadEncM1(address1)
	print "Bat Volt: " + str(roboclaw.ReadMainBatteryVoltage(address1))
  
  	time.sleep(2)
User avatar
Basicmicro Support
Posts: 1594
Joined: Thu Feb 26, 2015 9:45 pm
Re: Roboclaw 2x7a Read Error Python

Post by Basicmicro Support »

I recommend you disable multi-unit mode and retest with one Roboclaw. Once you have that debugged then you can go back and add the second.

What value pullup do you have on the RX pin of the BB? A pullup is necessary when the Roboclaws are in Multi-unit mode since they will only drive low and float high(so they dont conflict with each other).

Check that your hub doesnt need to be powered seperately. It sounds like it is resetting the USB connection to the roboclaws.
notcosmo
Posts: 2
Joined: Fri Jul 15, 2016 7:53 am
Re: Roboclaw 2x7a Read Error Python

Post by notcosmo »

Thanks for the reply! I was able to get encoder readings via UART. All i had to do was hook up a 2.7k ohm resistor, connecting the RX lines to the 3.3VDC of the BeagleBone.
User avatar
Basicmicro Support
Posts: 1594
Joined: Thu Feb 26, 2015 9:45 pm
Re: Roboclaw 2x7a Read Error Python

Post by Basicmicro Support »

Yep. That will also work. The Roboclaw is actually a 3.3v device with 5v tolerant signal lines so it works with things like the BB and Arduino Due out of the box.
User avatar
Basicmicro Support
Posts: 1594
Joined: Thu Feb 26, 2015 9:45 pm
Re: Roboclaw 2x7a Read Error Python

Post by Basicmicro Support »

For USB connections, because USB uses seperate connections, this is how you do it. Eg you need to know which USB ports are being used. However, you can read the Packet serial address back from each unit to auto detect which unit is conenct to each port.

For the TTL connections, The 2k ohm resistor is not used in series. One 2k resistor must go from the RX pin of the RPi to the 3.3v of the RPi and both Roboclaws must have multi-unit mode selected and saved and be conencted in parallel to the RX pin of the RPi.

Post Reply