Giter Site home page Giter Site logo

solo-fl / solopy Goto Github PK

View Code? Open in Web Editor NEW
11.0 3.0 6.0 277 KB

Controlling Motors using SOLO Motor Controllers with PYTHON on RASPBERRY PI, Linux, windows, and more!

Home Page: https://www.solomotorcontrollers.com/

License: GNU General Public License v3.0

Python 100.00%
automation linux motion motor motor-controllers motor-vehicles position-controller python3 raspberry-pi robotics

solopy's Introduction

Repository License

SoloPy

SoloPy is a Python library published by SOLO Motor Controllers to control, command or read all the parameters that are stored or existing in the command set of SOLO devices. More information about SoloPy on the SOLO website. For List of All the Available Methods Read the DataSheet

SoloPy allows SOLO devices to be used in this conditions:

  • USB Communication with Windows OS or Linux
  • UART protocol with RASPBERRY PI or any similar controller
  • CanOpen protocol with RASPBERRY PI or any similar controller

Installation

Please make sure you have installed Python 3 and pip

Install Solopy From Pip

$ pip install solopy

Update

If you have installed the library and you want to update it on Linux, RASPBERRY PI or Windows

$ pip install --upgrade SoloPy 

USB Communication with Windows OS or Linux Note ========================== 1. Connect Solo to Raspberry Pi or Pc

  1. Open terminal in linux(cmd in windows) and enter the following command
$ python -m serial.tools.list_ports -v
  1. this will show you the port name that SOLO is connected to (in linux it's sth like '/dev/ttyAMC0' and in windows it's sth like 'COM8'

UART protocol with RASPBERRY PI Note ============= In order to enable UART Protocol on Raspberry Pi you need to follow this one time process.

  1. In Raspberry Pi, enter following command in Terminal to enable UART
$ sudo raspi-config
  1. Select -> Interfacing Options
  2. After selecting Interfacing option, select Serial option to enable UART
  3. Then it will ask for the login shell to be accessible over Serial, select No shown as follows.
  4. At the end, it will ask for enabling Hardware Serial port, select Yes,
  5. Finally, our UART is enabled for Serial Communication on RX and TX pins of Raspberry Pi 3.
  6. Then, reboot the Raspberry Pi.

CanOpen protocol with RASPBERRY PI Note ============= In order to enable CanOpen Protocol on Raspberry Pi you need to follow this process one time

  1. turn SPI on in raspberry pi:
$ sudo raspi-config   

then go to interfaces

then go to SPI and turn on

then go to reboot

  1. type in terminal
$ sudo apt-get update
  1. then type this command:
$ sudo nano /boot/config.txt

4- scroll down and add these lines:

dtoverlay=mcp2515-can0,oscillator=16000000,interrupt=25

5- then reboot RASPBERRY PI

Every time you reboot RASPBERRY PI you need to follow this process

1- type this command

$ sudo ip link set can0 up type can bitrate 1000000

Notes

  • The bit-rate has to be the same as the one used in the code
  • The following CAN transceiver module "PiCAN2" has been used to test the library

Dependencies

Python 3

python-interface

for UART pyserial

for CanOpen Python-Can

Authors

SoloPy is created by SOLO Motor Controllers team

License

GNU General Public License v3.0 or later

See COPYING to see the full text.

solopy's People

Contributors

alimilad avatar mohkardan avatar solo-fl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

solopy's Issues

name 'solo' is not defined

Hi,

I am just getting started with the Solo Uno and wired it to my Raspberry Pi 4. I did the installation procedure as documented on the github but when I want to test the examples I am getting the error as shown:

Traceback (most recent call last): File "reading_temperature.py", line 38, in <module> do_work() File "reading_temperature.py", line 34, in do_work __setup() File "reading_temperature.py", line 29, in __setup __solo_driver = solo.SoloMotorController(__solo_address) NameError: name 'solo' is not defined

I also wired a brushed dc motor to the solo and my piano settings are all DOWN except for switch 3. The motor is then continuously running.

Thanks for any help!

Getter method for canbus baudrate

In main/v3.1.2, the get_can_bus_baudrate() method is implemented under solo.SoloMotorControllerUart(), and not under SOLOMotorControllersCanopen(). Was it a mistake or intentional?

Examples don't work with pypi package

While having same version numbering, code on pypi is different from this repo. This results in non-functioning example code, when trying to run with pypi package.

How to reproduce

  1. pip install solopy
  2. try to run examples/BLDC_Speed_Control.py .

result:

AttributeError: 'SoloMotorControllerUart' object has no attribute 'connection_is_working'.

analysis

I've compared SOLOMotorControllersUart.py from pypi package with github code.

  • both claim # @version 3.1.1 in the header
  • checked version installed from pypi, it is 3.1.3
  • compared actual code. It has different interfaces
    • pypi : serial_close and serial_is_working
    • repo: disconnect and connection_is_working.

conclusion

Two incompatible code versions share the same version number.

Naming convention

Can you fix the naming convention (in CAN, SOLO and in Uart, Solo). It is confusing.

SOLOMotorControllersCanopen vs SoloMotorControllerUart

BLDC_encoder

Hello, I am using Brushless Frameless Motor 50BLF15, for this i am using this file and modify as motor requirement examples/windows/usb/PMSM_Speed_Control_Encoder_based.py . When i run program motor is not work in clockwise direction and if i'm work on at counterclockwise direction with removing C.C. part its stop sometimes and take minute to rerun while loop. what should i add for not stopping motor again and again. Also, i need stall detection error time out i add command but its not working. What is the problem?

Here, i wrote my code below.

Copyright: (c) 2021, 2022, 2023 SOLO motor controllers project

GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

Title: SoloPy

Author: SOLOMotorControllers

Date: 2023

Code version: 3.0.0

Availability: https://github.com/Solo-FL/SoloPy/tree/main/SoloPy

This Library is made by SOLOMotorControllers.COM

please visit: https://www.SOLOMotorControllers.com/

The Motor used for Testings: teknic m-2310P-LN-04K

import SoloPy as solo

import time

instanciate a SOLO object:

mySolo = solo.SoloMotorControllerUart("COM5", 0, solo.UART_BAUD_RATE.RATE_937500)

Desired Switching or PWM Frequency at Output

pwmFrequency = 20

Motor's Number of Poles

numberOfPoles = 20

Motor's Number of Encoder Lines (PPR pre-quad)

numberOfEncoderLines = 2048

Speed controller Kp

speedControllerKp = 0.7

Speed controller Ki

speedControllerKi = 0.003

Position controller Kp

positionControllerKp = 0.12

Position controller Ki

positionControllerKi = 0.02

Current Limit of the Motor

currentLimit_init = 15

Battery or Bus Voltage

busVoltage = 0

Motor Torque feedback

actualMotorTorque = 0

Motor speed feedback

actualMotorSpeed = 0

Motor position feedback

actualMotorPosition = 0

wait here till communication is established

print("Trying to Connect To SOLO")
communication_is_working = False
while communication_is_working is False:
time.sleep(1)
communication_is_working, error = mySolo.communication_is_working()
print("Communication Established succuessfully!")

Initial Configuration of the device and the Motor

mySolo.set_output_pwm_frequency_khz(pwmFrequency)
mySolo.set_current_limit(currentLimit_init)
mySolo.set_motor_poles_counts(numberOfPoles)
mySolo.set_incremental_encoder_lines(numberOfEncoderLines)
mySolo.set_command_mode(solo.COMMAND_MODE.DIGITAL)
mySolo.set_motor_type(solo.MOTOR_TYPE.BLDC_PMSM)
mySolo.set_feedback_control_mode(solo.FEEDBACK_CONTROL_MODE.ENCODERS)
time.sleep(3)
mySolo.set_speed_controller_kp(speedControllerKp)
mySolo.set_speed_controller_ki(speedControllerKi)
mySolo.set_control_mode(solo.CONTROL_MODE.SPEED_MODE)

run the motor identification to Auto-tune the current controller gains Kp and Ki needed for Torque Loop

run ID. always after selecting the Motor Type!

ID. doesn't need to be called everytime, only one time after wiring up the Motor will be enough

the ID. values will be remembered by SOLO after power recycling

mySolo.motor_parameters_identification(solo.ACTION.START)
print("Identifying the Motor")

wait at least for 2sec till ID. is done

time.sleep(2)

Perform Encoder calibration

mySolo.sensor_calibration(solo.POSITION_SENSOR_CALIBRATION_ACTION.INCREMENTAL_ENCODER_START_CALIBRATION)
#t TODO: write while sensor_calibration.... and remove sleep(35)
time.sleep(35)

mySolo.set_speed_controller_kp(speedControllerKp)
mySolo.set_speed_controller_ki(speedControllerKi)
mySolo.set_control_mode(solo.CONTROL_MODE.SPEED_MODE)
enc_off_ccw = mySolo.get_encoder_hall_ccw_offset()
enc_off_cw = mySolo.get_encoder_hall_cw_offset()
print('encoder offsets cw, ccw: ' + str(enc_off_cw) + str(enc_off_ccw))
mySolo.set_speed_acceleration_value(30.0)
mySolo.set_speed_deceleration_value(30.0)

Current Limit of the Motor

currentLimit_run = 20
mySolo.set_current_limit(currentLimit_run)

loop actions

while True:

# set the Direction on C.C.W.
mySolo.set_motor_direction(solo.DIRECTION.COUNTERCLOCKWISE)
# set an arbitrary Positive speed reference[RPM]
mySolo.set_speed_reference(100)
time.sleep(1)
actualMotorSpeed, error = mySolo.get_speed_feedback()
print("Motor Speed: " + str(actualMotorSpeed))
actualMotorTorque, error = mySolo.get_quadrature_current_iq_feedback()
print("Measured Iq/Torque[A]: " + str(actualMotorTorque))
time.sleep(3)

# set an arbitrary Positive speed reference[RPM]
mySolo.set_speed_reference(0)
time.sleep(1)
actualMotorSpeed, error = mySolo.get_speed_feedback()
print("Motor Speed: " + str(actualMotorSpeed))
actualMotorTorque, error = mySolo.get_quadrature_current_iq_feedback()
print("Measured Iq/Torque[A]: " + str(actualMotorTorque))
time.sleep(3)

error_detection, error  = mySolo.get_error_register()
print("Stall detection error detected:" + str(error))
time.sleep(4)

using brushed DC with Raspberry Pi

Hi,

Short:
I would like to use the SoloUno together with my Raspberry Pi to control a brushed DC motor and control its speed.
Will there be an example for this in the future? If not, how would I approach it best to parse the Arduino example?

Long:
So far, the only example I found that comes close to this is here where an Arduino is used and a potentiometer as input.
However I am using a raspberry pi and do not need a potentiometer. Looking at the code for brushless control I have seen that motor_type = 1 stands for BLDC_PMSM.
Which number would then be for a brushed DC or where can I find the code documentation? Apart from that the functions would be the same for BLCD and brushed DC right? Only the Piano-Switch setting is different?

Also:
When I started the SoloUno with Piano switches 1,2,4,5 Down my brushed DC starts to run immediately and continously. After trying out the brushless examples (I wanted to see what happens using them on the brushed DC). The motor stutters a lot and sometimes runs smoothly. I assume this depends on which of the 3 phases would be selected, since the brushed dc is only connected to 2. If I exit the example, the behaviour continues.
So am I assuming right, that the last "action" is saved? Why does then the brushed dc automatically run if I switch on the SoloUno the first time?

Thanks a lot!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.