R and L setting by serial

General discussion of the MCP motion controller product line
fausto.tromba
Posts: 20
Joined: Wed Jul 31, 2019 7:24 am

R and L setting by serial

Post by fausto.tromba » Mon Nov 04, 2019 11:37 pm

Hi
On my project, I should move different model motors in current mode. So I have to set both L and R.
In the Python library, there is not. As I said i tried with the following code without any success.

Code: Select all

	def ReadM1IndRes(self,address):
		data = self._read_n(address,130,2)
		return data
Given that it is possible to set the R and L by BasicMicroStudio using the serial port, surely there is already a serial command to set them. Is it possible to have them?

User avatar
Basicmicro Support
Posts: 1277
Joined: Thu Feb 26, 2015 9:45 pm

Re: R and L setting by serial

Post by Basicmicro Support » Tue Nov 05, 2019 9:57 am

The python library(as well as the arduino library) are written for Roboclaw. MCP uses a superset of Roboclaws commands so some MCP commands are not in the python library. However you can add them fairly easily as long as you know the syntax:

Commands:
SETM1LR 128
SETM2LR 129
GETM1LR 130
GETM2LR 131

Syntax:
SETM#LR
Send: address,cmd,l(4 bytes),r(4 bytes),CRC16(2 bytes)
Receive: 0xFF

The L and R are the values in henries and ohms TIMES 0x1000000. Eg .004 ohms would be .004 * 0x1000000 = 671089.

GETM#LR
Send: address,cmd
Receive: L(4 bytes), R(4 bytes), CRC16(2bytes).

Divide the L and R values by 0x1000000 to get the henries and ohms.

fausto.tromba
Posts: 20
Joined: Wed Jul 31, 2019 7:24 am

Re: R and L setting by serial

Post by fausto.tromba » Tue Nov 05, 2019 11:50 am

I did as you can see in my previous post. I added this in the python library, but I don't receive the right information. For example for GETM1LR

def ReadM1IndRes(self,address):
data = self._read_n(address,130,2)
return data

User avatar
Basicmicro Support
Posts: 1277
Joined: Thu Feb 26, 2015 9:45 pm

Re: R and L setting by serial

Post by Basicmicro Support » Wed Nov 06, 2019 8:14 am

You have given me code(both times) with no results or errors. What is the result? Without that information your code doesnt help me help you.

fausto.tromba
Posts: 20
Joined: Wed Jul 31, 2019 7:24 am

Re: R and L setting by serial

Post by fausto.tromba » Wed Nov 06, 2019 11:35 pm

Code: Select all

import time
from roboclaw_3 import Roboclaw

#Windows comport name
#rc = Roboclaw("COM11",115200)
#Linux comport name
rc = Roboclaw("/dev/ttyS0",38400)

rc.Open()

#Get R and L
M1_RL = rc.GetM1IndRes(0x80)
print("Motor 1 RL=",M1_RL)

M2_RL = rc.GetM1IndRes(0x80)
print("Motor 2 RL=",M2_RL)

M2MaxCurrent = rc.ReadM2MaxCurrent(0x80)
print("ReadM2MaxCurrent=",M2MaxCurrent
Result:

Motor1 1 RL = [1,0,0]
Motor1 2 RL = [1,0,0]
ReadM2MaxCurrent= (1, 1500)

The library, what I added is:

Code: Select all

	def GetM1IndRes(self,address):
		data = self._read_n(address,self.Cmd.GETM1LR,2)
		return data
	
	def GetM2IndRes(self,address):
		data = self._read_n(address,self.Cmd.GETM2LR,2)
		return data
where
class Cmd():
...
GETM1LR = 130
GETM2LR = 131
...

I tried to attach the complete files, but is not possible.

User avatar
Basicmicro Support
Posts: 1277
Joined: Thu Feb 26, 2015 9:45 pm

Re: R and L setting by serial

Post by Basicmicro Support » Thu Nov 07, 2019 9:50 am

L and R are 0 by default. Did you set them in some other code or in Motion Studio. Reading the L and R is NOT measuring the L and R of the motor. It just returns the previously set values.

If you dont know your motors L and R you need to contact the manufacturer or measure them using appropriate tools.

fausto.tromba
Posts: 20
Joined: Wed Jul 31, 2019 7:24 am

Re: R and L setting by serial

Post by fausto.tromba » Fri Nov 08, 2019 12:20 am

Hi
I have set the Resistance and the Inductance by BasicMicroStudio (see the picture)
Image

surly is in the memory of the MCP because even if I switch on all system and i restart the PC+ motor driver etc, I could read those values.

I would like to read those values and write them by a serial command.
Fausto
Attachments
RL.PNG
RL.PNG (15.49 KiB) Viewed 52 times

User avatar
Basicmicro Support
Posts: 1277
Joined: Thu Feb 26, 2015 9:45 pm

Re: R and L setting by serial

Post by Basicmicro Support » Fri Nov 08, 2019 10:34 am

I got a copy of the pre-release for the next update of the python library. These are the defined functions for reading the L and R values.

def GetM1LR(self,address):
date = self._read_n(address,self.Cmd.GETM1LR,2)
if data[0]:
return (1,data[1]/0x1000000,data[2]/0x1000000)
return (0,0,0)

def GetM2LR(self,address):
data = self._read_n(address,self.Cmd.GETM2LR,2)
if data[0]:
return (1,data[1]/0x1000000,data[2]/0x1000000)
return (0,0,0)

The cmd defines are:

SETM1LR = 128 #MCP only
SETM2LR = 129 #MCP only
GETM1LR = 130 #MCP only
GETM2LR = 131 #MCP only

I don't see much difference between yours and ours except for the divide we do to convert the fixed point value to a double. Note we also do a check on data[0] to make sure the command executed properly and the CRC16 matched.

fausto.tromba
Posts: 20
Joined: Wed Jul 31, 2019 7:24 am

Re: R and L setting by serial

Post by fausto.tromba » Tue Nov 12, 2019 7:45 am

Dear
I modified what you said without any result. My model is MCP236. Can you try on your laboratory with the same model?

What I receive is (1,0,0). So the data[0] is 1 (the command executed properly).
I treid to attached here the sources, but it is not possible.

Can I send you it by mail in support@ ?

Thanks

Fausto

User avatar
Basicmicro Support
Posts: 1277
Joined: Thu Feb 26, 2015 9:45 pm

Re: R and L setting by serial

Post by Basicmicro Support » Tue Nov 12, 2019 10:01 am

1. Please email support. We will setup a test.

2. What firmware version are you using?

3. Have you gotten other read commands to function correctly?

Post Reply