1. Game not starting lately?
    Fixed in 0.19.4.2
    More information available here

    Dismiss Notice
  2. Intel iGPU (6xx series) crashes
    Fixed drivers available!
    Instructions here

    Dismiss Notice

WIP Beta released Saber - One Motor Per Wheel Electric Car

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

  1. Blijo

    Blijo
    Expand Collapse

    Joined:
    Apr 27, 2016
    Messages:
    2,069
    It must be a configuration error on your end, it is possible to have 1 motor per wheel, your powertrain might be misconfigured.
    I have found this thread today, which is too bad because I made something that could be interesting for you:

    For now, this thing controls the throttle for each motor, I just have to find a nice way to switch the direction of every motor. Hopefully without needing to modify/copy the exisisting code for the electric motors.
    Maybe you have found a way to do that already?
     
    • Like Like x 5
  2. Excrubulent

    Excrubulent
    Expand Collapse

    Joined:
    Aug 8, 2013
    Messages:
    83
    Hey Blijo!

    Pretty much my level of progress is what you see here. I had forgotten about the drivetrain debug GUI that I can see in that video, so I'll give that a try. If you want to take a look at what I've got it's in the jbeams I posted earlier. Just put them into a mod folder for the SBR to give them a try.

    I love the skidsteer, I really want to try it.
     
  3. Diamondback

    Diamondback
    Expand Collapse
    Moderator
    BeamNG Team

    Joined:
    Apr 8, 2014
    Messages:
    1,580
    It's perfectly possible to have one motor per wheel, all you need is one electricMotor and one shaft (connected to the wheel) each.
    I'm a bit busy atm, so can't look into what you have so far, but maybe this gets you somewhere :)
     
  4. Excrubulent

    Excrubulent
    Expand Collapse

    Joined:
    Aug 8, 2013
    Messages:
    83
    Okay, well thanks to the powertrain visualiser I discovered I was sending power to one halfshaft that I had made, and there were four unused halfshafts sitting around that were already part of the car. I had copied the eSBR rear diff jbeam and just changed the powertrain code from diff to shaft, but obviously there's a lot of extra bits and pieces there that must be messing up the config. Anyway, once I discovered the "wheelAxleRL" shafts, I found where they were kept in the stock SBR setup, copied those jbeams and reassigned their powertrains and now it works for both rear wheels. I'll just have to copy that work for the front shafts and create all the motors I'll need, then I'll be onto the fun part in code!

    Thanks for the help, Blijo. And also for the reassurance from both of you that it is in fact possible. :)
     
    • Like Like x 2
  5. Excrubulent

    Excrubulent
    Expand Collapse

    Joined:
    Aug 8, 2013
    Messages:
    83
    Okay, I haven't done any work in lua on the computer control, but I think this is already pretty good as a WIP. I've copied the eSBR 500 motors as is, but now there's twice as many, so I present the prototype Saber 1000! I have plans for a 1600 and maybe a 2400 version, because why not? I've also included a hillclimb config.

    Obviously it would make sense to redo the jbeams to separate the motors, but it works pretty well as it is, and that's something for later. Also, activating the traction control already tames it pretty well, I'm using the eSBR 800 TC. It spins the wheels initially, but if you look at the drivetrain visualiser you can see that it's independently throttling all four motors, which is really neat.

    And finally, because I got bored with having infinite torque and I wanted to explore top speeds, I also figured out the final drive issue, and now there are stock 7.6 final drives as well as race adjustable. I set the minimum gearing to 2 in anticipation of the 2400 model.
     

    Attached Files:

    #25 Excrubulent, Sep 17, 2019
    Last edited: Sep 17, 2019
  6. Excrubulent

    Excrubulent
    Expand Collapse

    Joined:
    Aug 8, 2013
    Messages:
    83
    I'm up to the stage of trying to program the controls, but I've never scripted in BeamNG before. Is that skidsteer done in lua at all? If it is do you mind sharing the file? It would help me get going so much faster to have an example to work from.
     
  7. Blijo

    Blijo
    Expand Collapse

    Joined:
    Apr 27, 2016
    Messages:
    2,069
    Here you go, throttle is determined by the steering angle and throttle input.
    Braking is the same but with brake input of course
    When you have no throttle input, it has just an output based on the steering.
    Works decent with a tire pack
     

    Attached Files:

    • Like Like x 2
  8. Excrubulent

    Excrubulent
    Expand Collapse

    Joined:
    Aug 8, 2013
    Messages:
    83
    Awesome thanks! It's basically a sherpa, it even floats. I love it. It's night for me now but I'll try to adapt this soon.
     
    • Like Like x 1
  9. Excrubulent

    Excrubulent
    Expand Collapse

    Joined:
    Aug 8, 2013
    Messages:
    83
    Mini update, still no scripting done, but I have included the 1600 and 2500 hp versions. Thanks to TommoT for letting me use their torque curves from the 1250 extreme eSBR. It's not the most drivable thing in the world though. The traction control doesn't know what to do and oscillates between oversteer and understeer, and without traction control the outside wheels always get more influence and tend to create a compounding oversteer effect. So I think to get this to work I'll need to tune up my own custom traction control, and I'll have my work cut out with the computer intervention to properly harness all this power.

    Oh, and in case anyone thinks 2500 hp is unrealistic, well, the Rimac Concept Two will reportedly have 1914 hp, so it's definitely within the realm of possibility.
     

    Attached Files:

  10. Justy4WDTURBO

    Justy4WDTURBO
    Expand Collapse

    Joined:
    May 14, 2016
    Messages:
    545
    Watching this thread with interest, even though I know jack about coding.
     
    • Agree Agree x 1
  11. Excrubulent

    Excrubulent
    Expand Collapse

    Joined:
    Aug 8, 2013
    Messages:
    83
    Haha, well I'm doing the coding so you don't have to. :) I'm hoping it gets results anybody can appreciate.
     
    • Like Like x 1
  12. Excrubulent

    Excrubulent
    Expand Collapse

    Joined:
    Aug 8, 2013
    Messages:
    83
    Okay, Blijo, I've been tinkering with the lua and I can see the troubles you were having reversing the motors. Any attempt to modify powertrain properties at runtime results in an error (EDIT: that might be wrong - it looks like the mainEngine_L object has a nil value, so I may simply need to find the right way to access it, but this workaround may still work for you). I've thought of a workaround, and it's a hacky pile of utter garbage, but I'm not above that.

    Here's the sample of jbeam that I've got:

    Code:
    "powertrain" : [
               ["type", "name", "inputName", "inputIndex"],
               ["shaft", "wheelaxleRL", "rearLeftMotor", 1, {"connectedWheel":"RL", "breakTriggerBeam":"axle_RL", "uiName":"Rear Left Axle", "friction":2, "canDisconnect":true, "electricsName":"wheelaxleRL"}],
               ["shaft", "wheelaxleRR", "rearRightMotor", 1, {"connectedWheel":"RR", "breakTriggerBeam":"axle_RR", "uiName":"Rear Right Axle", "friction":2, "canDisconnect":true, "electricsName":"wheelaxleRR"}],
               ["shaft", "wheelaxleRL_rev", "rearLeftMotor", 1, {"connectedWheel":"RL", "breakTriggerBeam":"axle_RL", "uiName":"Rear Left Axle", "friction":2, "canDisconnect":true, "gearRatio":-1, "electricsName":"wheelaxleRL_rev"}],
               ["shaft", "wheelaxleRR_rev", "rearRightMotor", 1, {"connectedWheel":"RR", "breakTriggerBeam":"axle_RR", "uiName":"Rear Right Axle", "friction":2, "canDisconnect":true, "gearRatio":-1, "electricsName":"wheelaxleRR_rev"}],
           ],
    So basically for each wheel I've got two shafts that can disconnect, and the reversed shafts simply have a negative gearRatio. If I want to send reversed torque, I just disconnect one and reconnect the other. Obviously this has problems at high speeds because the motors have their own intertia that will kick in as soon as this is done, but it might be fine for the skidsteer.

    My only issue now is how to disconnect/reconnect the shafts in code. I don't know what to invoke to make that happen.

    EDIT2: Okay, my final EVEN HACKIER solution is to create four duplicate reversed motors. They would throttle up when reverse motor torque was needed, and they would always be connected to the output shafts so there would be no problem with inertia. Maybe I could reduce the inertia and friction of the individual motors to simulate a single motor rather than two. If I can't find any way to enumerate and modify the powertrain devices in LUA, this might be the ultra-hacky solution.
     
    #32 Excrubulent, Sep 20, 2019
    Last edited: Sep 20, 2019
  13. Excrubulent

    Excrubulent
    Expand Collapse

    Joined:
    Aug 8, 2013
    Messages:
    83
    Okay, I've got basic computer control working! No reversed motors yet, that's coming soon. I'm currently just mapping steering input 1:1 with a left/right torque differential, just to explore the potential. Already it works well with the 1000hp model and I can drift controllably at about 80 degrees of angle without a lot of difficulty.



    My plan is to implement a PID loop to control yaw using left/right differential, then implement some understeer/oversteer logic, then I'll look at incorporating traction control so it's not just a hovercraft.

    One thing I need some help with is accessing sensors. I'd like to know how to access the car's g-force sensors, which I will need for the understeer/oversteer logic.
     
    • Like Like x 3
  14. Diamondback

    Diamondback
    Expand Collapse
    Moderator
    BeamNG Team

    Joined:
    Apr 8, 2014
    Messages:
    1,580
    Wait what? What are you guys doing there with duplicated motors and whatnot for reverse? :D
    Take a look at the official electric car shift logic to see how the motors can be easily reversed. :)
     
  15. Blijo

    Blijo
    Expand Collapse

    Joined:
    Apr 27, 2016
    Messages:
    2,069
    I know how you do it, just don't know (didn't put time in it) I can access that per motor yet :p
     
  16. Diamondback

    Diamondback
    Expand Collapse
    Moderator
    BeamNG Team

    Joined:
    Apr 8, 2014
    Messages:
    1,580
    Every motor has some property that determines its direction. Don't know the name by heart, but easy enough to look up in the code :)
     
    • Informative Informative x 2
  17. Excrubulent

    Excrubulent
    Expand Collapse

    Joined:
    Aug 8, 2013
    Messages:
    83
    Oh wait I figured it out! Based on what was in Blijo's code I was trying this:

    Code:
    rearLeftMotor.motorDirection = -1
    That gives the error that the rearLeftMotor's value is nil. But you can access the motor with this:

    Code:
    powertrain.getDevice("rearLeftMotor").motorDirection = -1
    Found that here: https://www.beamng.com/threads/vehicle-lua-reference.62186/

    That should help you with your skid steer, Blijo!
     
    • Like Like x 2
  18. Blijo

    Blijo
    Expand Collapse

    Joined:
    Apr 27, 2016
    Messages:
    2,069
    Thanks for looking that up!
    I changed that line in my lua code to be able to do neutral turns in "N" and it works great :)
    Video, should be online before power goes out here(scheduled maintance at 9AM on mondays, who the F thought that was a good idea):
     
    • Like Like x 3
  19. Excrubulent

    Excrubulent
    Expand Collapse

    Joined:
    Aug 8, 2013
    Messages:
    83
    Nice to see it working!

    Also I thought I'd show off my own portable showroom feature:

     
    • Like Like x 3
  20. Blijo

    Blijo
    Expand Collapse

    Joined:
    Apr 27, 2016
    Messages:
    2,069
    • Agree Agree x 2
    • Like Like x 1
  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