Notifications
Clear all

[Solved] Pulling resistance Unit App In Torque mode

Page 2 / 2
Forum 1
(@amitmaziel)
Eminent Member

Hi Milad

i managed to install the library and compile the code u've sent' thanks.

i am still tying to understand if there is any user manual for the library syntax besides the examples

, feels like i am missing something here...

tnx. again

Amit

ReplyQuote
Topic starter Posted : 11/05/2022 9:13 am
SOLO Team
(@milad)
Chief Member Moderator

Hi @amitmaziel,

sure, The main user manual for the commands existing in the UART or USB command set can be found below, you can find there the definition for all the Read and Write commands:

https://www.solomotorcontrollers.com/wp-content/uploads/materials/SOLO_UNO_Communication_Manual_UART_USB.pdf

So were you able to run the system on Arduino or there are still issues?

Regards
Milad 

If you found the answers helpful and you could solve your problems, please kindly verify here to help others in the future.

ReplyQuote
Posted : 11/05/2022 1:08 pm
Forum 1
(@amitmaziel)
Eminent Member

@milad 

tnx.

attached u will find a problem i am facing using this syntax.

the "SOLO_Obj1->GetQuadratureCurrent();" command is nonrecognizable in the v3 library as far as i can see.

is there any other read command to use for actual torque reading?

image
ReplyQuote
Topic starter Posted : 11/05/2022 2:18 pm
SOLO Team
(@milad)
Chief Member Moderator

@amitmaziel 

actually, as you can see in the SOLOMotorControllersUart.cpp file function name for reading the quadrature current is "GetQuadratureCurrentIqFeedback()", so you need to use the following syntax for the mentioned piece:

SOLO_Obj1->GetQuadratureCurrentIqFeedback();

Let me know if you have other questions.

Regards

Milad

 

If you found the answers helpful and you could solve your problems, please kindly verify here to help others in the future.

ReplyQuote
Posted : 12/05/2022 6:45 am
Forum 1
(@amitmaziel)
Eminent Member

Hi Milad

My v2 canopen board has arrived and i am running the app through it as u recommended .

also upgraded the firmware to 0009B00A.

It seems that the board is working fine except for a major issue with positioning: if i am running positioning app through motion terminal it seems to work ok,

but running a code from the arduino , using the same parameters gains is acting in an unstable way, sometims perform positioning , sometimes motor running in opposite direction in various speed levels.

what might be the problem in your opinion?

here is the code: 

/*
* Title: Position Control of a Brushless Motor with Arduino and SOLO
* Author: SOLOMOTORCONTROLLERS
* Date: 2022
* Code version: 3.0
* Availability: https://github.com/Solo-FL/SOLO-motor-controllers-ARDUINO-library
* Please make sure you are applying the right wiring between SOLO and your ARDUINO
* The Code below has been tested on Arduino UNO
* The Motor used for Testings: teknic m-2310P-LN-04K
* Read more about this code here: https://www.solomotorcontrollers.com/position-control-brushless-arduino-and-solo/
*/

#include "SOLOMotorControllersCanopen.h"

//For this Test, make sure you have calibrated your Encoder before
//to know more please read: https://www.solomotorcontrollers.com/how-to-connect-calibrate-incremental-encoder-with-solo/

//instanciate a SOLO object:
SOLOMotorControllers *SOLO_Obj1;

//the device address of SOLO:
unsigned char SOLO_address1 = 0;

//Desired Switching or PWM Frequency at Output
long pwmFrequency = 40;

//Motor's Number of Poles
long numberOfPoles = 28;

//Motor's Number of Encoder Lines (PPR pre-quad)
long numberOfEncoderLines = 2048;

//Speed controller Kp
float speedControllerKp = 3;

//Speed controller Ki
float speedControllerKi = 0.001;

//Position controller Kp
float positionControllerKp =0.5;

//Position controller Ki
float positionControllerKi = 0.001;

// Current Limit of the Motor
float currentLimit = 9.0;

// Battery or Bus Voltage
float busVoltage = 0;

// Desired Speed Limit[RPM]
long desiredSpeedLimit = 2000;

// Desired Position Reference
long desiredPositionReference = 0;

// Motor speed feedback
long actualMotorSpeed = 0;

// Motor position feedback
long actualMotorPosition = 0;

