Skip to content

Instantly share code, notes, and snippets.

@Mozyanari
Created July 24, 2019 15:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mozyanari/1cf83766b6b352d097df8f916851d9e5 to your computer and use it in GitHub Desktop.
Save Mozyanari/1cf83766b6b352d097df8f916851d9e5 to your computer and use it in GitHub Desktop.
servo.cpp
#include <ros/ros.h>
#include <pigpiod_if2.h>
#include <std_msgs/Bool.h>
int main(int argc, char** argv){
ros::init(argc, argv, "servo");
ros::NodeHandle n;
int pi;
pi = pigpio_start(NULL,NULL);
int i = 0;
ros::Rate rate(1);
set_servo_pulsewidth(pi,26,1500);
while(ros::ok()){
if(i == 0){
set_servo_pulsewidth(pi,26,1400);
i = 1;
}else{
set_servo_pulsewidth(pi,26,1600);
i = 0;
}
ROS_INFO("%d",i);
ros::spinOnce();
rate.sleep();
}
set_servo_pulsewidth(pi,26,0);
return 0;
}
© 2019 GitHub, Inc.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment