# Chatgpt AI FOR RC pwm node

**URL:** <https://forum.xod.io/t/chatgpt-ai-for-rc-pwm-node/6463>\
**Category:** XOD Programming Questions\
**Created:** [February 8, 2023, 2:23am UTC](https://forum.xod.io/t/chatgpt-ai-for-rc-pwm-node/6463 "2023-02-08T02:23:40Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![fantasydoom](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/fantasydoom/32/3729_2.png) [@fantasydoom](https://forum.xod.io/u/fantasydoom)\
**Post date:** [February 8, 2023, 2:23am UTC](https://forum.xod.io/t/chatgpt-ai-for-rc-pwm-node/6463/1 "2023-02-08T02:23:40Z")

</div>

**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

```auto
#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?**

---

<div class="post-metadata">

**Author:** ![gweimer](https://avatars.discourse-cdn.com/v4/letter/g/a9adbd/32.png) [@gweimer](https://forum.xod.io/u/gweimer)\
**Post date:** [February 8, 2023, 2:26pm UTC](https://forum.xod.io/t/chatgpt-ai-for-rc-pwm-node/6463/2 "2023-02-08T14:26:16Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![fantasydoom](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/fantasydoom/32/3729_2.png) [@fantasydoom](https://forum.xod.io/u/fantasydoom)\
**Post date:** [February 9, 2023, 2:29am UTC](https://forum.xod.io/t/chatgpt-ai-for-rc-pwm-node/6463/3 "2023-02-09T02:29:52Z")

</div>

> [@fantasydoom](#):
>
> PWM1

thanks alot for your kind replay

---

<div class="post-metadata">

**Author:** ![fantasydoom](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/fantasydoom/32/3729_2.png) [@fantasydoom](https://forum.xod.io/u/fantasydoom)\
**Post date:** [February 9, 2023, 2:51am UTC](https://forum.xod.io/t/chatgpt-ai-for-rc-pwm-node/6463/4 "2023-02-09T02:51:52Z")

</div>

> [@fantasydoom](#):
>
> CH1

here is the compilation result fo r tha AI NOD

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

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](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/2X/8/8740fa84d532862c0e28ddd341bda1931b26e994.jpeg)  
 ![Screenshot 2023-02-09 044834](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/2X/a/aa8634a8a2e7596dc788a4f73998e5fb2dcd450c.jpeg)

 ![Screenshot 2023-02-09 045107](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/2X/d/d4e8c82f4e330e9674f3f7131d249a3ebd7ed82b.jpeg)

---

<div class="post-metadata">

**Author:** ![fantasydoom](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/fantasydoom/32/3729_2.png) [@fantasydoom](https://forum.xod.io/u/fantasydoom)\
**Post date:** [February 9, 2023, 2:54am UTC](https://forum.xod.io/t/chatgpt-ai-for-rc-pwm-node/6463/5 "2023-02-09T02:54:14Z")

</div>

HERE IS THE FILE  
[rc-nod.xodball](https://forum.xod.io/uploads/short-url/kgLQrNt7Kw924wTZFCcDrMkvAlp.xodball) (3.4 KB)

---

<div class="post-metadata">

**Author:** ![mci-ryan](https://avatars.discourse-cdn.com/v4/letter/m/f08c70/32.png) [@mci-ryan](https://forum.xod.io/u/mci-ryan)\
**Post date:** [February 9, 2023, 6:12am UTC](https://forum.xod.io/t/chatgpt-ai-for-rc-pwm-node/6463/6 "2023-02-09T06:12:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![gweimer](https://avatars.discourse-cdn.com/v4/letter/g/a9adbd/32.png) [@gweimer](https://forum.xod.io/u/gweimer)\
**Post date:** [February 9, 2023, 6:51pm UTC](https://forum.xod.io/t/chatgpt-ai-for-rc-pwm-node/6463/7 "2023-02-09T18:51:13Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/1X/eb7348baa04192c2ef932d1db54d44f09f8a7888.png) [@system](https://forum.xod.io/u/system)\
**Post date:** [March 11, 2023, 6:51pm UTC](https://forum.xod.io/t/chatgpt-ai-for-rc-pwm-node/6463/8 "2023-03-11T18:51:33Z")

</div>

Closed on March 11, 2023, 6:51pm UTC

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