void setup() {

//Low Speed Low Performance Baudrate
//Use this baudrate only for devices that don't support
//937500 or 921600 baudrates.
Serial.begin(115200);

//Initialize the SOLO object
int SOLOdeviceAddress = 0;
int chipSelectPin = 9;
SOLO_Obj1 = new SOLOMotorControllersCanopen(SOLOdeviceAddress, chipSelectPin);
delay(1000);

Serial.println("\n Trying to Connect To SOLO");
delay(1000);
//wait here till communication is established
while(SOLO_Obj1->CommunicationIsWorking() == false)
{
delay(500);
}

Serial.println("\n Communication Established succuessfully!");

// Initial Configurations
SOLO_Obj1->SetOutputPwmFrequencyKhz(pwmFrequency);
SOLO_Obj1->SetCurrentLimit(currentLimit);
SOLO_Obj1->SetIncrementalEncoderLines(numberOfEncoderLines);

//select Digital Mode
SOLO_Obj1->SetCommandMode(SOLOMotorControllersdigital);

SOLO_Obj1->SetMotorType(SOLOMotorControllersbldcPmsm);

//run the motor identification
//run ID. always after selecting the Motor Type!
SOLO_Obj1->MotorParametersIdentification(SOLOMotorControllersstart);

Serial.println("\n Identifying the Motor");

//wait at least for 2sec till ID. is done
delay(2000);

//Operate while using Quadrature Encoder
SOLO_Obj1->SetFeedbackControlMode(SOLOMotorControllersencoders);

//Control The Position
SOLO_Obj1->SetControlMode(SOLOMotorControllerspositionMode);

//Speed Controller Tunings
SOLO_Obj1->SetSpeedControllerKp(speedControllerKp);
SOLO_Obj1->SetSpeedControllerKi(speedControllerKi);

//Position Controller Tunings
SOLO_Obj1->SetPositionControllerKp(positionControllerKp);
SOLO_Obj1->SetPositionControllerKi(positionControllerKi);
desiredSpeedLimit = 1000;
SOLO_Obj1->SetSpeedLimit(desiredSpeedLimit);
}

void loop() {

//set a desired Speed Limit for trajectory in RPM

// set a positive desired Position Reference
desiredPositionReference =+10000;
SOLO_Obj1->SetPositionReference(desiredPositionReference);

// wait till motor reaches to the reference
delay(3000);

actualMotorPosition = SOLO_Obj1->GetPositionCountsFeedback();
Serial.println("\n Number of Pulses passed: ");
Serial.println(actualMotorPosition);

}

 

 

 

 

tnx.

Amit

 

ReplyQuote
Topic starter Posted : 23/05/2022 9:05 am
Forum 1
(@amitmaziel)
Eminent Member

Hi

OK, just calibrated PI gains again and now positioning is working great.

could u advise, however ,  how can i switch from a certain operating mode to to another in Arduino IDE ??

lets say i want to perform index homing in positioning mode an than to switch to torque mode...

tnx

Amit

ReplyQuote
Topic starter Posted : 24/05/2022 7:54 pm
SOLO Team
(@milad)
Chief Member Moderator

@amitmaziel ,

sorry for the delayed response, been very busy the past days,

Posted by: @amitmaziel

OK, just calibrated PI gains again and now positioning is working great.

Ok great, yes, right after looking at the code I felt the Speedcontroller Kp gains is too high, I don't know if that was the source of the issue, but glad that you could solve it.

Posted by: @amitmaziel

could u advise, however ,  how can i switch from a certain operating mode to to another in Arduino IDE ??

To switch from 1 mode to the other is pretty easy as long as you are putting SOLO in Digital mode ( which I believe you are), so for instance to go from Torque mode to position mode you simply need to call the following function:

//Control The Torque

SOLO_Obj1->SetControlMode(SOLOMotorControllerstorqueMode);

// going back to position mode

SOLO_Obj1->SetControlMode(SOLOMotorControllerspositionMode);

one important thing you need to consider is, that whenever you go from Torque or Speed mode to position mode, as the Encoder counts value might be anything different than the desired position which by default is set at zero , your motor might move back to Zero position, to avoid that before changing the mode, you can read the current position of the Motor, set it as the position reference first, and then changing the mode to position mode, so by doing so, SOLO once goes into position mode, sees that the motor is already in the requested position and it won't move the motor, if you are going out of position mode to Torque or Speed mode, then this situation will not apply and you can do that switching on the fly.

let me know if you have other questions.

Milad

 

If you found the answers helpful and you could solve your problems, please kindly verify here to help others in the future.

ReplyQuote
Posted : 25/05/2022 6:13 pm
Forum 1
(@amitmaziel)
Eminent Member

@milad 

Hi

