R and L setting by serial
-
- Posts: 37
- Joined: Wed Jul 31, 2019 7:24 am
R and L setting by serial
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.
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?
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
- Basicmicro Support
- Posts: 1594
- Joined: Thu Feb 26, 2015 9:45 pm
Re: R and L setting by serial
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.
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.
-
- Posts: 37
- Joined: Wed Jul 31, 2019 7:24 am
Re: R and L setting by serial
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
def ReadM1IndRes(self,address):
data = self._read_n(address,130,2)
return data
- Basicmicro Support
- Posts: 1594
- Joined: Thu Feb 26, 2015 9:45 pm
Re: R and L setting by serial
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.
-
- Posts: 37
- Joined: Wed Jul 31, 2019 7:24 am
Re: R and L setting by serial
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
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
class Cmd():
...
GETM1LR = 130
GETM2LR = 131
...
I tried to attach the complete files, but is not possible.
- Basicmicro Support
- Posts: 1594
- Joined: Thu Feb 26, 2015 9:45 pm
Re: R and L setting by serial
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.
If you dont know your motors L and R you need to contact the manufacturer or measure them using appropriate tools.
-
- Posts: 37
- Joined: Wed Jul 31, 2019 7:24 am
Re: R and L setting by serial
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
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
- Attachments
-
- RL.PNG (15.49 KiB) Viewed 13535 times
- Basicmicro Support
- Posts: 1594
- Joined: Thu Feb 26, 2015 9:45 pm
Re: R and L setting by serial
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.
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.
-
- Posts: 37
- Joined: Wed Jul 31, 2019 7:24 am
Re: R and L setting by serial
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
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
- Basicmicro Support
- Posts: 1594
- Joined: Thu Feb 26, 2015 9:45 pm
Re: R and L setting by serial
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?
2. What firmware version are you using?
3. Have you gotten other read commands to function correctly?