Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
6 years, 11 months ago. This question has been closed. Reason: Unclear question
Remote Controlled Robotic Snake Servo
Hi, I'm trying to move the kondo4034 motor by using a remote control. The programme wont work (the part with the pulse width). I'm still a student so I might take a while to understand. Thanks.
- include "mbed.h"
- include "math.h"
- define PI 3.14159265358979323846264338327950288419716939937510582
- define amplitude 600
- define PeriodJoint 2
- define NoJoint 13
- define NoCycles 1.5
- define Resolution 0.01
DigitalOut myled1(LED1); DigitalOut myled2(LED2); PwmOut PWM(p26);
Serial motor1(p9,NC);p9 transmit, p10 receive Serial remote(p27,NC);p27 receive, p29 transmit
signed int MotorAngle; int MotorID; unsigned short int straightPosition[] = {7000};
unsigned short int currentposition, currentpositions; unsigned short int currentposition1[] = {0}; unsigned short int currentposition2[] = {0}; float Timing, kSpeed, kShape;
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() { PWM.period(0.0142);
if(PWM.pulsewidth == 0.001) { MotorAngle = 3500; wait(0.5); } if(PWM.pulsewidth == 0.0015) { MotorAngle = 7500; wait(0.5); } if(PWM.pulsewidth == 0.002) { MotorAngle = 11500; wait(0.5); } }