-
Notifications
You must be signed in to change notification settings - Fork 0
/
rccar_rosserial_arduino.ino~
65 lines (50 loc) · 1.27 KB
/
rccar_rosserial_arduino.ino~
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <ros.h>
#include <AFMotor.h>
#include <geometry_msgs/Twist.h>
#include <std_msgs/String.h>
#include <robot_emulator/Request.h>
#include <robot_emulator/BootResponse.h>
AF_DCMotor motor1(1);
ros::NodeHandle nh;
robot_emulator::BootResponse boot_msg;
ros::Publisher bootPub("boot", &boot_msg);
char bootchar[11] = "locomotion";
const char* const bootword = "boot";
void runMotors( const geometry_msgs::Twist& input_msg){
int forwardvel = input_msg.linear.x;
if (forwardvel > 0) {
motor1.setSpeed(forwardvel);
motor1.run(FORWARD);
}
else if (forwardvel < 0) {
motor1.setSpeed(forwardvel);
motor1.run(BACKWARD);
}
else {
motor1.setSpeed(0);
motor1.run(RELEASE);
}
}
void requests( const robot_emulator::Request& req_msg){
if(req_msg.request[0] == bootword[0]){
boot_msg.moduletype = "locomotion";
boot_msg.modulenumber = 1;
bootPub.publish( &boot_msg );
}
}
ros::Subscriber<geometry_msgs::Twist> in_sub("locomotionInputs", &runMotors );
ros::Subscriber<robot_emulator::Request> req_sub("reqs", &requests );
void setup()
{
motor1.setSpeed(200);
motor1.run(RELEASE);
nh.initNode();
nh.advertise(bootPub);
nh.subscribe(in_sub);
nh.subscribe(req_sub);
}
void loop()
{
nh.spinOnce();
delay(100);
}