B4R Question Questions about RunNative

Cesar_Morisco

Active Member
Hey guys, clear me a doubt
Because the pwm control acts on the servo motor control. If the RunNative call is separate
B4R:
Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
RunNative("initialize", Null)  ' Inicializar O PWM
RunNative("initializeServo", Null) ' Inicializa o servo
End Sub

Case "CMDE"
    ServoValue = ServoValue + 10 ' Incrementa o ângulo do servo X
    RunNative("setServoAngle", Null) ' Atualiza os servos
Case "CMDF"
    ServoValue = ServoValue - 10 ' Incrementa o ângulo do servo X
    RunNative("setServoAngle", Null) ' Atualiza os servos
    
    
Case "CMDM" ' Aumentar Velocidade
    PwmValue=PwmValue+1
    RunNative("Pwm", Null) ' Chama a função PWM para atualizar o valor
Case "CMDN" ' Diminuir Velocidade
    PwmValue=PwmValue-1
    RunNative("Pwm", Null) ' Chama a função PWM para atualizar o valor
    
    
    'PWM
#if C
void initialize(B4R::Object* o) {
// Configura o canal PWM com a frequência e resolução de timer
ledcSetup(b4r_main::_channel, b4r_main::_freq, b4r_main::_ledc_timer_13_bit);
ledcAttachPin(b4r_main::_pinpwm1, b4r_main::_channel);
Serial.println("PWM Initialized");
}
void Pwm(B4R::Object* o) {
// Escreve o valor PWM no canal configurado
ledcWrite(b4r_main::_channel, b4r_main::_pwmvalue);
 printf("PWM Value set to: %d\n", b4r_main::_pwmvalue);
}
#End If

'Motor servo2
#If C
#include <ESP32Servo.h>
Servo servo;  // Instância do objeto Servo
void initializeServo(B4R::Object* o) {
servo.attach(b4r_main::_pinservo); // Conecta o servo ao pino configurado no B4R
}
void setServoAngle(B4R::Object* o) {
int angle = b4r_main::_servovalue; // Obtém o valor de ângulo configurado no B4R
servo.write(angle); // Move o servo para o ângulo especificado
}
#End If
 

hatzisn

Expert
Licensed User
Longtime User
Hey guys, clear me a doubt
Because the pwm control acts on the servo motor control. If the RunNative call is separate
B4R:
Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
RunNative("initialize", Null)  ' Inicializar O PWM
RunNative("initializeServo", Null) ' Inicializa o servo
End Sub

Case "CMDE"
    ServoValue = ServoValue + 10 ' Incrementa o ângulo do servo X
    RunNative("setServoAngle", Null) ' Atualiza os servos
Case "CMDF"
    ServoValue = ServoValue - 10 ' Incrementa o ângulo do servo X
    RunNative("setServoAngle", Null) ' Atualiza os servos
   
   
Case "CMDM" ' Aumentar Velocidade
    PwmValue=PwmValue+1
    RunNative("Pwm", Null) ' Chama a função PWM para atualizar o valor
Case "CMDN" ' Diminuir Velocidade
    PwmValue=PwmValue-1
    RunNative("Pwm", Null) ' Chama a função PWM para atualizar o valor
   
   
    'PWM
#if C
void initialize(B4R::Object* o) {
// Configura o canal PWM com a frequência e resolução de timer
ledcSetup(b4r_main::_channel, b4r_main::_freq, b4r_main::_ledc_timer_13_bit);
ledcAttachPin(b4r_main::_pinpwm1, b4r_main::_channel);
Serial.println("PWM Initialized");
}
void Pwm(B4R::Object* o) {
// Escreve o valor PWM no canal configurado
ledcWrite(b4r_main::_channel, b4r_main::_pwmvalue);
 printf("PWM Value set to: %d\n", b4r_main::_pwmvalue);
}
#End If

'Motor servo2
#If C
#include <ESP32Servo.h>
Servo servo;  // Instância do objeto Servo
void initializeServo(B4R::Object* o) {
servo.attach(b4r_main::_pinservo); // Conecta o servo ao pino configurado no B4R
}
void setServoAngle(B4R::Object* o) {
int angle = b4r_main::_servovalue; // Obtém o valor de ângulo configurado no B4R
servo.write(angle); // Move o servo para o ângulo especificado
}
#End If

Maybe you forgot to write the question or I do not understand it.
 
Upvote 0

Cesar_Morisco

Active Member
Hello hatzisn how are you?
About C using RunNative("initialize", Null) 01 for the pwm and the other for servo motor control, the problem is that when I act with the "CMDM" function and to act on the pwm it acts on the servo motor
The commands of one are being used by the other
Example here
PwmValue=PwmValue+1 here it moves the servo motor where the pwm was supposed to act
Thank you already
 
Upvote 0

hatzisn

Expert
Licensed User
Longtime User
As I see you set the angle in two RunNative(s) and you set the speed of the servo in two other RunNative(s). I suppose you would ask either one of the following two questions:

1) What will happen if you set together the angle up and down? I suppose it will do both (it will go and return) or depending on the library will proceed up until an angle and then return 10 degrees back (or in front). The same is valid for pwm for the speed (increase speed and decrease speed during the rotation depending on the library or conclude the motion and then take the new command).

2) What will happen if you set the angle and the speed consecutively? I suppose it will start going to the angle with the initial speed and when it will receive the new command it will increase/decrease. Also the other way around for constant speed and different angles according to question 1.

Both questions will be answered only by trial and error... Or by checking the code of the library.
 
Upvote 0

Cesar_Morisco

Active Member
I confess I've already made several changes
And the two-pin intervention continues. Do you already have a library for this?
With servo control for esp32 or pwm?

Already change the pins and nothing If the two internal conflict codes remain
 

Attachments

  • PCB2.JPG
    PCB2.JPG
    408 KB · Views: 1
Upvote 0
Top