Google Bard and using it to write code to control an engine, calling sql experts!

Beneteau381

Well-known member
Joined
19 Nov 2019
Messages
2,087
Visit site
I have just started playing with Bard, scary! But it is a bit childish as well.
Anyway, I noticed it was offering to write sql so I asked it to “write code to control an engine” as an experiment.
this is what it came up with
Question, is it viable or just a collection of Google sea4ches?
“This code will read the engine speed, coolant temperature, and throttle position sensors every 0.1 seconds. It will then calculate the amount of fuel to inject and send a signal to the fuel injector.

This is just a simple example, and a real engine control would be much more complex. Howe
To write code to make an engine control, you need to first understand the different components of an engine and how they work together. The main components of an engine are:

  • Cylinders: The cylinders are where the combustion process takes place.
  • Pistons: The pistons move up and down inside the cylinders to create compression and power.
  • Spark plugs: The spark plugs ignite the air-fuel mixture in the cylinders.
  • Fuel injectors: The fuel injectors spray fuel into the cylinders.
  • Crankshaft: The crankshaft is connected to the pistons and converts the linear motion of the pistons into rotary motion.
  • Camshaft: The camshaft controls the timing of the valves.
The engine control unit (ECU) is responsible for controlling all of these components. It does this by reading sensor data and sending signals to the actuators. The sensor data includes information such as the engine speed, coolant temperature, and throttle position. The actuator signals control the fuel injectors, spark plugs, and other components.

Here is a simple example of code to make an engine control:

Python
import time

class EngineControl:
def __init__(self):
self.engine_speed = 0
self.coolant_temperature = 0
self.throttle_position = 0

def read_sensors(self):
# Read the sensor data
self.engine_speed = 1000
self.coolant_temperature = 80
self.throttle_position = 50

def calculate_fuel_injection(self):
# Calculate the amount of fuel to inject
fuel_injection = self.engine_speed * self.coolant_temperature / self.throttle_position
return fuel_injection

def send_signals(self):
# Send signals to the actuators
self.fuel_injector.inject(self.fuel_injection)

def run(self):
while True:
self.read_sensors()
self.calculate_fuel_injection()
self.send_signals()

# Wait for a short time
time.sleep(0.1)

if __name__ == '__main__':
engine_control = EngineControl()
engine_control.run()
 

wonkywinch

Well-known member
Joined
30 Jul 2018
Messages
2,030
Location
Hamble, UK
Visit site
I used to own a TR5 with the 2500 PI engine. Frightening to think the fuel injection "computer" was mechanical. Designed by Lucas to replace carburettors on piston aero engines but future business thwarted by Frank Whittle so they switched to cars.

A little revolving rod with slots in it moved up and down a cylinder according to throttle position & vacuum in the manifold.

None of your wiggly amps to be seen.
 

lustyd

Well-known member
Joined
27 Jul 2010
Messages
12,403
Visit site
You’d be better off with GitHub Copilot for code as it’s designed for the task.
This code won’t control an engine, no. It lacks any modules to communicate with the engine which would need hardware to do the controlling. Certainly with Copilot if you’d asked it it would have told you that.
 

Hoolie

Well-known member
Joined
3 Mar 2005
Messages
8,150
Location
Hants/Lozère
Visit site
You may be slightly missing the point. The OP is asking for views whether the Google s/w is a useful tool for code development rather than searching for an off-the-shelf solution.
I haven't used Bard so I'm afraid I can't really help ...
 

lustyd

Well-known member
Joined
27 Jul 2010
Messages
12,403
Visit site
And that’s a no. Bard is like ChatGPT and statistically provides the most likely next words. Codex, used by GitHub Copilot, is designed for code generation and gives more consistent and relevant code as well as explaining that code and won’t have hallucinations like the generic ones. Our customers using Copilot are finding 30-40% of code is written by Copilot in enterprise uses.
 
Last edited:
Top