Community
cancel
Showing results for 
Search instead for 
Did you mean: 
BChen64
Novice
1,643 Views

Please help solve the problem of servo motor

My servo motor can not work with success compile,It is my c++ code:

# include

using namespace std;

# include

struct Devices{

upm::Servo *servo;

void init(){

servo = new upm::Servo(5);

}

};

Devices devices;

int main() {

for(;;){

devices.servo->setAngle(0);

devices.servo->setAngle(90);

devices.servo->setAngle(180);

devices.servo->setAngle(0);

}

return 0;

}

6 Replies
idata
Community Manager
36 Views

Hello Jeff_Chen,

 

 

I was reading your code and unfortunately I'm not able to determine if you are working with the Arduino IDE or if you are writing your code in C++. I believe you were trying to translate an Arduino example to C++, is that right? If so, could you please post the Arduino code you are using?

 

 

Also, if you would like to interact with Edison's interface using C++, I'd suggest you to use mraa. If you would like to learn more about it, you should check the following link: https://github.com/intel-iot-devkit/mraa

 

 

-Peter.
BChen64
Novice
36 Views

No im using eclipse IoT platform,BTW I've already solved this, but another problem comes out, my professor wants me use GWS-S03T servo motor using c++,plz give me some sample code..

idata
Community Manager
36 Views

Servo motors are controlled by a PWM signal. Since you are using Eclipse, that means you can use mraa, so, if you would like to control a servo motor you can check mraa's PWM example in https://github.com/intel-iot-devkit/mraa/blob/master/examples/c%2B%2B/Pwm3-cycle.cpp.

 

 

If you would like to learn how to control a servo motor and what exactly is PWM, I'd suggest you to read the following documents:

 

 

https://www.servocity.com/how-does-a-servo-work

 

http://www.fuelsaver-mpg.com/what-is-a-pwm

 

 

I hope this information is of help.

 

-Peter.
BChen64
Novice
36 Views

Really appreciate you provided this mraa example code,it works~~but a little problem is that when i executed this sample code(Pwm3-cycle.cpp),servo motor(GWSS03T) would shake,how could i adjust from sample code?

idata
Community Manager
36 Views

Hi Jeff_Chen,

 

 

Did you make sure to modify the example in order to send the data you need in order to move the servo? I mean, the example probably won't work out of the box as it might not send the signal the servo requires.

 

 

Make sure you are sending the specific signal the servo requires as its turn rate since this is a specification that may vary from servo to servo.

 

 

-Peter.
idata
Community Manager
36 Views

Hi Jeff_Chen,

 

 

Do you have any updates about this?

 

 

-Peter.
Reply