WIP Beta released Saber - One Motor Per Wheel Electric Car

Discussion in 'Content Creation' started by Excrubulent, Dec 24, 2017.

  1. Excrubulent

    Excrubulent
    Expand Collapse

    Joined:
    Aug 8, 2013
    Messages:
    83
    This is inspired by the Rimac Concept One, which is an electric supercar with one electric motor per wheel. It has special torque vectoring that sends power to each wheel as needed. I'd like to have a crack at an offroad version of this, with some extra features, if I can manage it.

    So the first thing is, what is the current state of electric motors in BeamNG? From the looks of the RC pack of cars, it looks like they're just heavily modified petrol engines. If there aren't proper electric motors, are there APIs available that would allow me to send drive to the wheels using custom code, so I could program my own motors?

    Secondly, and I assume this is possible, I'd like to program my own ESC system to manage drive to all four wheels, using some PID loops. You could get some unreal behaviour out of this.

    Thirdly, what about custom steering controls? With this, I could create a four-wheel steering setup that would allow rear-wheel steer to be turned on and off for crawling, but beyond that, you could also enable a "turret mode", where the car could rotate on the spot like NASA's manned rover. Even without four-wheel steering, skid-steer mode would be possible if I have full control over the torque going to all wheels.

    How doable is all this stuff? Just assume I can handle the required programming for now, I'm curious if the modding APIs exist to enable this kind of behaviour.
     
  2. Excrubulent

    Excrubulent
    Expand Collapse

    Joined:
    Aug 8, 2013
    Messages:
    83
    Okay, thanks for that, nice to hear it's all theoretically possible!

    Also, I just noticed you're the author of the Outlaw - that's an awesome buggy! I was actually considering using the Outlaw as a base for this project, it has the kind of layout that I want. Would you be okay if I used it?
     
  3. Excrubulent

    Excrubulent
    Expand Collapse

    Joined:
    Aug 8, 2013
    Messages:
    83
    Great, thanks! If I do end up using it I will of course let you know and get confirmation before I do anything with it.
     
  4. AM-DB9

    AM-DB9
    Expand Collapse

    Joined:
    Mar 24, 2014
    Messages:
    106
    Electric motors have 2 major limitations as of now: they can't rotate in reverse and they need a clutch at their output as any other engine. Both of these things hamper their usage.
    I made a single-wheel traction experiment here (AIO drivetrain section).

    Workarounds are:
    1. Disable clutch assistant in game (care of the mod user)
    2. Use rangeboxes (as in dual speed transfer cases) instead of gearboxes because there's no way to shift multiple transmissions at once. Rangeboxes benefit from the UI applet so you can click on each of them. I used one negative and one positive value to obtain forward and reverse.

    Another issue is that most electric mods give a fatal vehicle exception when the ESC is present. This is a novelty brought by the latest game updates (example at post 104).

    6eng.jpg
    The speedometer in the cabin will work, not the applet one. Also the rev meter will go blank. Sound might be challenging, I didn't add sound.
     
  5. Diamondback

    Diamondback
    Expand Collapse
    Vehicle Systems Lead
    BeamNG Team

    Joined:
    Apr 8, 2014
    Messages:
    1,957
    What makes you think that electric motors can't rotate in reverse? :confused:
    Also the clutch is just a technical requirement, you can just always have it closed and completely ignore it.
     
  6. Diamondback

    Diamondback
    Expand Collapse
    Vehicle Systems Lead
    BeamNG Team

    Joined:
    Apr 8, 2014
    Messages:
    1,957
    All of this is perfectly doable. However you do need deep knowledge of Lua for the logic that controls the powertrain. The regular "car logic" won't get you anywhere.
     
  7. Excrubulent

    Excrubulent
    Expand Collapse

    Joined:
    Aug 8, 2013
    Messages:
    83
    If you're looking for an IRL explanation there are two answers, one for brushed motors and one for brushless.

    For brushed, the motor will apply torque if you apply a voltage across its two terminals. If you reverse the voltage, the torque direction reverses. I say "torque" because the torque can be accelerating or braking. Also, every electric motor doubles as a generator. When you apply a braking torque, that energy can be recovered to charge the batteries.

    A brushless motor is what any decent full-sized electric vehicle should probably have - I say full-sized because my experience is in RC cars. Anyway, for that you have an ESC (Electronic Speed Control) with three terminals. The ESC sends timed pulses of voltage to those three terminals to control the spinning of the motor. As far as I understand, if the motor has a rotation sensor, then the ESC uses that sensor to determine which terminals to send voltage to.

    If the system is "sensorless", the ESC can use the regenerative properties of the motor to detect where the rotor is and thus control the motor - as the motor spins and generates voltage, that can be detected. The problem with sensorless is that it needs movement in the motor to work, so at very low speeds you get "cogging" in the motor where it jerks as it tries to get the motor moving. Once it's rolling though, you're good. Also you can just punch the throttle and the motor will spin away and you'll never notice any cogging.

    An interesting property of brushless is that if you want to reverse a motor manually, you can simply swap the order of any two of the three terminals between the ESC and motor. However, the ESC is equally capable of controlling the motor to reverse, & brake. You can even hold the motor in place with the right voltage input.

    When you say "a deep knowledge of Lua", do you just mean it will take a lot of programming? If that's the case, that's perfect for me. I like attacking difficult programming problems. I've not done much in Lua, but in my experience once you learn the syntax & features of the language and you get a handle on the API you need, it's all just programming.
     
  8. Excrubulent

    Excrubulent
    Expand Collapse

    Joined:
    Aug 8, 2013
    Messages:
    83
    You can always try, the worst that'll probably happen is the game crashes. More likely you get an error. EDIT: But on the upside, it might work!

    Also, if you can send negative throttle to the quad, you can enable 3D flying (upside-down) and "turtle mode", which is something modern FPV quads are doing now so they can flip over by themselves when they land on their backs.
     
    #6 Excrubulent, Jan 5, 2018
    Last edited: Jan 5, 2018
  9. Excrubulent

    Excrubulent
    Expand Collapse

    Joined:
    Aug 8, 2013
    Messages:
    83
    Yikes, I see now. Well, that would be a reliability problem in the real world, since fixed-pitch quads have literally four moving parts compared to the MANY that you get in variable pitch, but at least in-game when it gets smashed you can just press a button and carry on. :)
     
  10. Diamondback

    Diamondback
    Expand Collapse
    Vehicle Systems Lead
    BeamNG Team

    Joined:
    Apr 8, 2014
    Messages:
    1,957
    Just set the motorDirection attribute of the powertrain device to -1 for reverse (1 means forward again, please don't use values other than 1 or -1, they are not clamped for performance reasons)
    Please be aware that, for obvious reasons, this has no effect on combustion engines.
     
  11. Diamondback

    Diamondback
    Expand Collapse
    Vehicle Systems Lead
    BeamNG Team

    Joined:
    Apr 8, 2014
    Messages:
    1,957
    Yea you'll have to custom code anything in that regard, which means you need to 1) understand how lua works (easy) and 2) need to understand how the game works (the hard part).
    Unfortunately at this point our documentation is very lacking to non-existant, so it's a lot of trial and error.
    However, I'm very interested in your project and can imagine working with you together on this, which at least somewhat solves 2) (since I wrote all the relevant game code ;) )
    I'm positive that a full electric car even with gimmicks like torque vectoring is possible in beam. If you are interested in a potential collaboration, please send me a personal message :)
     
  12. Excrubulent

    Excrubulent
    Expand Collapse

    Joined:
    Aug 8, 2013
    Messages:
    83
    Thanks for the motorDirection tip, and for this response! I'll send you a PM soon.
     
  13. Excrubulent

    Excrubulent
    Expand Collapse

    Joined:
    Aug 8, 2013
    Messages:
    83
    So I'm going ahead with this, and after talking to DiamondBack, I'm going to mod the SBR, to make things simpler. Then I might move on to a buggy or some other offroad vehicle once I've proven the concept. I'm having trouble breaking down the steps required though, the first thing I want to do is add the electric motors to the vehicle. Does anybody have any idea how I might get started doing that?
     
  14. Excrubulent

    Excrubulent
    Expand Collapse

    Joined:
    Aug 8, 2013
    Messages:
    83
    Okay, I have some progress, this is just some basic 3D modelling work, because I wanted something to visualise and because once I got started I thought I may as well finish the job. Here's what I have so far:

    2018-01-1322_19_38-Blender_C__Users_Marvin_Documents_himac_himacblend.png

    There are a number of things removed: engine, fuel tank, radiator, fuel lines, brake lines, brakes (wtf?! I'll explain), exhaust, basically anything required for internal combustion. I've also removed the driveshafts and the central driveshaft channel. That's all flat now. Oh, also the motor mounts on the rear subframe have been cut off with an angle grinder.

    I removed the brakes because they were where I wanted my motors. You can see in the image four objects outlined, they are my four motors, arranged in a motor-in-wheel configuration. My thinking with this is that for a start, motor-in-wheel eliminates all transmission-related weight and losses, and it also lowers the COG, which should improve handling. Obviously it will seriously impact how the suspension is set up, but that's way down the line right now. Also the parts that used to be brake discs are now "wheel mounts". Just the mounting bolts are left behind, and they are very thin, to accommodate the motors. If they need to be thicker I could create an indent in the motors to make space. Also the cylinders on the wheel hubs have been shortened, but I could likewise push them inside the motor and make corresponding holes.

    Also my theory about the brakes is that they should be either integrated with the motors, or entirely motor-driven. So you don't use physical brakes, you just use the motors to brake. "But what if the motors fail?!" I hear you cry. It's okay, this isn't real, nobody will die. Also, mechanical brakes fail too, but nobody's screaming about that every time they get into a car.

    So there are a few things I need to do:

    1. Once these changes are finalised I need to update the jbeams to suit. Maybe I could've left the meshes as they were, but in the end that wasn't possible. I also need to figure out how to remodel the rear wheel hubs, because parts of them are intersecting with the motors currently. I'm assuming intersecting parts are a great big ol' no-no.

    2. Then the next thing to do is find a way to make those motors functional. I've not done any of this before so I'm going to need some help with that.

    Should I continue asking for help here or should this go into its own new thread?
     
    #10 Excrubulent, Jan 13, 2018
    Last edited: Jan 13, 2018
  15. Excrubulent

    Excrubulent
    Expand Collapse

    Joined:
    Aug 8, 2013
    Messages:
    83
    Awesome, thanks for all the info. It's late night where I am now, so I'll get onto that in the morning and let you know if I have any questions.
     
  16. Excrubulent

    Excrubulent
    Expand Collapse

    Joined:
    Aug 8, 2013
    Messages:
    83
    Hmmm... what I'm reading here is that despite whatever technical merits motor-in-wheel might have, it's going to be more work. So it's out for now. I'm going to move the motors to the middle, where the diffs would go, and restore the front & rear driveshafts. I might also revert the changes to the subframe & body, so I don't have to do any work on those jbeam structures, at least for now.

    This also means there will be space for friction brakes, so if I want to include them, I can.
     
    #12 Excrubulent, Jan 13, 2018
    Last edited: Jan 13, 2018
  17. Excrubulent

    Excrubulent
    Expand Collapse

    Joined:
    Aug 8, 2013
    Messages:
    83
    Yeah, I'd like to do it properly, which means completely rejiggering the suspension if it's on the wheel, I didn't think much about that. Plus I still have to decide how the motor should fit in a very limited space. Screw that noise.


    The ESC stuff is my jam, no worries there. :) I see this motor placement & jbeam stuff as the annoying boilerplate needed for the real interesting work, hence my reluctance to complicate matters.
     
    #12 Excrubulent, Jan 13, 2018
    Last edited: Jan 14, 2018
  18. Excrubulent

    Excrubulent
    Expand Collapse

    Joined:
    Aug 8, 2013
    Messages:
    83
    So I've moved the motors and added a placeholder battery. I've also restored all the original parts and renamed any parts that have been edited, so as far as I understand, if I export this as a DAE it should still work with the stock vehicle configurations, but it'll have a few more parts in it.

    2018-01-1523_50_27-Blender.png

    The parts I've added you can see highlighted here. The motors are a lot smaller than they should be, and I don't really know how big the battery should be. I'll research that myself. I made the motors so small because otherwise they would clip through the subframes, and also through the driveshafts. So I'll need to push the driveshaft ends outwards, and make a bit more room in the subframes for the motors. But that's all in the future, this is all placeholder geometry to make the idea as clear as possible. Once I know a bit more about jbeams I'll be able to change this stuff around.

    Next up I'll need to create some jbeam structures for these parts & make the motors work.

    EDIT: Also, interestingly, the inside ends of the driveshafts are lower than the wheels, so contrary to what I said before, putting the motors on the wheels would result in a higher COG, not a lower one.
     
    #13 Excrubulent, Jan 15, 2018
    Last edited: Jan 15, 2018
  19. Excrubulent

    Excrubulent
    Expand Collapse

    Joined:
    Aug 8, 2013
    Messages:
    83
    Hey so after a year or two I've come back to this. Obviously having a stock electric SBR makes this whole process a lot easier than it was! I've named the project the "Saber".

    I'm trying to get the most basic proof of concept working, so I'm just trying to setup a motor that will only send power to a single wheel. I'm referring to https://wiki.beamng.com/Powertrain and https://wiki.beamng.com/Shaft.

    So far I've got an empty object that will serve as the mount for two motors, under which I've got the Rear Left Motor, then the Rear Left Halfshaft, then the final drive which is taken from the eSBR.

    Here's what it looks like in the inspector:

    2019-09-1514_00_10-Window.png

    I've also attached the two jbeam files I'm making.

    I'm really close to getting drive to the wheel. Here's where I'm at:

    - If I comment out the powertrain section in the halfshaft jbeam, then the motor just revs up instantly.

    - If I include the powertrain section but leave out the connectedWheel property (or set it to an empty string), the motor revs up slowly but the car does nothing.

    - If I include the connectedWheel property, the motor doesn't rev up, but when I drag the car by grabbing nodes, the revs increase, which indicates the motor is in fact connected to the wheel!

    So I'm getting somewhere, I just can't figure out why the motor won't move the wheel. Even if I beach the car so all four wheels are off the ground, pressing the accelerator still won't move the wheel, but pushing the car around does spin up the motor.
     

    Attached Files:

    #19 Excrubulent, Sep 15, 2019
    Last edited: Sep 15, 2019
    • Like Like x 2
  20. Excrubulent

    Excrubulent
    Expand Collapse

    Joined:
    Aug 8, 2013
    Messages:
    83
    Okay, quick update, if I switch the connectedWheel to RR, then I get drive to that wheel, although the gearing is so incredibly high it's got almost no torque. So at least that's the concept proven, I can spin up one wheel with a motor! Now to fix the gearing, send it to the correct wheel and make three more.

    UPDATE 2: Going to put updates here for now so I'm not spamming posts.

    I can get around the gearing issue by setting gearRatio on the halfshaft. It seems the final drive component has no effect on the halfshaft. It would be nice to be able to use the final drive system but I don't need it for this proof of concept.

    Also even with the gearing fixed, if I set connectedWheel to RR, it works, I can do one-wheel donuts to my heart's content. If I set it to RL... nothing. No response from pressing the accelerator. Again if I pull the car along then the motor spins up, but it just doesn't seem to want to drive anything. I'd love some help with this.

    UPDATE 3: So just trying the front wheels, I can send power to RR and FL, but not to RL or FR. Really strange, is this like an edge case where there's a bug, or is there something in my jbeams that's misconfigured?
     
    #20 Excrubulent, Sep 16, 2019
    Last edited: Sep 16, 2019
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice