3 years, 1 month ago.

How to control kondo motor using R/C ?

Hi, I'm trying to control a kondo motor using R/C by using the switchcase function. I have already gotten the pulsewidth of when the remote control throttle is at the neutral position, when it is pushed and when it is pulled. I am not sure how to use that information to create the switchcase function.

main.cpp

#include "mbed.h"
DigitalOut myled1(LED1);
DigitalOut myled2(LED2);

Serial motor1(p9,NC);//p9 transmit, p10 receive
Serial pc(USBTX,USBRX);
int MotorID;
int Position;
void motor_update(unsigned char Id, unsigned short int Position)
{
    unsigned short int id,lo,hi;
    motor1.format(8,Serial::Even,1);
    motor1.baud(115200);
    id=0x80|Id;
    hi=(Position>>7)&0x007F;
    lo=Position&0x007F; 
    motor1.putc(id);
    motor1.putc(hi);
    motor1.putc(lo);  
    wait(0.001); 
}   

int main()
{
    while(1)
    {
    myled1=1;
    myled2=1;
    pc.printf("Stop\t");
    wait(1);
    
    motor_update(0, 11500);
    myled1=1;
    myled2=0;
    pc.printf("MotorAngle is %d\t",Position);
    wait(1);
    
    motor_update(0, 3500);
    myled1=0;
    myled2=1;
    pc.printf("MotorAngle is %d",Position);
    wait(1);
    }
}

Be the first to answer this question.