diff --git a/RMCS2301_RMCS2004/new_driver/README.md b/RMCS2301_RMCS2004/new_driver/README.md new file mode 100644 index 0000000..b5b8779 --- /dev/null +++ b/RMCS2301_RMCS2004/new_driver/README.md @@ -0,0 +1,2 @@ +## RMCS 2004 Motor +Previously used motor driver (RMCS 2301) works erratically. Code for a different motor driver. \ No newline at end of file diff --git a/RMCS2301_RMCS2004/new_driver/motor_pwm_control.ino b/RMCS2301_RMCS2004/new_driver/motor_pwm_control.ino new file mode 100644 index 0000000..dd9dd83 --- /dev/null +++ b/RMCS2301_RMCS2004/new_driver/motor_pwm_control.ino @@ -0,0 +1,50 @@ + + + +#include +#include +#include +#include + +ros::NodeHandle nh; +int TicksCount=4; +std_msgs::Int16 ticks; +int speed=0; +void messageCb( const geometry_msgs::Twist& toggle_msg){ + + speed=int(toggle_msg.linear.x*900); + + } +ros::Publisher chatter("chatter",&ticks); + +ros::Subscriber sub("cmd_vel", &messageCb ); + + +void setup() { + Serial.begin(57600); + + nh.initNode(); + nh.subscribe(sub); + pinMode(8,OUTPUT); + pinMode(9,OUTPUT); + digitalWrite(8,LOW); + attachInterrupt(digitalPinToInterrupt(2), HandleRightMotorInterruptA, RISING); + nh.advertise(chatter); + + // put your setup code here, to run once: + +} +void HandleRightMotorInterruptA() +{ + // count the ticks between some interval and calculate the rotation rate in the interval + TicksCount++; + } + +void loop() { + + nh.spinOnce(); + delay(1); + analogWrite(9,speed); + ticks.data=TicksCount; + chatter.publish(&ticks); +}