jmccorm
Well-Known Member
- Thread starter
- #586
QUESTION:
Should ChatGPT be spun off onto it's own thread or kept here?
I've enjoyed working with ChatGPT (now using the 4.0 "paid" version). While I don't see it being a major topic (to rival this one), I realize that not everyone who is interested in this thread would want to wade through all the ChatGPT tips and examples. Any objection to spinning it off to it's own thread?
On the topic of ChatGPT...
My Latest ChatGPT Python Programming Prompt
Here is my latest prompt which seems to avoid a number of programming issues I've ran into so far:
A Quick Example of Wrangler CAN Programming with ChatGPT:
"Create for me a script that filters the CAN buses for any specified messages. On can0, a message ID of 0x322 will contain the engine's RPMs. It is stored as a word and begins at the 0th byte of the message. If it exceeds 500RPMs, print a warning with it's current value."
Asking ChatGPT to add to the code...
"On can1, a message ID of 0x127 will contain the intake air temperature in Fahrenheit. It is stored as the 0th byte of the message. Add a warning that includes it's current value whenever the intake air temperature exceeds 20F."
Sample Output:
Asking ChatGPT to add one more thing...
"On can1, a message ID of 0x1F7 will contain the vehicle speed in MPH. It is stored as the 3rd word of the message. Add a warning that includes it's current value whenever the vehicle's speed exceeds 90MPH."
The code looks good, but I didn't test the last condition. Oddly enough, ChatGPT failed my next request. I found this particularly interesting because it was able to convert some of my Wrangler's BASH scripts into Python.
"Please convert this to a BASH shell script."
Summary
If you don't know enough Python (or another language) to actually do the programming, but you know what data is located where (see our spreadsheet in the first page of this thread) and what you want to do with it, if you start with a good initial prompt, ChatGPT can actually create working code for you to build off of.
It isn't foolproof, but the more I learn about ChatGPT's limitations, the more I'm able to add to the initial prompt to guide ChatGPT into coding the correct solutions.
Should ChatGPT be spun off onto it's own thread or kept here?
I've enjoyed working with ChatGPT (now using the 4.0 "paid" version). While I don't see it being a major topic (to rival this one), I realize that not everyone who is interested in this thread would want to wade through all the ChatGPT tips and examples. Any objection to spinning it off to it's own thread?
On the topic of ChatGPT...
My Latest ChatGPT Python Programming Prompt
Here is my latest prompt which seems to avoid a number of programming issues I've ran into so far:
For now on, you will always write to the following standard unless told otherwise:
The Jeep Wrangler JL has two CAN buses: can0 (CAN-IHS) and can1 (CAN-C). Its CAN data is big-endian. You will use Python 3.9.2 and the Python-CAN module version 4.1.0. If using the udsoncan module, write for version 1.16, and if using the can-isotp module, write for version 1.8. The CAN bus has an 11 bit ID and is not extended. Configure for a SocketCAN interface but don't specify channels or bitrate unless necessary. Avoid using the channel_info attribute. If setting a CAN filter, use set_filters(). Code that access both can0 and can1 and uses recv() should set "timeout=0.001" unless told otherwise. Only initialize those CAN busses that will be used. Use a Raspberry Pi environment and always begin Python3 scripts with #!/usr/bin/python3.
Do you understand? Please answer only YES or NO.
A Quick Example of Wrangler CAN Programming with ChatGPT:
"Create for me a script that filters the CAN buses for any specified messages. On can0, a message ID of 0x322 will contain the engine's RPMs. It is stored as a word and begins at the 0th byte of the message. If it exceeds 500RPMs, print a warning with it's current value."
Python:
#!/usr/bin/python3
import can
def rpm_warning(msg):
rpm = int.from_bytes(msg.data[0:2], byteorder='big')
if rpm > 500:
print(f"Warning: Engine RPM exceeds 500! Current RPM: {rpm}")
def main():
can0 = can.interface.Bus(bustype='socketcan', channel='can0')
can0.set_filters([{"can_id": 0x322, "can_mask": 0x7FF}])
while True:
msg = can0.recv(timeout=0.001)
if msg:
rpm_warning(msg)
Sample output:
Warning: Engine RPM exceeded 500. Current value: 1091
Warning: Engine RPM exceeded 500. Current value: 1097
Warning: Engine RPM exceeded 500. Current value: 1110
Warning: Engine RPM exceeded 500. Current value: 1106
Warning: Engine RPM exceeded 500. Current value: 1098
Asking ChatGPT to add to the code...
"On can1, a message ID of 0x127 will contain the intake air temperature in Fahrenheit. It is stored as the 0th byte of the message. Add a warning that includes it's current value whenever the intake air temperature exceeds 20F."
Python:
#!/usr/bin/python3
import can
def rpm_warning(msg):
rpm = int.from_bytes(msg.data[0:2], byteorder='big')
if rpm > 500:
print(f"Warning: Engine RPM exceeds 500! Current RPM: {rpm}")
def temp_warning(msg):
temp_f = msg.data[0]
if temp_f > 20:
print(f"Warning: Intake air temp exceeds 20°F! Current temperature: {temp_f}°F")
def main():
can0 = can.interface.Bus(bustype='socketcan', channel='can0')
can1 = can.interface.Bus(bustype='socketcan', channel='can1')
can0.set_filters([{"can_id": 0x322, "can_mask": 0x7FF}])
can1.set_filters([{"can_id": 0x127, "can_mask": 0x7FF}])
while True:
msg_can0 = can0.recv(timeout=0.001)
msg_can1 = can1.recv(timeout=0.001)
if msg_can0:
rpm_warning(msg_can0)
if msg_can1:
temp_warning(msg_can1)
Warning: Intake air temp exceeded 20°F. Current value: 81°F
Warning: Engine RPM exceeded 500. Current value: 1043
Warning: Intake air temp exceeded 20°F. Current value: 81°F
Warning: Engine RPM exceeded 500. Current value: 1086
Warning: Intake air temp exceeded 20°F. Current value: 81°F
Warning: Engine RPM exceeded 500. Current value: 1120
Asking ChatGPT to add one more thing...
"On can1, a message ID of 0x1F7 will contain the vehicle speed in MPH. It is stored as the 3rd word of the message. Add a warning that includes it's current value whenever the vehicle's speed exceeds 90MPH."
Python:
#!/usr/bin/python3
import can
def rpm_warning(msg):
rpm = int.from_bytes(msg.data[0:2], byteorder='big')
if rpm > 500:
print(f"Warning: Engine RPM exceeds 500! Current RPM: {rpm}")
def temp_warning(msg):
temp_f = msg.data[0]
if temp_f > 20:
print(f"Warning: Intake air temperature exceeds 20°F! Current temperature: {temp_f}°F")
def speed_warning(msg):
speed_mph = int.from_bytes(msg.data[6:8], byteorder='big')
if speed_mph > 90:
print(f"Warning: Vehicle speed exceeds 90 MPH! Current speed: {speed_mph} MPH")
def main():
can0 = can.interface.Bus(bustype='socketcan', channel='can0')
can1 = can.interface.Bus(bustype='socketcan', channel='can1')
can0.set_filters([{"can_id": 0x322, "can_mask": 0x7FF}])
can1.set_filters([{"can_id": 0x127, "can_mask": 0x7FF}, {"can_id": 0x1F7, "can_mask": 0x7FF}])
while True:
msg_can0 = can0.recv(timeout=0.001)
msg_can1 = can1.recv(timeout=0.001)
if msg_can0:
rpm_warning(msg_can0)
if msg_can1:
if msg_can1.arbitration_id == 0x127:
temp_warning(msg_can1)
elif msg_can1.arbitration_id == 0x1F7:
speed_warning(msg_can1)
"Please convert this to a BASH shell script."
Converting the given Python script to a Bash script is not directly possible, as Bash and Python are fundamentally different scripting languages with different syntax and functionality.
Summary
If you don't know enough Python (or another language) to actually do the programming, but you know what data is located where (see our spreadsheet in the first page of this thread) and what you want to do with it, if you start with a good initial prompt, ChatGPT can actually create working code for you to build off of.
It isn't foolproof, but the more I learn about ChatGPT's limitations, the more I'm able to add to the initial prompt to guide ChatGPT into coding the correct solutions.
Sponsored