-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pedal assist support (PAS) #243
Conversation
This commit enables cadence-based pedal assist for ebikes using quadrature-style pedal speed sensors. There are 2 operation modes: * PAS only: Motor current is based only on pedal feedback * ADC + PAS: The code will use both ADC and pedal feedback and use the strongest command to provide seamless overlap when the user is pedalling and requests extra torque with the throttle. Signed-off-by: Marcos Chaparro <mchaparro@powerdesigns.ca>
Looks good! |
Glad its merged, I was about to post some datalogs to prove its has been tested.
I don't see any real problem with that. One potential problem is that usually a system with PAS most likely will have a display, and most displays use a serial communication so I wonder if people would struggle to have both PAS and display support if PAS takes the UART pins by default. Anyway, I'd say go for it, 2 lines of code are the least of their problems, ebike displays suck because they require some custom and undocumented wiring. There is another patch coming that provides support to some ebike displays but I'm leaving it for last as it provides very basic support, and will leave it for right before the product goes on sale :) |
Sick! |
I'm building ebikes for my family using the Sempu T9 pedal torque BB. It has analog torque and digital cadence outputs. I was planning to just use the torque output to command current (with braking, preferably). I can do this with the standard setup, using the torque sensor as the throttle input, right? This leaves the cadence sensor unused. (When I was still thinking of using an Arduino and another ESC, I considered using cadence for braking. Brake if torque and cadence are both zero.) Is there any advantage in using PAS mode over standard throttle mode? (Note that I'm new to VESC so I might be missing some basic concepts.) |
you might need to use the quadrature sensor (cadence) anyways to make sure the user is not pedaling backwards... |
What would be the issue to resolve if the user pedals backward? The torque will be zero, so it should slow/stop. |
Oh, I've been told that the torque sensor could produce an output when the user was pedaling backwards, but its not necessarily your case |
This one seemed to only register a change while torqued forward when I static tested it. Besides, these bikes freewheel so it's hard for me to imagine getting enough torque to register when backpedaling. Sidenote...the quadrature signal is handled internally on the T9 and a simple (single) square wave is output for cadence only for pedaling forward. I'm a little disappointed because I was hoping to use backpedaling to activate regen braking (like a coaster brake). Now I'm hoping to regen when torque and cadence are zero - like a very forgiving fixie. |
I am trying to understand the PAS code. In the current code, pas_event_handler() is polled instead of being invoked from ISR. As it is the case, if update_rate_hz is low enough, wouldn't it cause pedal_rpm calculation & thus torque control go wrong ?, sorry if I am wrong, based on code it is what I felt. Consider the default values for PAS variables, sleep_time = 2ms (1/500), i.e. thread would get invoked every 2 ms If both PAS signals are high when pas_event_handler() is invoked, new_state = 3. As both signals can be high during the next invocation of pas_event_handler() (as it would get invoked every 2ms), again new_state = 3. So per pas_event_handler(), Since period_filtered(0.048) < min_pedal_period(0.17), pedal_rpm would not be calculated at this point of time, this case is okay. Now suppose update_rate_hz = 100, thread would get invoked every 10ms, i.e., In this case, period_filtered(0.24) < min_pedal_period(0.17) is no longer true & hence pedal_rpm would get updated to a value that corresponds to the thread frequency & not to QEP signal frequency. If that is the case the torque would not correspond to the cadence. Based on the above, update_rate_hz should be a high enough value for the current PAS code to work, right? |
Yeah I used pretty high polling frequencies (500Hz), we could set a minimum update rate in vesc tool, or just hardcode it too 500Hz. Originally I intended to use interrupts, which is why pas_event_handler() was named that way. Interrupts were okay, but made the code diff a bit less clean for no real reason as it worked just fine without them. If someone else wanted to use different pins the change in the isr files would be a somewhat dirty so I settled for the polling approach. |
Thanks for the clarification |
Is PAS build into VESC Tool? |
The PAS app is great. It works when in PAS alone mode. However, I could never make it work in ADC + PAS mode. Only the ADC works when in the combined mode. I think it's due to the pas_event_handler() being polled instead of being invoked from ISR. I could be wrong. But could anyone test this and hopefully solve the problem? Thank you. |
When I coded this I only covered the use case where the ADC also has a brake signal:
In particular I use ADC_CTRL_TYPE_CURRENT_NOREV_BRAKE_ADC. My idea was to force an immediate motor release when the user applies brakes (many ebikes have brake sensors) because cadance PAS has like 1 second of ramp up / ramp down times and I don't want the motor to keep pushing when you are braking. My guess is that you are using ADC_CTRL_TYPE_CURRENT which doesn't read the PAS state. Not sure if we should include this mode. Should we? |
Yeah, you made my day! Thank you so much for your quick and valuable information. I didn't read your code carefully. ;) I did use ADC_CTRL_TYPE_CURRENT and when it didn't work I changed to a duty cycle mode and it still didn't work. Now I understand. I think you should include this mode or provide some tips on using PAS+ADC. By the way, I adapted your code to make my particular cadence sensor work. It works but not so predictable.. Sometimes the motor simply continue run even I stop pedaling. Could you check the code below and see if it could be improved? Thank you so much for your time. void pas_event_handler(void) {
#endif |
Have you tried longer ramp times? I configured VESC Tool to use 0.3s by default, but then we found that sometimes with shocks or vibrations the pas would be engaged and the motor spin. So we made the up/down ramp to be 1.2sec and the shock issue was removed. Definetively the help page could use some improvement, will try to make it happen on my next vesc tool PR |
That's very likely. Great tip again. I will try it in another day. I could never figure this out without your advice. Looking forward to your next PR. |
I really like it! i want to test it but i have a 3-wires PAS sensor, with GND, VCC and OUT. Is there any way to make it work? |
My PAS sensor has 3 wires like yours. You have to adapt the app code to make it work with your sensor, like my code snippet above. Or nitrousnrg may release a new version which incorporates the 3-wire sensor. To nitrousnrg: My pas sensor is indeed very unreliable. It has 2 hall sensors and 12 magnets, but only 3 wires. Even when I crank the shaft with my hand at home, it will be engaged quite frequently. I can tell this because I connected the signal wire to the tx pin. The led will light when magnet passes. |
@RobertXuChun Me too have 3 wire sensor. PAS code was adapted to take care of single signal instead of QEP, but I did not face the issues you mentioned about motor running with no pedaling. I then made the changes like you made (your code looked better than mine), still no issue was observed. Note that I am testing without connecting the sensor to pedal, i.e. tested by rotating rotary part of sensor by hand (rather finger). Sensor was part of a bicycle conversion kit, checking signal in oscilloscope, it seems to be a 12 magnet one. |
@nitrousnrg Unreliable motor stop after stop pedaling. Every time when stop pedaling motor stops very slowly. I think this is wrong way. Motor must stop immediately after stop pedaling. |
I guess I need to disable uart. I use default hw_config, no modification of source code. |
@afzalmam @RobertXuChun @albertomercurio Could you please help me to build vesc tool for 3-wire PAS? How can I change PINs so I can use a display on the UART port? |
@afzalmam did you see the first message? There is an instruction how to change pins. You will face problems with PAS what I mentioned. But if you plan to ride fire or paved roads it will not stop you... |
@adnion Code snippet by RobertXuChun above in the thread works for me |
@nitrousnrg i have gearless e-cycle and the location here has a lot of high gradient slopes. It was difficult to ride uphill with Cadence control. To make ride comfortable in my situation, a new control type - Constant Torque has been, more details in the pull request - #346, let me know if you have any comments |
Hi guys, Please bare with me being a beginner. I would like to connect the VESC to my Tongsheng TSDZ2, the phase wires and hall connectors are simple enough. How should I connect the torque sensor to the VESC pins for the stock firmware? The TSDZ2 has a torque sensor with only 2 wires, black and red. Where should I try to connect those? If I want to do throttle and PAS would I choose PAS + uart? or just select PAS and constant torque? I will eventually want to try livello's version after I figure out how to get this torque sensor working, so i could use the other SWDIO, SWDCLK pins for PAS instead and have comms for throttle and uart for bluetooth. TIA for the help. |
I have noticed the exact same behaviour |
@TreadMTB But torque sensor is very complicated. Also, there is no place to hide vesc controller inside motor. So why you need vesc on TSDZ2? For smooth ride? For more watts? The best and only way of using torque sensor on TSDZ is to keep stock controller and make him send data from torque sensor to vesc. But it is complicated. You must keep calibration feature... TSDZ2 has his own open source firmware with a lot of functions. |
does anyone have a link to a compatible quadrature PAS ? |
any one for Cycle Analyst V3 should work (there are some links in this thread, check my comments), just power up the PAS with 5V, and trust @jon2con on that 5v is fine on RX/TX lines, or use a 5v - 3.3v converter to step down voltage from the 2 signals of the pas. |
I was planning on putting the controller externally to lower the heat in the system. Also this would give the space needed to put water cooling for both. I would love the ability to run 36-72v and throttle + torque sensing PAS. VESC is easily set up with throttle, but I wouldn't want to give up the torque sensing PAS. How can I keep the TSDZ2 controller and have it send it's torque/cadence data to the vesc? |
I think you should buy some of the original ones from china(be sure to read the specs, most but not all run off of 5v input), they are cheaper priced and also not modified to the higher voltage/price/longer cable by grin tech. Then you can also avoid having to buy that voltage converter in the first place. My statements apply to their torque sensors, I'm not sure about if they have modified the input voltage on their cadence sensors(although I'm sure they put a good mark up on them). TLDR don't buy torque sensors from grin unless you like paying more and having to buy something extra to wire in just to get it back to 5v input. |
I haven't yet found a quadrature one from china, if you do please put the link. Grin uses these "Kingmeter". I was able to find one in Germany for 25€. |
You can make cables longer. Two wires from torque sensor and four wires from hall cadense sensor. Lot of work. Lot of tests. Weeks, months, depends on your skill. If you have a lot of time and no money... Go, try. But much beteer is to buy bafang ultra with vesc-based controller or keep stock one... |
Sorry to ping an old thread -- are you just using the torque output signal directly to, say, ADC1? |
I have a Mini Vesc 4.20 with broken mini usb connector. Actually it should run from the connections, if I select ADC and UART, only the software does not start the support for PAS although the connections fit. When the Miniusbbuchse still went, I could make the engine run via laptop with the newly assigned PIN ADC/ADC2 and the selection PAS. |
Can I get a connection from the Vesc tool without mini usb and without Bluetooth(UART), for example about the SWD Port? |
By default the PAS app uses the UART pins for the quadrature sensor, this is the reason there is no PAS+UART app
|
@007trains : thanks. Ok. I am not a professional. Please check my thinking . In the first step my friend adjusted the hwconf/hw.h. The signal of the QuadraturPAS is now processed by the PIN ADC +ADC2. Then I would have to select the App Application "PAS" in the Vesctool. So that the connection via BT (UART) still exists another adjustment is necessary. To get around this you need to reassign the HW PAS pins (your friend has already done this) case APP_PAS: After that the PAS works on ADC + ADC2 and the controller is still reachable via BT. Remind: I need the BT connection because my mini USB socket is broken. Thanks for your help |
Yes your correct in your thinking, in order to get Bluetooth working the next step is to add the line:
into adc.c under That will start the UART when the PAS app is selected so you can use Bluetooth to connect to VESC while the PAS app is selected |
I just found this Pedal assist support (PAS) for vesc. I have been looking for something like this to build my own eMTB with som extra power, especially the ADC part, i feel is missing for most eMTB. When you reach a section where you cant pedal because your pedals will touch the ground it would be nice to push the throttle to get through. Does it work like this? Also I dont mind using a more powerfull moter even tho the motor is limited to 250w, I think by law, for eMTBs, noone will notice as long as I just use the extra power for the throttle on extra technical parts on the trail. Also, I guess this supports adjustable throttle, regenerative braking and would be most convenient to use on a hub motor, but I wonder if there is any suggestions to make the regenerative braking work on a mid-drive-motor? I was thinking about adding a secound chain on the opposite side of the chain used for pedaling and find some way to activate it when using regenerative braking. |
3 wire pas to work, just set a variable "pas_one_magnet" true |
mistakenly filled in the wrong file. fixed |
what does it mean? 1 pulse per 1 round? Or 1 hall sensor in pas sensor? |
this variable in my code, changes the operation of the controller to read a 3-wire sensor with 1 hall Unfortunately, my bike is not ready yet, so I conduct experiments on the table. |
guys, I tried at the beginning of the year, the stock fw 6.0 version, and it still had a very laggy stop (aka, it takes 1-2 secs to cut off power to the motor after stop pedalling). Does anyone know if this has been fixed now in the master branch? is it worth for me to try again ? |
@rupebac pas works the same. But new problem arrived, if cadence is higher than max value. |
|
Could you tell me which input did you connect the 3 wires of the pas sensor to the vesc? |
I cant find case APP_PAS, so im bit confused where to add -TukkiS |
Found it! |
This commit enables cadence-based pedal assist for ebikes using
quadrature-style pedal speed sensors.
There are 2 operation modes:
the strongest command to provide seamless overlap when the user is
pedaling and requests extra torque with the throttle.
For this to work it needs the PAS hall sensor pins configured in the hw_xxx.h,
this is an example:
I'm preparing a VESC Tool Pull Request that unlocks the GUI side of this.