Compilation error when trying to transmit and receive data to Dynamixel XL320 motors with esp32 with an active BLE connexion

huangapple go评论54阅读模式
英文:

Compilation error when trying to transmit and receive data to Dynamixel XL320 motors with esp32 with an active BLE connexion

问题

I am trying to control various Dynamixel XL320 motors (<https://emanual.robotis.com/docs/en/dxl/x/xl320/>) with an esp32. I want my program to do three things:

  1. Transmit data to the motors (control mode, speed goal, ...)
  2. Read data from the motors (current position, current speed, ...)
  3. Communicate with the esp32 with Bluetooth

Various libraries implement point 1 and 2, although point n°2 seems to be the most difficult without external hardware. The two main libraries I found are this one and this one.

With the first one I can complete point 1 and 3, using the BluetoothSerial esp library. The XL320_servo_example.ino works well, and is compatible with BLE communication when not using the SoftwareSerial library (commented lines 15, 18 and 35). From what I have seen on internet, it seems that this first xl320 library doesn't work for reading data through the RX serial pin.

On the other hand, the second xl320 library does implement the receiving task with RX but makes extensive use of the SoftwareSerial library. I can implement points 1 and 2 with the examples. As explained in this question, the SoftwareSerial and BluetoothSerial libraries are not compatible. I am getting exactly the same error as in this question, that is:

C:\Users\nicol\AppData\Local\Temp\arduino_build_322778\libraries\EspSoftwareSerial\SoftwareSerial.cpp.o: In function `std::function&lt;void ()&gt;::operator()() const&#39;:
C:\Users\nicol\Documents\Arduino\libraries\EspSoftwareSerial\src/SoftwareSerial.h:188:(.iram1.54[delegate::detail::DelegateImpl&lt;void*, void&gt;::operator()() const]+0x22): dangerous relocation: l32r: literal placed after use: .literal._ZNK8delegate6detail12DelegateImplIPvvEclEv
collect2.exe: error: ld returned 1 exit status
Usando librer&#237;a BluetoothSerial con versi&#243;n 1.0 en la carpeta: C:\Users\nicol\AppData\Local\Arduino15\packages\esp32\hardware\esp32.0.6\libraries\BluetoothSerial 
Utilizando biblioteca Arduino-Dynamixel-XL320-master en carpeta: C:\Users\nicol\Documents\Arduino\libraries\Arduino-Dynamixel-XL320-master (legacy)
Usando librer&#237;a EspSoftwareSerial con versi&#243;n 7.0.1 en la carpeta: C:\Users\nicol\Documents\Arduino\libraries\EspSoftwareSerial 
exit status 1
Error compilando para la tarjeta ESP32 Dev Module.

The minimal Arduino code used to generate this error is as following:

// ###########BLE COMM##########
#include &quot;BluetoothSerial.h&quot;

#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif

BluetoothSerial SerialBT;

//############SERVO COMM#############
#include &quot;Dynamixel-XL320.h&quot;
DynamixelXL320 xl320(21, 19);

void setup()
{
    Serial.begin(9600);
    ////// BLE
    SerialBT.begin(&quot;Robot_centipede&quot;); //Bluetooth device name

    ////// servos
    xl320.begin(DynamixelXL320::Baud::BAUD_57600);
}

void loop()
{
}

I tried to solve my problem by modifying the (second library. I tried to remove every call to SoftwareSerial and use HardwareSerial instead but some functions from SoftwareSerial are hard to understand for me, especially this following:

void SoftwareSerial::enableRx(bool on) {
    if (m_rxValid &amp;&amp; on != m_rxEnabled) {
        if (on) {
            m_rxLastBit = m_pduBits - 1;
            // Init to stop bit level and current tick
            m_isrLastTick = (microsToTicks(micros()) | 1) ^ m_invert;
            if (m_bitTicks &gt;= microsToTicks(1000000UL / 74880UL))
                attachInterruptArg(digitalPinToInterrupt(m_rxPin), reinterpret_cast&lt;void (*)(void*)&gt;(rxBitISR), this, CHANGE);
            else
                attachInterruptArg(digitalPinToInterrupt(m_rxPin), reinterpret_cast&lt;void (*)(void*)&gt;(rxBitSyncISR), this, m_invert ? RISING : FALLING);
        }
        else {
            detachInterrupt(digitalPinToInterrupt(m_rxPin));
        }
        m_rxEnabled = on;
    }
}

I tried to comment the calls to this function and to use the third serial port of esp32 (pins 16 and 17) but I couldn't read data from the motors.

I am desesperately looking for an esp32 library that permits to transmit AND recieve data from the XL320 motors and that DOES NOT use the SoftwareSerial library so that it is compatible with BluetoothSerial. Please, feel free to ask any question you would need to help me.

英文:

I am trying to control various Dynamixel XL320 motors (<https://emanual.robotis.com/docs/en/dxl/x/xl320/>) with an esp32. I want my program to do three things:

  1. Transmit data to the motors (control mode, speed goal, ...)

  2. Read data from the motors (current position, current speed, ...)

  3. Communicate with the esp32 with Bluetooth

Various libraries implement point 1 and 2, although point n°2 seems to be the most difficult without external hardware. The two main libraries I found are this one and this one.

With the first one I can complete point 1 and 3, using the BluetoothSerial esp library. The XL320_servo_example.ino works well, and is compatible with BLE communication when not using the SoftwareSerial library (commented lines 15, 18 and 35). From what I have seen on internet, it seems that this first xl320 library doesn't work for reading data through the RX serial pin.

On the other hand, the second xl320 library does implement the receiving task with RX but makes extensive use of the SoftwareSerial library. I can implement points 1 and 2 with the examples. As explained in this question, the SoftwareSerial and BluetoothSerial libraries are not compatible. I am getting exactly the same error as in this question, that is:

>
&gt; C:\Users\nicol\AppData\Local\Temp\arduino_build_322778\libraries\EspSoftwareSerial\SoftwareSerial.cpp.o: In function `std::function&lt;void ()&gt;::operator()() const&#39;:
&gt; C:\Users\nicol\Documents\Arduino\libraries\EspSoftwareSerial\src/SoftwareSerial.h:188:(.iram1.54[delegate::detail::DelegateImpl&lt;void*, void&gt;::operator()() const]+0x22): dangerous relocation: l32r: literal placed after use: .literal._ZNK8delegate6detail12DelegateImplIPvvEclEv
&gt; collect2.exe: error: ld returned 1 exit status
&gt; Usando librer&#237;a BluetoothSerial con versi&#243;n 1.0 en la carpeta: C:\Users\nicol\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.6\libraries\BluetoothSerial
&gt; Utilizando biblioteca Arduino-Dynamixel-XL320-master en carpeta: C:\Users\nicol\Documents\Arduino\libraries\Arduino-Dynamixel-XL320-master (legacy)
&gt; Usando librer&#237;a EspSoftwareSerial con versi&#243;n 7.0.1 en la carpeta: C:\Users\nicol\Documents\Arduino\libraries\EspSoftwareSerial
&gt; exit status 1
&gt; Error compilando para la tarjeta ESP32 Dev Module.
&gt;
&gt;

The minimal Arduino code used to generate this error is as following:

// ###########BLE COMM##########
#include &quot;BluetoothSerial.h&quot;

#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif

BluetoothSerial SerialBT;

//############SERVO COMM#############
#include &quot;Dynamixel-XL320.h&quot;
DynamixelXL320 xl320(21, 19);

void setup()
{
    Serial.begin(9600);
    ////// BLE
    SerialBT.begin(&quot;Robot_centipede&quot;); //Bluetooth device name

    ////// servos
    xl320.begin(DynamixelXL320::Baud::BAUD_57600);
}

void loop()
{
}

I tried to solve my problem by modifying the (second library. I tried to remove every call to SoftwareSerial and use HardwareSerial instead but some functions from SoftwareSerial are hard to understand for me, especially this following:

void SoftwareSerial::enableRx(bool on) {
    if (m_rxValid &amp;&amp; on != m_rxEnabled) {
        if (on) {
            m_rxLastBit = m_pduBits - 1;
            // Init to stop bit level and current tick
            m_isrLastTick = (microsToTicks(micros()) | 1) ^ m_invert;
            if (m_bitTicks &gt;= microsToTicks(1000000UL / 74880UL))
                attachInterruptArg(digitalPinToInterrupt(m_rxPin), reinterpret_cast&lt;void (*)(void*)&gt;(rxBitISR), this, CHANGE);
            else
                attachInterruptArg(digitalPinToInterrupt(m_rxPin), reinterpret_cast&lt;void (*)(void*)&gt;(rxBitSyncISR), this, m_invert ? RISING : FALLING);
        }
        else {
            detachInterrupt(digitalPinToInterrupt(m_rxPin));
        }
        m_rxEnabled = on;
    }
}

I tried to comment the calls to this function and to use the third serial port of esp32 (pins 16 and 17) but I couldn't read data from the motors.

I am desesperately looking for an esp32 library that permits to transmit AND recieve data from the XL320 motors and that DOES NOT use the SoftwareSerial library so that it is compatible with BluetoothSerial.

Please, feel free to ask any question you would need to help me.

答案1

得分: 1

关于我最终如何解决我的问题的一些新闻。

在更深入地研究了这个库之后,我设法实现了一些小的更改,使得可以从伺服电机中读取数据。我创建了这个分支来发布这些小的更改。它不使用SoftwareSerial库,所以我没有兼容性问题。

尽管如此,数据读取仍然不完美,因为电机有时会返回超出范围的测量值。我怀疑这部分原因是我的esp和XL320之间的连接电缆太长所致。

我根据经验建议在每次通信总线的调用之间实施20ms的延迟(读取或写入),并且在同一线上不要连接超过4个XL320。在我的应用中,我连接了8个XL320,将它们分成了2行,每行4个电机,中央节点直接连接到我的esp的RX/TX端口。

值得一提的是,XL320电机应该由74LVC2G241或NC7WZ241控制,这两者用于“合并”来自ESP32的RX和TX引脚。这篇帖子中描述的解决方案只需连接这两个引脚,但这并不是最佳方法。

英文:

Some news about how I finally managed to solve my problem.

After digging a bit more about this library I managed to implement some small changes that enable data reading from the servos. I created this fork to publish the small changes. It doesn't uses the SoftwareSerial library so I have no compatibility problems.

Data reading is still not perfect though, as the motors sometimes give back out-of-bounds measurements. I suspect this is partially caused by long connecting wires between my esp and the XL320s.

I empirically advice to implement a delay of 20ms between each call on the communication bus (read or write) and to not have more than 4 XL320 connected in serie in the same line. In my application with 8 XL320 I connected them in 2 two lines of 4 motors each, with a central node directly connected to the RX/TX port of my esp.

For the record, XL320 motors are supposed to be controlled with a 74LVC2G241 or a NC7WZ241, which are used to "merge" the RX and TX pins from the ESP32. The solution described in this post works simply by connecting these two pins but this is not optimal.

huangapple
  • 本文由 发表于 2023年7月7日 07:36:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/76633105.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定