Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added code for new motor driver #12

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions RMCS2301_RMCS2004/new_driver/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
## RMCS 2004 Motor
Previously used motor driver (RMCS 2301) works erratically. Code for a different motor driver.
50 changes: 50 additions & 0 deletions RMCS2301_RMCS2004/new_driver/motor_pwm_control.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@



#include <ros.h>
#include <geometry_msgs/Twist.h>
#include <digitalWriteFast.h>
#include <std_msgs/Int16.h>

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<geometry_msgs::Twist> 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);
}