EFeru / hoverboard-firmware-hack-FOC

With Field Oriented Control (FOC)
GNU General Public License v3.0
1.15k stars 957 forks source link

Joystick control #66

Closed farev closed 4 years ago

farev commented 4 years ago

Hello, this project was really helpful for me it is the only hoverboard-hack code that runs smoothly. I am building a mini go-kart and I want to control with an analog joystick I tried setting up the code for this but I couldn't, I can't control it very well. Can someone please help to set it up correctly for my analog joystick.

Or is there a tutorial or instructions I can follow to correctly controll it with an arduino?

EFeru commented 4 years ago

I'm happy to hear that you like the project. What type of joystick do you have? And I am a bit confused when I read Arduino and joystick together, what is the Arduino purpose?

As a side note you can also use 2 pedals with VARIANT_HOVERCAR of the firmware which is all already completely ready to use. You can check the Hovercar video in Readme page to see how it looks and if you like it.

farev commented 4 years ago

I am using an analog joystick, that is just two potentiometers together. A picture of the joystick: https://www.google.com/search?q=analog+joystick&rlz=1C5CHFA_enGT877GT877&sxsrf=ALeKk01HagegYZcXhoeEO0exbg4JlSgH7Q:1592511648157&source=lnms&tbm=isch&sa=X&ved=2ahUKEwin0dqYmIzqAhVOn-AKHUIkDxEQ_AUoAXoECAwQAw&biw=1417&bih=671#imgrc=vSuR7hnQ3RTpAM

When I mentioned to use an arduino I meant that if there are instructions I can follow to controll it with arduino instead of the joystick, because I do not know how to set it up correctly.

EFeru commented 4 years ago

For joystick control is very easy:

EDIT: Arduino control is also possible via the Serial port.

On the other hand, I still consider that pedals are more suitable for Go Karts. You can buy 2 of these for example: https://www.banggood.com/custlink/mmG32e8i46

farev commented 4 years ago

Than you, only how do I select VARIANT_ADC in platformio.ini, do I just remove the semi colon?

EFeru commented 4 years ago

yes

farev commented 4 years ago

I was able to get it all set up but it isn't working properly. It moves when it is at the center and when I move it forward or to the side it does not move the motors as it should.

EFeru commented 4 years ago

When is at the center it moves because the ADC is not calibrated. And what do you mean by "not moving as it should"?

farev commented 4 years ago

Likw when I try to move forwars only one motor moves forward, or when I try to turn it stops, it does different mivements than the ones to turn, or to move forward. How do I calibarate it? Maybe that is the problem.

EFeru commented 4 years ago

Have a look here: https://github.com/EmanuelFeru/hoverboard-firmware-hack-FOC/blob/85552b3e41f383475990a26f85ae4290f571388e/Src/util.c#L398-L406

farev commented 4 years ago

I did it but it is still the same.

farev commented 4 years ago

Also when I turn it on it doesn't move until a little while after I start randomly moving the joystick.

farev commented 4 years ago

I tried with a normal potentiometer and I calibarate it and I found out that both motors ,when trying only the speed, don't roatate at the same speed.

EFeru commented 4 years ago

Can you try swapping the motor phase wires? Sounds like the motor wires or hall sensors are not mapped correctly. Also if you make a short video it will be easier to understand what is going on.

farev commented 4 years ago

Here is a video: Video.zip

farev commented 4 years ago

Also now after I accelerate and then stop it turns off.

EFeru commented 4 years ago

From the video looks like the motor phases are not correct (even thought the colors are ok). Try swapping them. Apply small input and check how it behaves.

farev commented 4 years ago

I tried sawapping the mtor wires and when it started moving it inmediatly turned off. I think my motherboard died because it doesn’t turn on any more.

farev commented 4 years ago

It doesn't turn on with the button, I tried another button and nothing, but it does turn on if I connected to my computer with 3.3v connected. What may have happenned here?

EFeru commented 4 years ago

I think one of the TIP27 might be damaged. Can you check it with an multimeter?

farev commented 4 years ago

I got it to turn on again but the motors are still not moving correctly. I tried different phase mapping and it still dirrent work.

EFeru commented 4 years ago

did you fixed it?

farev commented 4 years ago

Yes, it turns on now but I still can't controll it correctly with the joystick. Do you know if someone else has tried to use an analog joystick?

farev commented 4 years ago

Now the mainboard turns on and makes the sound but it then immediately turns off without making any sound. How do I check if a TIP27 is damaged with my multimeter? I tried it but couldn't figure out if something was wrong.

EFeru commented 4 years ago

If it doesn't hold power on, then one TIP27 I guess is damaged. You can check them for continuity, I think one of them is shortened.

farev commented 4 years ago