Regarding my last question, i am trying to work with 2 operation modes- position/torque.

something is not right since when i push the trigger to go from torque mode to position mode the motor starts running at high speed ' regardless of the defined speed limit and to the opposite direction.

it seems that if i operates the position control inside the loop its not working well...

here is the code:

tnx.

#include <Arduino.h>
#include "SOLOMotorControllersCanopen.h"
//#include <avr_debugger.h>

//For this Test, make sure you have calibrated your Encoder before
//to know more please read: https://www.solomotorcontrollers.com/how-to-connect-calibrate-incremental-encoder-with-solo/

//instanciate a SOLO object:
SOLOMotorControllers *SOLO_Obj1;
//
int in_A1=3;
int in_A2=2;
//---------------------------------------Motor Parameters Setup-------------------------------------------
//the device address of SOLO:
unsigned char SOLO_address1 = 0;

//Desired Switching or PWM Frequency at Output
long pwmFrequency = 20;

//Motor's Number of Poles
long numberOfPoles = 28;

// Current Limit of the Motor
float currentLimit = 9.0;

// Battery or Bus Voltage
float busVoltage = 0;

// Desired Speed Limit[RPM]
long desiredSpeedLimit = 1000;

// Desired Position Reference
long desiredPositionReference = 0;
//position ref. tolerance
long Positive_pos=50+desiredPositionReference;
long Negative_pos=-(50+desiredPositionReference);
//Motor's Number of Encoder Lines (PPR pre-quad)
long numberOfEncoderLines = 2048;
//===================================pi controll tuning==================================================
//Speed controller Kp
float speedControllerKp = 3;
//Speed controller Ki
float speedControllerKi = 0.001;
//Position controller Kp
float positionControllerKp =0.1;
//Position controller Ki
float positionControllerKi = 0.0001;

// Motor speed feedback
long actualMotorSpeed = 0;
// Motor position feedback
long actualMotorPosition = 0;
int home_Done=0;
float Applied_Torque=0;
float Actual_Current = 0;
float Applied_Current=2;
float Applied_Force=0;
void setup() {
// #ifdef __DEBUG__
// dbg_start();
//#endif

// ------------------------------Srl Com.----------------------------------------------
Serial.begin(115200);
//-----------------------------inputs -----------------------------------------------
pinMode(in_A1, INPUT); // set pin 6 (sw) to input
pinMode(in_A2, INPUT); // set pin 5 (sw) to input
//--------------------------Motor Definition-----------------------------------------
//Initialize the SOLO object
int SOLOdeviceAddress = 0;
int chipSelectPin = 9;
SOLO_Obj1 = new SOLOMotorControllersCanopen(SOLOdeviceAddress, chipSelectPin);
delay(1000);
//--------------------------Communication Establishing-----------------------------------
Serial.println("\n Trying to Connect To SOLO");
delay(1000);
//wait here till communication is established
while(SOLO_Obj1->CommunicationIsWorking() == false)
{
delay(500);
}
Serial.println("\n Communication Established succuessfully!");

//----------------------------- Initial Configurations------------------------------------
SOLO_Obj1->SetOutputPwmFrequencyKhz(pwmFrequency);
SOLO_Obj1->SetCurrentLimit(currentLimit);
SOLO_Obj1->SetIncrementalEncoderLines(numberOfEncoderLines);

//----------------------------select Digital Mode----------------------------------------
SOLO_Obj1->SetCommandMode(SOLOMotorControllersdigital);

//----------------------------Motor Type----------------------------------------
SOLO_Obj1->SetMotorType(SOLOMotorControllersbldcPmsm);

//----------------------run the motor identification----------------------------
//run ID. always after selecting the Motor Type!
SOLO_Obj1->MotorParametersIdentification(SOLOMotorControllersstart);

Serial.println("\n Identifying the Motor");
//wait at least for 2sec till ID. is done
delay(2000);
//
//Operate while using Quadrature Encoder
SOLO_Obj1->SetFeedbackControlMode(SOLOMotorControllersencoders);

//-------------------------------Speed/position Controller Tunings----------------------------------------
SOLO_Obj1->SetSpeedControllerKp(speedControllerKp);
SOLO_Obj1->SetSpeedControllerKi(speedControllerKi);
SOLO_Obj1->SetPositionControllerKp(positionControllerKp);
SOLO_Obj1->SetPositionControllerKi(positionControllerKi);

desiredSpeedLimit = 200;
SOLO_Obj1->SetSpeedLimit(desiredSpeedLimit);

}
void loop() {

//--------------------------------if input=0 kill motor on torque ctrl-----------------------------------------
int buttonState = digitalRead(in_A1);
while(buttonState==0){
buttonState = digitalRead(in_A1);
SOLO_Obj1->SetControlMode(SOLOMotorControllerstorqueMode);
SOLO_Obj1->SetTorqueReferenceIq(0.0);
Serial.println("\n buttonState=0");
}
Serial.println("\n loop1" );
int home_buttonState= digitalRead(in_A2);
buttonState = digitalRead(in_A1);

//--------------------------------if input=1 Get ref. Position on Position ctrl-----------------------------------------
if(buttonState==1){
//---------------------------------Control The Position--------------------------------------------
SOLO_Obj1->SetControlMode(SOLOMotorControllerspositionMode);
buttonState = digitalRead(in_A1);
}
delay(1000);
// set a positive desired Position Reference
desiredPositionReference =0;
delay(3000);
SOLO_Obj1->SetPositionReference(desiredPositionReference);

// wait till motor reaches to the reference
//delay(3000);
loop2:
buttonState = digitalRead(in_A1);
actualMotorPosition = SOLO_Obj1->GetPositionCountsFeedback();
Serial.println("\n buttonState==1)");
Serial.println("\n Actual Position: ");
Serial.println(actualMotorPosition);
if(actualMotorPosition>Positive_pos||actualMotorPosition<Negative_pos&&buttonState==1) goto loop2;

}

