electric_vehicle_lover Posted November 10, 2016 Share Posted November 10, 2016 @lizardmech can you please share the values measured by VESC of your EUC motor for: #define MOTOR_RESISTANCE 0.015 #define MOTOR_L_INDUCTANCE 0.00002 #define MOTOR_FLUX_LINKAGE 0.00245 #define MOTOR_ESTIMATOR_GAIN_GAMA 30000000 // 600 / L as noted on VESC mcconf_default.h Seems I need to adjust them very well for the estimator to work correctly. Quote Link to comment Share on other sites More sharing options...
lizardmech Posted November 12, 2016 Share Posted November 12, 2016 On 11/11/2016 at 7:58 AM, electric_vehicle_lover said: @lizardmech can you please share the values measured by VESC of your EUC motor for: #define MOTOR_RESISTANCE 0.015 #define MOTOR_L_INDUCTANCE 0.00002 #define MOTOR_FLUX_LINKAGE 0.00245 #define MOTOR_ESTIMATOR_GAIN_GAMA 30000000 // 600 / L as noted on VESC mcconf_default.h Seems I need to adjust them very well for the estimator to work correctly. Did you buy a VESC? Here's my calibration xml euc2.xml Quote Link to comment Share on other sites More sharing options...
electric_vehicle_lover Posted November 12, 2016 Share Posted November 12, 2016 8 hours ago, lizardmech said: Did you buy a VESC? Here's my calibration xml euc2.xml Thanks. I will try later the estimator with that values and my motor - I hope it will work. No I didn't bought VESC. I am not ready to spend more money, change my setup, etc. I will keep working on 30B4 board, and now that I am more close to have FOC and understand it. I am learning a lot from VESC and I hope to reuse the code of FOC and SVM. But I can guide you - you start put the first code and comments on github and I can go and write code, we discuss and you test. For balancing code, I already did my tests with 30B4 board for the MPU and the balance code - the issue is that I don't have the motor code working correctly unlike you have on the VESC. 1 Quote Link to comment Share on other sites More sharing options...
lizardmech Posted November 13, 2016 Share Posted November 13, 2016 7 hours ago, electric_vehicle_lover said: Thanks. I will try later the estimator with that values and my motor - I hope it will work. No I didn't bought VESC. I am not ready to spend more money, change my setup, etc. I will keep working on 30B4 board, and now that I am more close to have FOC and understand it. I am learning a lot from VESC and I hope to reuse the code of FOC and SVM. But I can guide you - you start put the first code and comments on github and I can go and write code, we discuss and you test. For balancing code, I already did my tests with 30B4 board for the MPU and the balance code - the issue is that I don't have the motor code working correctly unlike you have on the VESC. Can you please try to port the balancing code to a VESC control module? It doesn't have to be perfect just enough to get me started. Quote Link to comment Share on other sites More sharing options...
electric_vehicle_lover Posted November 13, 2016 Share Posted November 13, 2016 10 hours ago, lizardmech said: Can you please try to port the balancing code to a VESC control module? It doesn't have to be perfect just enough to get me started. First, this will not be a one shoot!! You will be the one that will be compiling, flashing and debug the code - are you ready?? We need to figure out what debug tools we will use, I mean you. I did my prototype of balance code using printfs to send out of the board the variables and angle values. I also used JTAG debug to flash and debug the code, also to "simulate" pieces of the code and see the variables values. Do you have such tools with you?? VESC page talks about using JTAG for flash and debug the code. What is your background, electronics? What tools do you have with you? do you have an oscilloscope? Quote Link to comment Share on other sites More sharing options...
lizardmech Posted November 14, 2016 Share Posted November 14, 2016 (edited) 13 hours ago, electric_vehicle_lover said: First, this will not be a one shoot!! You will be the one that will be compiling, flashing and debug the code - are you ready?? We need to figure out what debug tools we will use, I mean you. I did my prototype of balance code using printfs to send out of the board the variables and angle values. I also used JTAG debug to flash and debug the code, also to "simulate" pieces of the code and see the variables values. Do you have such tools with you?? VESC page talks about using JTAG for flash and debug the code. What is your background, electronics? What tools do you have with you? do you have an oscilloscope? I have everything, my linux setup is configured for building arm code straight through terminal with gcc. VESC tool has built in oscilloscopes and graphs for all values. It even has it's own built in terminal you can access over USB provided the chibios part boots. Failing that I have a cypress psoc I turned into a makeshift oscilloscope, debug through stlink and eclipse. I can install a linux distro from source such as gentoo and one of my linux desktops has an ARM cpu, it's just I have no experience writing entirely new C code. Edited November 14, 2016 by lizardmech 1 Quote Link to comment Share on other sites More sharing options...
electric_vehicle_lover Posted November 14, 2016 Share Posted November 14, 2016 Só, can you update you schematic with the MPU? After I will look at the pins and start the code for the initialiation, then you will debug the code to see if the initialiation is ok. Quote Link to comment Share on other sites More sharing options...
lizardmech Posted November 14, 2016 Share Posted November 14, 2016 (edited) 36 minutes ago, electric_vehicle_lover said: Só, can you update you schematic with the MPU? After I will look at the pins and start the code for the initialiation, then you will debug the code to see if the initialiation is ok. It's all in here already https://github.com/vedderb/bldc/blob/master/applications/app_nunchuk.c From what I understand of the code it's abstracted from hw. I think all you have to do is enter the correct I2C settings starting line 85 then activate I2C via hw_start_i2c(); then just add the usual MPU C code. After that is done all that is left is to change the code so gyro output to replace the joystick output float app_nunchuk_get_decoded_chuk(void) { return ((float)chuck_d.js_y - 128.0) / 128.0; Edited November 14, 2016 by lizardmech Quote Link to comment Share on other sites More sharing options...
electric_vehicle_lover Posted November 15, 2016 Share Posted November 15, 2016 @lizardmech ok, I went and created the base files for the EUC app files. I added the imu.c file that have the code for balance controller: https://github.com/EGG-electric-unicycle/bldc/blob/EUC-VESC_electronics/applications/imu.c The code builds but the IMU files are not included as they need work - they need to use the Chibios functions for I2C and not the ones used on the original code - can you please go ahead and do this changes?? the code have a lot of comments, I think you will understand each step. I will not have time on next week to continue working on this project. Please make your changes and push them back to github, I will try to find some time and review the code. You can also go by small step by step and run/debug the code with JTAG to see if it works. The code is here: https://github.com/EGG-electric-unicycle/bldc/tree/EUC-VESC_electronics For your reference, the code on firmware for Gen1 boards is here and his the latest code where I tested the IMU and the balance code: https://github.com/EGG-electric-unicycle/bldc/blob/EUC-VESC_electronics/applications/imu.c For adding source files to be built on VESC firmware, like adding imu.c, you will need to add them to applications/applications.mk, for instance I added the file app_euc.c: APPSRC = applications/app.c \ applications/app_ppm.c \ applications/app_adc.c \ applications/app_sten.c \ applications/app_uartcomm.c \ applications/app_nunchuk.c \ applications/app_euc.c Quote Link to comment Share on other sites More sharing options...
lizardmech Posted November 16, 2016 Share Posted November 16, 2016 So I need to more or less port everything from IMU into the app_euc file? The only thing I don't quite get is how to initialize the MPU6050 on chibiOS. Quote Link to comment Share on other sites More sharing options...
electric_vehicle_lover Posted November 16, 2016 Share Posted November 16, 2016 4 hours ago, lizardmech said: So I need to more or less port everything from IMU into the app_euc file? The only thing I don't quite get is how to initialize the MPU6050 on chibiOS. You want to call IMU_init() from app_euc_start(). And on IMU_init() you will see that there is a MPU6050_TestConnection() - if it return TRUE, then the initialization is ok!! You want to get here :-) On IMU_init(), you will take care off putting the I2C working for the IMU - here should be easy because you should just need to adapt to the calls of Chibios I2C for initialization. MPU6050_Initialize() you will start sending commands to the MPU6050... --- BOOL IMU_init(void) { unsigned int i; MPU6050_I2C_Init(); MPU6050_Initialize(); // if the MPU6050 is ready, make "calibration" // read the sensor values and average if (MPU6050_TestConnection()) { return TRUE; } else { return FALSE; } Quote Link to comment Share on other sites More sharing options...
KingQueenWong Posted November 28, 2016 Share Posted November 28, 2016 @electric_vehicle_lover I come from China.My job is a hardware engineer,i love brushless contorl.Thanks to many open source and hardware project,i learn a lots. Maybe I can support somethings for the EGG-electric-unicycle project. I really sure that STM32F1 can implement FOC,even though it not very very high performances,but it very well enough.Beause some guy have implemented it,such as scolton Colton. I really hope that you can insist the owesome work and keep moving.You know that benjamin develop vesc over 4 years. The link's source is full opensource:http://scolton.blogspot.jp/2011/11/ah-software-optimization-my-old-friend.html I have the link's soucre code,i have a backup.But i do not know why the origin source link is invalide.Could i post the link's sources code in here? 1 Quote Link to comment Share on other sites More sharing options...
electric_vehicle_lover Posted November 28, 2016 Share Posted November 28, 2016 Hi @KingQueenWong. Thanks for the support words <3. And yes, I want to keep moving with this project. I never saw the sources from Shane Colton, if you have them, yes please share with me. You can also send me a private message here in the forum. Quote Link to comment Share on other sites More sharing options...
lizardmech Posted November 28, 2016 Share Posted November 28, 2016 3 hours ago, KingQueenWong said: @electric_vehicle_lover I come from China.My job is a hardware engineer,i love brushless contorl.Thanks to many open source and hardware project,i learn a lots. Maybe I can support somethings for the EGG-electric-unicycle project. I really sure that STM32F1 can implement FOC,even though it not very very high performances,but it very well enough.Beause some guy have implemented it,such as scolton Colton. I really hope that you can insist the owesome work and keep moving.You know that benjamin develop vesc over 4 years. The link's source is full opensource:http://scolton.blogspot.jp/2011/11/ah-software-optimization-my-old-friend.html I have the link's soucre code,i have a backup.But i do not know why the origin source link is invalide.Could i post the link's sources code in here? Hi @KingQueenWong do you have any experience writing balancing vehicle code? I have someone working on gyro drivers for VESC but I still need to find someone to help with the balancing algorithm code. But not many english speaking developers have experience with balancing vehicles. I don't mind even if I have to pay, if I can just find anyone with balancing vehicle coding experience it will help finish VESC powered unicycle. Quote Link to comment Share on other sites More sharing options...
KingQueenWong Posted November 28, 2016 Share Posted November 28, 2016 @lizardmech Firstly,i have some experience writing balancing small car; Secondly,usually i can't debug algorithm or code without hardware; Thirdly,i can support your something balancing algorithm and others tips; In the end,you can references some Arduino balancing small car codes which is very easy to learn and implement. Quote Link to comment Share on other sites More sharing options...
lizardmech Posted November 28, 2016 Share Posted November 28, 2016 1 hour ago, KingQueenWong said: @lizardmech Firstly,i have some experience writing balancing small car; Secondly,usually i can't debug algorithm or code without hardware; Thirdly,i can support your something balancing algorithm and others tips; In the end,you can references some Arduino balancing small car codes which is very easy to learn and implement. The main thing I need to find out is how it is done with brushless motors. Most balancing robot has stepper motors. Do you know if chinese balance vehicles just use the IMU sensor and kalman filter then adjust motor current in FOC mode? I assume that is how they work but I have never seen a brushless balancing vehicle code to see how it works. Quote Link to comment Share on other sites More sharing options...
Tomek Posted November 28, 2016 Share Posted November 28, 2016 1 hour ago, lizardmech said: The main thing I need to find out is how it is done with brushless motors. Most balancing robot has stepper motors. Do you know if chinese balance vehicles just use the IMU sensor and kalman filter then adjust motor current in FOC mode? I assume that is how they work but I have never seen a brushless balancing vehicle code to see how it works. my assumption is that there needs to be a PID loop between what comes out from the Kalman filter and what's sent to VESC (not sure if/how you should dynamically divide control across current and/or RPM and/or duty cycle) 1 Quote Link to comment Share on other sites More sharing options...
electric_vehicle_lover Posted November 28, 2016 Share Posted November 28, 2016 7 minutes ago, Tomek said: my assumption is that there needs to be a PID loop between what comes out from the Kalman filter and what's sent to VESC (not sure if/how you should dynamically divide control across current and/or RPM and/or duty cycle) I already tough on this. I think we don't need to control speed/RPM as when I ride my different EUCs, I understand that I don't keep the same... the speed depends only from what power I define by my balance. Also the speed lowers If I keep the same inclination balance but get over on a step hill. I think is only current control (means torque control). The speed controller is inside riders head, the rider do the PID control for the speed, by adjusting the torque the motor gives, by balancing forward/backward. I mean, from the balance angle is configured the motor current(==torque). Not duty cycle control, as duty cycle would mean no stable current/torque. Quote Link to comment Share on other sites More sharing options...
lizardmech Posted November 28, 2016 Share Posted November 28, 2016 One thing I don't know is if existing designs alter the control loop based on RPM or if they just use the same setting at all times. There seems to be two models to control inverted pendulum, conventional PID or active disturbance rejection control. ADRC newer and only has one variable but is less documented. Quote Link to comment Share on other sites More sharing options...
Tomek Posted November 28, 2016 Share Posted November 28, 2016 1 hour ago, lizardmech said: One thing I don't know is if existing designs alter the control loop based on RPM or if they just use the same setting at all times. There seems to be two models to control inverted pendulum, conventional PID or active disturbance rejection control. ADRC newer and only has one variable but is less documented. From the few examples I googled, ADRC seems to always complement PID in self-balancing robots. I think it would be a safe way to go to start with Kallman->PID->VESC_current_control, test it, tweak it, try riding it (full safe gear + some extra pillows duct taped .') ) and only start further adding more complexity based on the outcome of tests Quote Link to comment Share on other sites More sharing options...
electric_vehicle_lover Posted November 28, 2016 Share Posted November 28, 2016 @KingQueenWong Many thanks for the Shane Colton firmware and documents!!!! I don't know why but I missed the posts Shane talks about FOC and is great that he uses also the same STM32F103. I am now archiving Shane post and documents on my notes and I will read all of them later: 1 Quote Link to comment Share on other sites More sharing options...
lizardmech Posted November 29, 2016 Share Posted November 29, 2016 I have someone helping with the VESC and getting a MPU6050 driver running. I think the driver is mostly complete now we just need to work out how to get the data from it into the application thread, to run filters and convert it to motor current. But chibiOS is still a little confusing to us both in comparison to directly coding to the MCU which slows progress. https://github.com/votuananhs/bldc/blob/EUC-VESC_electronics/applications/MPU6050/MPU6050.c 1 Quote Link to comment Share on other sites More sharing options...
electric_vehicle_lover Posted November 29, 2016 Share Posted November 29, 2016 The code seems good!! Please let us know when the MPU6050_Init() is working/was tested. When that is working, then is time to finally to test MPU6050_GetRawAccelGyro(); Then you guys can go and test my code for balance, here: https://github.com/EGG-electric-unicycle/firmware-gen1_boards/blob/balance_control-1/src/IMU/imu.c // read the accel and gyro sensor values MPU6050_GetRawAccelGyro (accel_gyro); // takes abut 15ms to be executed!!! acc_x = accel_gyro[0]; acc_y = accel_gyro[1]; acc_z = accel_gyro[2]; gyro_rate = accel_gyro[5] * GYRO_SENSITIVITY; // calc dt, using micro seconds value micros_new = micros (); dt = (micros_new - micros_old) / 1000000.0; micros_old = micros_new; angle = atan2(acc_x, acc_y); //calc angle between X and Y axis, in rads angle = (angle + PI) * RAD_TO_DEG; //convert from rads to degres // angle = 0.98 * (angle + (gyro_rate * dt)) + 0.02 * (acc_y); //use the complementary filter. angle = (0.25 * angle) + (0.25 * old_angle1) + (0.25 * old_angle2) + (0.25 * old_angle3); old_angle1 = angle; old_angle2 = old_angle1; old_angle3 = old_angle2; // zero value error when the board is on balance current_error = INITIAL_ANGLE - angle; #define ANGLE_MAX 2 if (angle > ANGLE_MAX) angle = ANGLE_MAX; if (angle < -ANGLE_MAX) angle = -ANGLE_MAX; float kp = 1; float ki = 1; float kd = 1; float angle_old; progressive_term = current_error * kp; integrative_term += current_error * ki; derivative_term = (current_error - old_error) * kd; old_error = current_error; duty_cycle = progressive_term + integrative_term + derivative_term; motor_set_duty_cycle ((int) duty_cycle); // -1000 <-> 1000 1 Quote Link to comment Share on other sites More sharing options...
KingQueenWong Posted December 8, 2016 Share Posted December 8, 2016 @electric_vehicle_lover Yesterday, I went to MicroWorks's factory and touched to MicroWorks's boss and his engineer. I order two dual motor driver boards.The board support up to 2KW,and the board's communication protocol was made to order.Let us Have a look! 1 Quote Link to comment Share on other sites More sharing options...
electric_vehicle_lover Posted December 8, 2016 Share Posted December 8, 2016 I don't understand your message. Is that dual motor controller board for application of a segway or such? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.