Skip to content

Commit 5c8f085

Browse files
Updated Comments
================ Changed "arbitrary" to "hand-tuned" to more accurately describe the conversion value comment. Fixed the comment format from "//Comment here" to "// Comment here".
1 parent c7a64ce commit 5c8f085

2 files changed

Lines changed: 60 additions & 60 deletions

File tree

src/sbridge/src/sbridge.cpp

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,131 +1,131 @@
1-
//This file handles communication between the gazebo simulation and the rover
1+
// This file handles communication between the gazebo simulation and the rover
22

3-
//Since the simulation cannot get data from the real rovers, this package converts
4-
//the behavior package data into readable data for the gazebo simulation to understand
3+
// Since the simulation cannot get data from the real rovers, this package converts
4+
// the behavior package data into readable data for the gazebo simulation to understand
55
#include "sbridge.h"
66

7-
//sbridge constructor
7+
// sbridge constructor
88
sbridge::sbridge(std::string publishedName) {
99

10-
//Create a new node that will communicate with ROS
10+
// Create a new node that will communicate with ROS
1111
ros::NodeHandle sNH;
1212

1313

14-
//Create a drive control subscriber
15-
//publishedName + '/driveControl" == the topic to subscribe to
16-
//10 == the incoming message queue size
17-
//&sbridge::cmdHandler == callback to class method first parameter
18-
//this == calllback to class method second parameter
14+
// Create a drive control subscriber
15+
// publishedName + '/driveControl" == the topic to subscribe to
16+
// 10 == the incoming message queue size
17+
// &sbridge::cmdHandler == callback to class method first parameter
18+
// this == calllback to class method second parameter
1919
driveControlSubscriber = sNH.subscribe((publishedName + "/driveControl"), 10, &sbridge::cmdHandler, this);
2020

21-
//Create a heatbeat publisher to show that the node is still alive and running
22-
//publishedName + "/sbridge/heartbeat" == topic to publish to
23-
//1 == the outgoing message queue
24-
//false == disables the latching connection. It does not save the last message nor automatically send
25-
//automatically send it to future connecting subscribers
26-
//this parameter is optional
21+
// Create a heatbeat publisher to show that the node is still alive and running
22+
// publishedName + "/sbridge/heartbeat" == topic to publish to
23+
// 1 == the outgoing message queue
24+
// false == disables the latching connection. It does not save the last message nor automatically send
25+
// automatically send it to future connecting subscribers
26+
// this parameter is optional
2727
heartbeatPublisher = sNH.advertise<std_msgs::String>((publishedName + "/sbridge/heartbeat"), 1, false);
2828

29-
//Create a skidsteer publisher to
29+
// Create a skidsteer publisher to
3030
skidsteerPublish = sNH.advertise<geometry_msgs::Twist>((publishedName + "/skidsteer"), 10);
3131

32-
//Create a infoLog publisher to send log information to the log box in the GUI
32+
// Create a infoLog publisher to send log information to the log box in the GUI
3333
infoLogPublisher = sNH.advertise<std_msgs::String>("/infoLog", 1, true);
3434

35-
//Publishes a heartbeat every 2 seconds
35+
// Publishes a heartbeat every 2 seconds
3636
float heartbeat_publish_interval = 2;
3737

38-
//Schedules a callback at the heartbeat_publish_interval
39-
//This is not a realtime timer
40-
//ros::Duration(heartbeat_publish_interval) == period between calls to the callback
41-
//&sbridge::publishHeartBeatTimerEventHandler == callback to class method first parameter
42-
//this == callback to class method second parameter
38+
// Schedules a callback at the heartbeat_publish_interval
39+
// This is not a realtime timer
40+
// ros::Duration(heartbeat_publish_interval) == period between calls to the callback
41+
// &sbridge::publishHeartBeatTimerEventHandler == callback to class method first parameter
42+
// this == callback to class method second parameter
4343
publish_heartbeat_timer = sNH.createTimer(ros::Duration(heartbeat_publish_interval), &sbridge::publishHeartBeatTimerEventHandler, this);
4444

4545
ROS_INFO("constructor");
4646

4747
}
4848