ReplyQuote
Topic starter Posted : 10/06/2022 9:22 am
SOLO Team
(@milad)
Chief Member Moderator

Hi @amitmaziel,

  • Did you try to go from Position mode to Torque mode in Motion Terminal ( trying to replicate your situation)?
  • It seems that in your code if the condition for Loop2 execution doesn't hold, you go back to the beginning of the forever loop ( void loop() ) however there we don't know if "while(buttonState==0)" still holding, so to me is not clear what happens if button state is not Zero, based on your code, you stay in position mode and give the 0 reference for the position...
  • in general, strongly recommend avoiding "goto" methods and trying to write those sections either in form of a function or a switch case.

 

Let me know your thoughts on this.

Regards
Milad

 

If you found the answers helpful and you could solve your problems, please kindly verify here to help others in the future.

ReplyQuote
Posted : 13/06/2022 8:06 am
Forum 1
(@amitmaziel)
Eminent Member

Hi Milad

even if loop2 doesnt hold, once buttonState =1,the driver enters  position mode with ref. position 0 and defined speed limit ( loop2 is relevant only once we reached required position).

i cant see the reason why the motor should rotate to the opposite direction with an uncontrolled speed.

tnx.

Amit

ReplyQuote
Topic starter Posted : 13/06/2022 9:09 am
Forum 1
(@amitmaziel)
Eminent Member

pls advise

is it possible that once i put " SOLO_Obj1->SetControlMode(SOLOMotorControllerspositionMode);" inside the loop it goes creasy?

ReplyQuote
Topic starter Posted : 17/06/2022 8:08 am
SOLO Team
(@milad)
Chief Member Moderator

Hi @amitmaziel,

Actually I feel the only way I can see what is the issue it to implement and test what you did in your code, I can't see that behavior in Motion terminal, so it must be related to some section of the code, I need more time, but I'll do my best to test it within this week and report back to you some results.

Milad

 

If you found the answers helpful and you could solve your problems, please kindly verify here to help others in the future.

ReplyQuote
Posted : 19/06/2022 4:20 pm
Forum 1
(@amitmaziel)
Eminent Member

@milad 

thanks a lot .

i appreciate your effort and dedication very much.

Amit

ReplyQuote
Topic starter Posted : 19/06/2022 5:41 pm
SOLO Team
(@milad)
Chief Member Moderator

Hi @amitmaziel,

Today I finally found time to prepare an initial test for what you're doing using the CAN module and Arduino UNO and the code is attached, so basically I could switch between Position and Torque mode with no issues, in my code I'm using Hall sensors, but for Encoder the loop part will be identical, let me know if this sample code could help you through your development and if not, how you'd like to proceed and change it to make sense to you.

Regards
Milad

If you found the answers helpful and you could solve your problems, please kindly verify here to help others in the future.

ReplyQuote
Posted : 23/06/2022 2:04 pm
Forum 1
(@amitmaziel)
Eminent Member

Thanks a lot 

i will try it and let u know.

BR

Amit

ReplyQuote
Topic starter Posted : 23/06/2022 2:27 pm
Page 2 / 2
Share: