How to get active parking brake

This is crazy, having a print statement anywhere in a loop will just overtake everything.

LISP on VESC Tool very much seems like a work in progress. It’s as if the code is running parallel on the same thread. It would print repeatedly but not run any other code in the loop.

Why LISP was chosen instead of literally any other programming language is beyond me. Python is the obvious choice to make it programming friendly. C++ would have been a good choice.

Well whatever, can’t complain too much when it’s free, but it’s boggling. They even programmed it in C and said themselves they’re still learning LISP.

2 Likes

Well, I guess that’s it. LISP is just plain awful to work with, but it doesn’t take much to do what I wanted:

(print(get-adc 0))
(print(get-rpm))

(loopwhile t
  (if (< (get-adc 0) 0.5)
  
    (if (< (abs(get-rpm)) 200)
     (set-handbrake 50)
     (set-handbrake 0)
    )
    
    (set-handbrake 0)
  )
)

My plan with the remote-less skateboard is to have two “pedals” that I can easily press when needed. I can have it so the acceleration happens while my foot is on the pedal and then maintains the current when I take my foot off. Then it’ll slow down when I press on the brake pedal.

Left foot accelerates, right foot brakes. They’ll also be weight sensors instead of just pressure pads, which is something that I can either take advantage of or might be too unreliable. If that doesn’t work out, I have some other ideas.

And if all else fails, I’ll have a stupid remote ;(

May have to alter the code a bit, though this very well could be close enough to perfect. The 200 will definitely have to change. It has to be a value low enough that the skateboard doesn’t dead stop while going too fast, but high enough it doesn’t think it’s moving when it’s really just braking while overcoming something like a slope. I’d have to test, but I think there’s likely a very large sweet spot.

Did I mention how stupidly unintuitive if statements are? Whoever made this language definitely wanted to look important while programming.

3 Likes

Well, looks like LISP and regular old VESC tool don’t exactly play nice.

LISP takes up valuable CPU time running a loop which interferes with regular operation.

Two solutions:

Stop using App input all together and rely solely on LISP code to run the motor.

Or be reasonable and figure out how to do some multithreading.

I’ll update with code once I figure this stupidity out.

2 Likes

Well, it didn’t need threading, it just shouldn’t constantly set handbrake current while not braking.

However, I can’t get the handbrake to work at all without turning ADC off manually in the settings. I used “(app-adc-detach 1 1)” which should (and does) stop the motor from acting on ADC input. But I noticed that using that command alone makes the motor draw 1-2 amps of braking current. This stops by settings ADC to just current and no brake.

Even then, the handbrake still will not work, and the motor will just make a ticking sound for every loop iteration. Turn ADC off manually, and it works no problem.

At my wits end for tonight. If anyone has any idea what’s causing that issue, would help a lot. It’s the final nail in the coffin.

Getting regular App input to play nice with LISP is such a pain, I am actually really considering just having input off and programming my own current logic… in LISP… shudders.

Functional programming my ass

4 Likes

Oh, well I changed ADC update rate to 1hz, then it did a 180. It’ll handbrake and once a second it’ll make a tick where it wont.

This confirms that even though I’ve detached ADC input, it hasn’t actually stopped the update loop for ADC input which then interferes with the code.

Anyway, I’ll have to figure it out tomorrow. Here’s the code I have so far, idk if anyone is even interested or reading this stuff anymore:

(define rate 1)
(define braking 0)

(define one 1)
(define zero 0)

(print(get-adc 0))
(print(get-rpm))


(defun brake()
    (progn
      (print "Braking")

     (if (eq braking 1)
      
      (progn
      (print "1")
      (set-handbrake 25)
      )
      
      (progn
      (print "2")
      (app-adc-detach 1 1)
      (set-handbrake 25)
      (define braking one)
      )
      
     )
    )
)

(defun unBrake()
     (progn
      ;(print "unBraking")
      
      (if (eq braking 1)
      (progn
      (app-adc-detach 1 0)
      (set-handbrake 0)
      (define braking zero)
      )
      )
     )
)

(defun loop()

    (progn
    
        (if (< (get-adc 0) 0.5)
            (brake)
            (unBrake)
        )
        
        (yield (/ 1000000 rate))
        (loop)
    )
)

(loop)
3 Likes

Hey @zapshe you should copy and paste all of these comments to the official VESC forum so Ben can see all of this.

2 Likes

He can see it here, this is a public thread. :crazy_face:

2 Likes

Ben has better things to do than hang around this corner of the web.

@zapshe are you on discord? You should hit up the official VESC project discord. Lots of peeps on there would love to see and help with your work.

3 Likes

Well, just started a thread on the VESC forum. Was hoping I’d be done with the programming side of all this yesterday ;(

If I don’t get any replies on there, I’ll hit up the discord.

Seeing the LISP documentation makes me believe it wouldn’t be particularly hard to just drive the motor using LISP code and not using the regular ADC control. But it’ll be a waste of time if there’s a real solution.

I’ve also noticed the documentation isn’t as thorough as I thought, with some important things missing that I only noticed from skimming Ben’s coding videos.

Group hug :pleading_face:

3 Likes

20220814_160726_1

I’ve tried something similar and I would recommend attaching an ebike twist throttle to your leg instead. Much more reliable, easier to control, no handling quirks, low latency, great resolution.

2 Likes

Oo, that seems like a nice idea. They’re pretty cheap too. I already have some weight sensors, so I’ll try that out first. But I’ll try bike the twist throttle after if it sucks.

Thanks for recommending the Discord! Someone pointed out conf-set which worked perfectly. It didn’t just detach ADC input, but completely turns off ADC control like I wanted! Documentation also says the value isn’t stored in flash, so even if you shut down the system while ADC input was turned off, it’ll be working again as usual when you turn it back on.

Now that I’ve supplied the code, no reason everyone can’t have amazing braking at 0RPM! It bugged me so much because there are so many threads where people wanted to have this braking capability but no one had code to share to do so.

This final code is optimized and runs an RPM check. The RPM value is from testing with my hands, so basically worthless. It’ll be different for every person’s setup anyway.

So anyone who wants to use this will need to adjust the RPM at which the handbrake will be able to activate (to avoid accidentally turning on while you’re moving too fast) and the amperage that the handbrake should operate at.

(define rate 10)
(define braking 0)

(define one 1)
(define zero 0)

(define brakeVal 30)

(print(get-adc 0))
(print(get-rpm))


(defun brake()
    (progn
     (if (eq braking 1)
      
      (progn
       (set-handbrake brakeVal)
      )
      
      (progn
       (conf-set 'app-to-use 0)
       (set-handbrake brakeVal)
       (define braking one)
      )
      
     )
    )
)

(defun unBrake()
     (progn
      
      (if (eq braking 1)
       (progn
        (conf-set 'app-to-use 2)
        (set-handbrake 0)
        (define braking zero)
       )
      )
     )
)

(defun loop()

    (progn
    
        (if (< (get-adc 0) 0.5)
        
         (if (or (eq braking 1) (< (abs(get-rpm)) 200)) 
          (brake)
          (unBrake)
         )
         
         (if (eq braking 1)
          (unBrake)
         )
         
        )
        
        (yield (/ 1000000 rate))
        (loop)
    )
)

(loop)

LISP functional programming is a hard pass for me.

5 Likes

This was really cool to watch the code progress!

So after this code is loaded into the VESC tool, it will apply the parking brake anytime the eRPMs are below 200 and the throttle is at rest, and turn off when you give it throttle? I wonder if I change the app from ADC to PPM if it would work with a remote?

3 Likes

Yes, should work fine. I haven’t tested with PPM, so there may be unexpected problems. But I don’t see why it wouldn’t work.

For me, the handbrake engages when throttle is set fully back. I’m actually just using a B10K potentiometer atm LOL, so I don’t have to hold any throttle to keep it in that position.

However, I can see it would make a lot of sense to want parking braking at a certain input range rather than just below a certain input value.

The code also isn’t exactly beginner friendly. Here’s a reworked version where you only have to change variable values for the most part. If anyone runs into a hiccup, I can help out.

BE CAREFUL USING THIS! I only know it works for my setup, have your off button handy just in case!

; Only Change hz If You Need Faster Responsiveness
(define hz 10)
(define isBraking 0)

(define one 1)
(define zero 0)
; -------------------------------------------------


; Braking Current  (CHANGE)
(define brakeVal 30)

; Input Range For Handbrake to engage
; inputTop is the top of the range, inputButtom is the bottom of the range

; Input Value Which AT/BELOW To Engage Handbrake (CHANGE)
; Negative Value Means Handbrake Will Engage At Any Value Greater Than inputBottom
(define inputTop 0.5)

; Input Value Which AT/ABOVE To Engage Handbrake (CHANGE)
; Negative Value Means Handbrake Will Engage At Any Value Less Than inputTop
(define inputBottom -1)

; RPM At Which You'd Be Too Fast For Handbrake To Engage (CHANGE)
(define RPM 200)

; Value 2 = ADC, Value 1 = PPM
(define inputType 2)

; THIS IS FOR ADC INPUT
; FOR PPM, CHANGE:
; ALL (get-adc 0) to (get-ppm)
; inputType to 1


(print(get-adc 0))
(print(get-rpm))


(defun brake()
    (progn
     (if (eq isBraking 1)
      
      (progn
       (set-handbrake brakeVal)
      )
      
      (progn
       (conf-set 'app-to-use 0)
       (set-handbrake brakeVal)
       (define isBraking one)
      )
      
     )
    )
)

(defun unBrake()
     (progn
      
      (if (eq isBraking 1)
       (progn
        (conf-set 'app-to-use inputType)
        (set-handbrake 0)
        (define isBraking zero)
       )
      )
     )
)

(defun loop()

    (progn
    
        (if (and (< (get-adc 0) inputTop) (> (get-adc 0) inputBottom))
        
         (if (or (eq isBraking 1) (< (abs(get-rpm)) RPM)) 
          (brake)
          (unBrake)
         )
         
         (if (eq isBraking 1)
          (unBrake)
         )
         
        )
        
        (yield (/ 1000000 hz))
        (loop)
    )
)

(loop)
1 Like

My only concern with a handbrake range would be if the RPM value is set wrong and you pass by the handbrake range accidently, you’ll go flying for sure. If you’re strapped to the deck of the skateboard, you will both go flying :joy:.

Wish I could edit my posts. You can also skip dealing with RPM and use (canget-speed id) instead (replacing “id” with the actual CAN id). That’ll give you you’re actual speed in meters per second. You can then just adjust the variable RPM’s value for a m/s speed and would work fine.

Lot’s of tweaking can be done to the code. I don’t have a board yet to tinker with, so this code may have a couple faults.

2 Likes

Just post more and do the forum tutorial thingy

Well, I put together my skateboard, haven’t yet attached the motor to it. I took the skateboard out for a test drive the old fashion way…

And I suppose it’s time to say that I’ve never actually had a skateboard before. I haven’t really ridden one :zipper_mouth_face:. Skateboards looked boring and slow. However, these higher end skateboards can go pretty fast, it’s crazy.

I skated (poorly) to the top of a hill, on the way down I must have hit 25MPH. HOW DO YOU STOP?! I know people say to grind one foot against the ground, but how do you take a foot off?! Is it because my truck is a double-king pin? When I take a foot off, I can’t control if it starts leaning right or left.

This obviously wont be a big deal once there’s a motor, but what if something happens and I need to stop it myself?!

So far, I’ve been jumping off and running off my momentum and letting the skateboard ride into oblivion.

Otherwise though, was really fun! Went down that hill a few more times, nearly broke my foot on the last attempt to stop LMAO. I’m getting the hang of riding it pretty well though.

I also wanted a low profile skateboard, it’s only 24 long. I was worried the wheels would take up space and that I wouldn’t get enough footing on the 24" long board, but that was no issue at all.

I’ll need to ride it a little longer before I’m comfortable enough to know where I’d like to place the acceleration/braking aspects on the board.

3 Likes

Yeah this is pretty much exactly why. At least not without a decent degree of skill. With DKP you’re mainly limited to sliding to stop and slowdown, and Colemans.

This is why people say “learn to sk8 before you esk8”

It’s not mean, it’s for your own good.

Once you hit serious speeds, this is a great way to break a leg or two. I twisted both ankles simultaneously doing this.

Roll. Don’t run.

This is the smart way to do things. Walk before you can run.

1 Like

Because you said this, I will now fly before I crawl.

I had success with bending down and grabbing the skateboard. Then I could comfortably put a foot on the ground to slow down. Not ideal, but if it works.

Ouch. I’ve gotten pretty good at it from being an idiot and jumping onto treadmills while they’re already moving fast. Though if I’m going too fast I’ll definitely roll.

The wheels are super super smooth and quiet. Only exception is the wheel where the motor should be mounted on, which has the wheel gears on a secondary 10mm axil. They didn’t provide a washer for it which they should have, so the bearing is rubbing against the metal truck. Bought some here:

TrackStar Pro Shim Set - Inner 10mm (10pcs) (hobbyking.com)

They were pretty hard to find!

Anyway, will be testing out ways of controlling the board without a remote. Skateboard looks pretty cool! I cut out the deck myself. It kind of looks like a mashup of the Batmobile and the Cybertruck :joy:

1 Like