Page 1 of 2
R and L setting by serial
Posted: Mon Nov 04, 2019 11:37 pm
by fausto.tromba
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?
Re: R and L setting by serial
Posted: Tue Nov 05, 2019 9:57 am
by Basicmicro Support
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.
Re: R and L setting by serial
Posted: Tue Nov 05, 2019 11:50 am
by fausto.tromba
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
Re: R and L setting by serial
Posted: Wed Nov 06, 2019 8:14 am
by Basicmicro Support
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.
Re: R and L setting by serial
Posted: Wed Nov 06, 2019 11:35 pm
by fausto.tromba
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.
Re: R and L setting by serial
Posted: Thu Nov 07, 2019 9:50 am
by Basicmicro Support
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.
Re: R and L setting by serial
Posted: Fri Nov 08, 2019 12:20 am
by fausto.tromba
Hi
I have set the Resistance and the Inductance by BasicMicroStudio (see the picture)
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
Re: R and L setting by serial
Posted: Fri Nov 08, 2019 10:34 am
by Basicmicro Support
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.
Re: R and L setting by serial
Posted: Tue Nov 12, 2019 7:45 am
by fausto.tromba
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
Re: R and L setting by serial
Posted: Tue Nov 12, 2019 10:01 am
by Basicmicro Support
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?