Some of them are passing like 0.2 or 0.7v and others are passing the complete voltage of the battery. Which ones are the broken ones?

EFeru commented 4 years ago

That I am not sure. Maybe you are better at electronics than me: https://www.st.com/resource/en/datasheet/tip120.pdf

For me when they broke they were usually shortened.

joedeveloper commented 4 years ago

Just FYI, I did a quick test with a cheap analog joystick connected to Arduino and then sending the massaged values to the hoverboard via uart, this works for me. Personally I find using direct connect adc joysticks potentially dangerous - I haven't tried on this firmware, so maybe the calibration / deadband / out of range logic is solid. The problem with wired joysticks are manyfold - from induction, to handling physical wear and tear a runaway condition can happen both on shorts and disconnects etc.

My plan is to have an esp32 connect to the hb over uart, then process control data from a wireless source - at least then you know you have to deal with out of bounds data gracefully.

farev commented 4 years ago

Thank you for your help, could you send an example of your arduino code please. I have never used uart with an arduino.

joedeveloper commented 4 years ago

I modified the arduino sample included in this repo only very slightly: https://gist.github.com/joedeveloper/8b26ffa01f513a67e004164667ced5bc

the values I add / subtract here are specific to the cheap joystick I am using for testing. Dont forget to read the docs in this repo carefully regarding pins, only one of the uart connections ( the default one ) is 5v tolerant, as you would need to communicate directly with the arduino.

EFeru commented 4 years ago

I agree that joysticks resting at middle could be more dangerous. Normally, you should solder pull down resistors on the ADC pins, so in case of wire disconnection, the value is pulled down, making the ADC go out of range and by that it will go to a safety state. For this protection the ADC_PROTECT_ENA needs to be activated in config.h

The classic potis resting at the lower bound (not middle) are safer to me.

Of course, depends on the application is better to work with digital signals. Like it was mentioned esp32, no need for ADC calibration, and the signal can be very clean, depending of the input source, for e.g. your smartphone or other digital device connected to the esp32.

farev commented 4 years ago

Can I use a bluetooth hc05 or hc06 module the same way as a esp32?

EFeru commented 4 years ago

I am not familiar with the bluethooth module, but I see they output UART data. What is the format of the UART data? Can it be programmed? Because the mainboard expects a certain UART data format. ESP32 gives can be programmed so it is quite flexible, but I am not sure if the hc05 can be programmed or not.

farev commented 4 years ago

No I would have to use an arduino to use it.

farev commented 4 years ago

I am trying to control it directly from the arduino but I can't get it to move it just beeps. Does the arduino need a seperate power source or can I connect it to the 3.3v in the mainboard?

EFeru commented 4 years ago

For testing, you can power the Arduino externally. Use the example sketch.

farev commented 4 years ago

I couldn't get the test working with the arduino, it just beeps.

EFeru commented 4 years ago

What Variant are you using. Make sure you connected the arduino to the right cable and wires. Tx to Rx, Rx to Tx.

farev commented 4 years ago

I am using the USART Variant and I connected it correctly, do I need to connect the gnd too?

EFeru commented 4 years ago

Yes, sure. Otherwise there is no proper TX RX high and low level, it would be just floating input.

farev commented 4 years ago

Even with the gnd connected the motors don't move when I try using the arduino.

EFeru commented 4 years ago

That is strange.. in my testing it worked. Is there a posibility to check with an oscilloscope or an FTDI debuger to check if data is send by Arduino Tx and that data is send by Mainboard Tx?

farev commented 4 years ago

Could this be happenning because of a faulty motherboard? I don't if my motherboard could be fualty.

EFeru commented 4 years ago

If the melody is playing and the board turns on off properly, I think the board is ok.

farev commented 4 years ago

I tried several times but I can't get it to work with the arduino, I tried checking with the arduino serial monitor if it was recieving and sending correctly but it didn't print what it should. The rx light in the arduino lights up but the tx doesn't, could the arduino be the problem?

EFeru commented 4 years ago

On the Arduino did you use pin 2 and 3? Those are the pins that should go to the main board not Tx and Rx (see the Arduino code)

farev commented 4 years ago

So I got the test running it worked fine, but when I tried it with the joystick and the modified arduino code it didn't work. It moved the wheels very little and not smoothly.

EFeru commented 4 years ago

What was the issue?

EFeru commented 4 years ago

As soon as you add additional code in the main loop, that can crate delay Arduino code must be a bit optimized, that is just an example. Better is to do the sending in a periodic interrupt.

farev commented 4 years ago

To get the test working I had to reflash again the motherboard becuase I found out that if you conected the pins wrong one time you had to flash it again to make it work. How do I do the sending in periodic interrupt?

EFeru commented 4 years ago

https://www.instructables.com/id/Arduino-Timer-Interrupts/