Quantcast
Channel: ROS Answers: Open Source Q&A Forum - RSS feed
Viewing all articles
Browse latest Browse all 314

cant assign the value to 'cmd_msg.data' in runtime.

$
0
0
I am doing a stepper motor programming.*what i want is "when i enter an angle on command line,then stepper should rotate that angle"*. but i cant assign the value in runtime. help me please. #include #include #include signed int angle; int enable2 = 13; const int stepPin = 9; const int dirPin = 8; int x; ros::NodeHandle nh; void pwm( const std_msgs::UInt16& cmd_msg) { analogWrite(enable2, cmd_msg.data); angle=analogRead(enable2); } ros::Subscriber sub("servo", pwm); void setup(){ // pinMode(angle, OUTPUT); pinMode(enable2, OUTPUT); pinMode(stepPin,OUTPUT); pinMode(dirPin,OUTPUT); nh.initNode(); nh.subscribe(sub); // servo.attach(9); //attach it to pin 9 } void loop() { if (angle<0) { cw(); delay(100); } else { ccw(); delay(100); } delay(10000); nh.spinOnce(); delay(1); } void cw() { digitalWrite(dirPin,LOW); for(x = 0; x < 17.77*(angle*-1); x++) { digitalWrite(stepPin,HIGH); delayMicroseconds(500); digitalWrite(stepPin,LOW); delayMicroseconds(500); }} void ccw() { digitalWrite(dirPin,HIGH); for(x = 0; x < 17.77*angle; x++) { digitalWrite(stepPin,HIGH); delayMicroseconds(500); digitalWrite(stepPin,LOW); delayMicroseconds(500); }}

Viewing all articles
Browse latest Browse all 314

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>