Chatgpt AI FOR RC pwm node

Der friends and Xoders

I’m trying to make a node through chatgpt AI
Its mission is to read the PWM signal from the RC receiver and display the value on the screen
This is the result of the program:((

's an example of how you could create a custom node in XOD using C++ that reads 4 PWM channels from an RC receiver and displays the values:

  1. Open XOD IDE and create a new project.
  2. Create a new custom node by clicking the “+” button in the Library tab and selecting “Custom Node.”
  3. Give your custom node a name, such as “RC Receiver PWM Reader,” and select “C++” as the implementation language.
  4. In the “Pins” section, add 4 input pins named “PWM1,” “PWM2,” “PWM3,” and “PWM4” to receive the PWM signals from the RC receiver.
  5. In the “Implementation” section, paste the following code:

cCopy code

#include <xod/pwm.h>

struct State {
  xod::pwm::PwmDecoder decoder1;
  xod::pwm::PwmDecoder decoder2;
  xod::pwm::PwmDecoder decoder3;
  xod::pwm::PwmDecoder decoder4;
};

[[combinable]]
void evaluate(Context ctx) {
  auto state = getState(ctx);

  int pwm1 = getValue<input_PWM1>(ctx);
  int pwm2 = getValue<input_PWM2>(ctx);
  int pwm3 = getValue<input_PWM3>(ctx);
  int pwm4 = getValue<input_PWM4>(ctx);

  state->decoder1.update(pwm1);
  state->decoder2.update(pwm2);
  state->decoder3.update(pwm3);
  state->decoder4.update(pwm4);

  emitValue<output_CH1>(ctx, state->decoder1.getValue());
  emitValue<output_CH2>(ctx, state->decoder2.getValue());
  emitValue<output_CH3>(ctx, state->decoder3.getValue());
  emitValue<output_CH4>(ctx, state->decoder4.getValue());
}
  1. In the “Pins” section, add 4 output pins named “CH1,” “CH2,” “CH3,” and “CH4” to display the values of the 4 channels.
  2. Save the custom node and add it to your project.
  3. Connect the input pins to the PWM signals from the RC receiver, and connect the output pins to nodes that will display the values.
  4. Upload the code to your device and start reading the PWM signals from the RC receiver and displaying the values.

Note: This is just a basic example. You may need to modify the code to meet the specific requirements of your project. ))

Is it possible to apply what was written by the artificial intelligence program?

Is it possible to run through those steps in XOD? Yes, though ‘In the “Pins” section’ is a little misleading since there is no separate sections for “Pins”; you need to add input-number & output-numbers nodes and label them as described.

Will it actually work? I don’t know. You can always enter the code & try to compile/upload to a board and see what happens. The worst that can happen is the compile fails because XOD doesn’t understand the data types or functions used, or it compiles but doesn’t return valid output. It’s not like it is going to blow up your hardware if it is wrong…

thanks alot for your kind replay

here is the compilation result fo r tha AI NOD

Begin compiling code for the board Arduino Due (Programming Port) :package:

C:\Users\DRONE-~1\AppData\Local\Temp\xod_temp_sketchbookNnceWO\xod_1675910771413_sketch\xod_1675910771413_sketch.ino:1013:9: error: ‘____eceiver’ does not name a type
typedef ____eceiver::Node Node_4;
^
C:\Users\DRONE-~1\AppData\Local\Temp\xod_temp_sketchbookNnceWO\xod_1675910771413_sketch\xod_1675910771413_sketch.ino:1014:1: error: ‘Node_4’ does not name a type
Node_4 node_4 = Node_4(0, 0, 0, 0);
^

C:\Users\DRONE-~1\AppData\Local\Temp\xod_temp_sketchbookNnceWO\xod_1675910771413_sketch\xod_1675910771413_sketch.ino: In function ‘void xod::runTransaction()’:
C:\Users\DRONE-~1\AppData\Local\Temp\xod_temp_sketchbookNnceWO\xod_1675910771413_sketch\xod_1675910771413_sketch.ino:1078:13: error: ‘Node_4’ has not been declared
Node_4::ContextObject ctxObj;
^

C:\Users\DRONE-~1\AppData\Local\Temp\xod_temp_sketchbookNnceWO\xod_1675910771413_sketch\xod_1675910771413_sketch.ino:1078:35: error: expected ‘;’ before ‘ctxObj’
Node_4::ContextObject ctxObj;
^

C:\Users\DRONE-~1\AppData\Local\Temp\xod_temp_sketchbookNnceWO\xod_1675910771413_sketch\xod_1675910771413_sketch.ino:1081:13: error: ‘ctxObj’ was not declared in this scope
ctxObj._input_PWM1 = node_0_output_VAL;
^

C:\Users\DRONE-~1\AppData\Local\Temp\xod_temp_sketchbookNnceWO\xod_1675910771413_sketch\xod_1675910771413_sketch.ino:1093:13: error: ‘node_4’ was not declared in this scope
node_4.evaluate(&ctxObj);
^

Error during build: exit status 1
Compilation failed
Command Process exited with code 1
The generated C++ code contains errors. It can be due to a bad node implementation or if your board is not compatible with XOD runtime code. The original compiler error message is above. Fix C++ errors to continue. If you believe it is a bug, report the problem to XOD developers.
Screenshot 2023-02-09 044917
Screenshot 2023-02-09 044834

HERE IS THE FILE
rc-nod.xodball (3.4 KB)

Are you trying to achieve this to test chat GPT or are you actually trying to make a device that achieves what you’re describing?

You can use analog read and analog pins to read pwm values, so long as your input voltage is the same as your pin reference voltage.

The input pins should probably input-port, not input-number. That might reduce your compile errors. In actual use, they will probably need to be analog pins unless decoder is measuring pulse-widths.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.