49-
//Command Handler
50-
//PWM (pulse with modulation) values to linear values
49+
// Command Handler
50+
// PWM (pulse with modulation) values to linear values
5151
void sbridge::cmdHandler(const geometry_msgs::Twist::ConstPtr& message) {
52-
//Gets and sets the linear PWM value
52+
// Gets and sets the linear PWM value
5353
double left = (message->linear.x);
54-
//Gets and sets the angular PWM value
54+
// Gets and sets the angular PWM value
5555
double right = (message->angular.z);
5656

57-
//Set max values
58-
float max_turn_rate = 4.5; //radians per second
59-
float max_linear_velocity = 0.65; // meters per second
57+
// Set max values
58+
float max_turn_rate = 4.5; // radians per second
59+
float max_linear_velocity = 0.65; // meters per second
6060

61-
//Temperary Variables to store the velocity values
62-
//Angular
61+
// Temperary Variables to store the velocity values
62+
// Angular
6363
float turn = 0;
64-
//Linear
64+
// Linear
6565
float forward = 0;
6666

6767
float linearVel = (left + right)/2;
6868
float angularVel = (right-left)/2;
6969

70-
//Converts the PWM values to velocity values
71-
//Necessary arbitrary conversion value
70+
// Converts the PWM values to velocity values
71+
// Necessary hand-tuned conversion value
7272
turn = angularVel/55;
73-
//Necessary arbitrary conversion value
73+
// Necessary hand-tuned conversion value
7474
forward = linearVel/390;
7575

76-
//If the rover is moving forward and turning at the same time, it will not have enough power to carry out
77-
//each of those at it's full values, so we need to lower this value so the PIDs can compensate for both
78-
//the linear and angular velocity
76+
// If the rover is moving forward and turning at the same time, it will not have enough power to carry out
77+
// each of those at it's full values, so we need to lower this value so the PIDs can compensate for both
78+
// the linear and angular velocity
7979
if (forward >= 150){
80-
//Lower forward velocity value by necessary arbitrary conversion value
80+
// Lower forward velocity value by necessary hand-tuned conversion value
8181
forward -= (abs(turn)/5);
8282
}
8383

84-
//If the linear velocity (PWM value) is moving in the forward direction (value is greater than or equal to 0),
85-
//but forward (velocity) gets converted to a non-positive value (for reverse movement)
84+
// If the linear velocity (PWM value) is moving in the forward direction (value is greater than or equal to 0),
85+
// but forward (velocity) gets converted to a non-positive value (for reverse movement)
8686
if (linearVel >= 0 && forward <= 0)
8787
{
88-
//Do not move (set forward velocity to 0)
88+
// Do not move (set forward velocity to 0)
8989
forward = 0;
9090
}
9191

92-
//If the linear velocity (PWM value) is moving in the reverse direction (value is greater than or equal to 0),
93-
//but the foward (velocity) variable gets converted to a non-negative value (for forwards movement)
92+
// If the linear velocity (PWM value) is moving in the reverse direction (value is greater than or equal to 0),
93+
// but the foward (velocity) variable gets converted to a non-negative value (for forwards movement)
9494
if (linearVel <= 0 && forward >= 0)
9595
{
96-
//Do not move (set forward velocity to 0)
96+
// Do not move (set forward velocity to 0)
9797
forward = 0;
9898
}
9999

100-
//If the absolute value of the forward value (float) is greater than or equal to the max_linear_velocity
100+
// If the absolute value of the forward value (float) is greater than or equal to the max_linear_velocity
101101
if (fabs(forward) >= max_linear_velocity) {
102102
forward = forward/fabs(forward) * max_linear_velocity;
103103
}
104104

105-
if (fabs(turn) >= max_turn_rate) { //max value needs tuning
105+
if (fabs(turn) >= max_turn_rate) { // max value needs tuning
106106
turn = turn/fabs(turn) * max_turn_rate;
107107
}
108108

109-
//Sets the converted (PWM to velocity) values into the variable that the simulation can read
110-
//Linear velocity
109+
// Sets the converted (PWM to velocity) values into the variable that the simulation can read
110+
// Linear velocity
111111
velocity.linear.x = forward,
112-
//Angular velocity
112+
// Angular velocity
113113
velocity.angular.z = turn;
114-
//Publish velocity information to rotary wheel movement
114+
// Publish velocity information to rotary wheel movement
115115
skidsteerPublish.publish(velocity);
116116
}
117117

118118

119119
void sbridge::publishHeartBeatTimerEventHandler(const ros::TimerEvent& event) {
120120
std_msgs::String msg;
121121
msg.data = "";
122-
//Publish the heartbeat message
122+
// Publish the heartbeat message
123123
heartbeatPublisher.publish(msg);
124124

125-
//Log information for the timer in seconds and nanoseconds
125+
// Log information for the timer in seconds and nanoseconds
126126
ROS_INFO("%ds, %dnsec", event.last_real.sec, event.last_real.nsec);
127127
}
128128

129-
//Destructor
129+
// Destructor
130130
sbridge::~sbridge() {
131131
}

src/sbridge/src/sbridge.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef SBRIDGE
22
#define SBRIDGE
33

4-
//ROS messages
4+
// ROS messages
55
#include <ros/ros.h>
66
#include <std_msgs/Float32.h>
77
#include <std_msgs/String.h>
@@ -26,16 +26,16 @@ class sbridge {
2626

2727
private:
2828

29-
//Publishers
29+
// Publishers
3030
ros::Publisher skidsteerPublish;
3131
ros::Publisher heartbeatPublisher;
3232
ros::Publisher infoLogPublisher;
3333

34-
//Subscribers
34+
// Subscribers
3535
ros::Subscriber driveControlSubscriber;
3636
ros::Subscriber modeSubscriber;
3737

38-
//Timer callback handler
38+
// Timer callback handler
3939
void publishHeartBeatTimerEventHandler(const ros::TimerEvent& event);
4040

4141
ros::Timer publish_heartbeat_timer;

0 commit comments

Comments
 (0)