Skip to content

Commit 42097e3

Browse files
committed
Format and/or add documentation comments
1 parent 1f23108 commit 42097e3

19 files changed

+359
-161
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Setup
44

55
1. Install the [Arduino IDE](https://www.arduino.cc/en/software). Use the new 2.0.0 version if possible as it is easier to work with.
6-
2. Install CrcLib, ArduinoExtra (see programming resources document) and [Paul Stoffergen's Encoder library](https://www.arduino.cc/reference/en/libraries/encoder/)
6+
2. Install CrcLib, ArduinoExtra, and [Paul Stoffergen's Encoder library](https://www.arduino.cc/reference/en/libraries/encoder/)
77
3. Clone this repository in the User/Documents/Arduino/libraries/ folder (or equivalent on Mac).
88
4. Open the Arduino IDE and create a new project. Select the `Arduino Mega or Mega 2560` board. Write `#include <RobotUtils.h>` at the top of the file and press verify to make sure everything is installed properly.
99
5. Open the cloned repository in VSCode or another text editor/IDE (make sure you don't commit your project files on accident). You can install an editorconfig extension for automatic file formatting ([VSCode Example](https://marketplace.visualstudio.com/items?itemName=EditorConfig.EditorConfig)).

RobotUtils/Controller.h

Lines changed: 83 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
/**
22
* @file Controller.h
33
* @author Gabriel Saberian
4-
* @brief Controller header file for Vanier Robotics' RobotUtils library, controls the robot by pressing
5-
* digital and analog buttons on a controller.
4+
* @brief Controller class used to manage all sorts of inputs
65
*
76
* @copyright Copyright (c) 2023 Vanier Robotics (MIT License)
87
*/
9-
108
#include <ArduinoExtra.h>
119
#include <CrcLib.h>
1210

@@ -16,98 +14,144 @@
1614
namespace rou
1715
{
1816

17+
/**
18+
* @brief Controller class, which can be used to manage the various inputs for a robot
19+
*
20+
*/
1921
class Controller
2022
{
21-
// Structure that contains the variables and fuctions for the digital binding
23+
/**
24+
* @brief Structure that contains the variables and function for a digital binding
25+
*
26+
*/
2227
struct DigitalBinding
2328
{
24-
Crc::BUTTON buttonID; //variable of type BUTTON (from CRC lib) that stores a specific button
25-
aex::Function<void(bool)> callback; //pointer function used to do some action with a digital button
29+
Crc::BUTTON buttonID; ///< variable of type BUTTON (from CrcLib) that stores a specific button
30+
aex::Function<void(bool)> callback; ///< pointer to the function called when the binding changes state
2631
};
2732

28-
//Structure that contains the variables and fuctions for the toggle binding
33+
/**
34+
* @brief Structure that contains the variables and function for a toggle binding
35+
*
36+
*/
2937
struct ToggleBinding
3038
{
31-
Crc::BUTTON buttonID; //variable of type BUTTON (from CRC lib) that stores a specific button
32-
aex::Function<void(bool)> callback; //pointer function used to do some action with a toggle action
39+
Crc::BUTTON buttonID; ///< variable of type BUTTON (from CrcLib) that stores a specific button
40+
aex::Function<void(bool)> callback; ///< pointer to the function called when the binding changes state
3341

34-
bool isToggled; //boolean variable that stores the state of the button (Toggled = true and not toggled = false)
35-
// boolean variable that stores the last value of a button and used to defined the isToggled value
36-
//(if lastValue = true, then the last button was pressed and if lastValue = false, then the last button wasn't pressed)
37-
bool lastValue;
42+
bool isToggled; ///< stores the state of the button
43+
bool lastValue; ///< boolean variable that keeps track of the previous value of a button
3844
};
3945

40-
//Structure that contains the variables and fuctions for the analog binding
46+
/**
47+
* @brief Structure that contains the variables and function for an analog binding
48+
*
49+
*/
4150
struct AnalogBinding
4251
{
43-
Crc::ANALOG analogID; //variable of type ANALOG (from CRC lib) that stores a specific button
44-
aex::Function<void(int8_t)> callback; //pointer function used to do some action with an analog button
52+
Crc::ANALOG analogID; ///< variable of type ANALOG (from CrcLib) that stores a specific button
53+
aex::Function<void(int8_t)> callback; ///< pointer to the function called when the binding changes state
4554
};
4655

47-
//Structure that contains the variables and fuctions for the digital sensor binding
56+
/**
57+
* @brief Structure that contains the variables and functions for a digital sensor binding
58+
*
59+
*/
4860
struct DigitalSensorBinding
4961
{
50-
uint8_t pin; //variable of type uint8_t that stores the number of the pin on the crcDuino board change type
51-
aex::Function<void(bool)> callback;
62+
uint8_t pin; ///< the pin number from Crclib
63+
aex::Function<void(bool)> callback; ///< pointer to the function called when the binding changes state
5264
};
5365

54-
//Structure that contains the variables and fuctions for the analog sensor binding
66+
/**
67+
* @brief Structure that contains the variables and functions for an analog sensor binding
68+
*
69+
*/
5570
struct AnalogSensorBinding
5671
{
57-
uint8_t pin; //variable of type uint8_t that stores the number of the pin on the crcDuino board change type
58-
aex::Function<void(unsigned int)> callback;
72+
uint8_t pin; ///< the pin number from Crclib
73+
aex::Function<void(unsigned int)> callback; ///< pointer to the function called when the binding changes state
5974
};
6075

6176
public:
62-
//callback functions (pointer functions) of the different structures
63-
//callback function for digital bindings
77+
/**
78+
* @brief Setup a callback function for a digital binding
79+
*
80+
* @param buttonID The BUTTON to which the binding is assigned
81+
* @param callback Pointer to the function that will be called when this binding is updated
82+
*/
6483
void digitalBind(Crc::BUTTON buttonID, aex::Function<void(bool)> callback)
6584
{
6685
m_digitalBindings.pushBack({buttonID, callback});
6786
}
6887

69-
//callback function for toggle bindings
88+
/**
89+
* @brief Setup a callback function for a toggle binding
90+
*
91+
* @param buttonID The BUTTON to which the binding is assigned
92+
* @param callback Pointer to the function that will be called when this binding is updated
93+
*/
7094
void toggleBind(Crc::BUTTON buttonID, aex::Function<void(bool)> callback)
7195
{
7296
m_toggleBindings.pushBack({buttonID, callback, false, false});
7397
}
7498

75-
//callback function for analog bindings
99+
/**
100+
* @brief Setup a callback function for an analog binding
101+
*
102+
* @param analogID The ANALOG input to which the binding is assigned
103+
* @param callback Pointer to the function that will be called when this binding is updated
104+
*/
76105
void analogBind(Crc::ANALOG analogID, aex::Function<void(int8_t)> callback)
77106
{
78107
m_analogBindings.pushBack({analogID, callback});
79108
}
80109

81-
//callback function for digital sensor bindings
110+
/**
111+
* @brief Setup a callback function for a digital sensor binding
112+
*
113+
* @param pin The CrcLib pin number to which the sensor is connected
114+
* @param callback Pointer to the function that will be called when this binding is updated
115+
*/
82116
void digitalSensorBind(uint8_t pin, aex::Function<void(bool)> callback)
83117
{
84118
m_digitalSensorBindings.pushBack({pin, callback});
85119
}
86120

87-
//callback function for analog sensor binding
121+
/**
122+
* @brief Setup a callback function for an analog sensor binding
123+
*
124+
* @param pin The CrcLib pin number to which the sensor is connected
125+
* @param callback Pointer to the function that will be called when this binding is updated
126+
*/
88127
void analogSensorBind(uint8_t pin, aex::Function<void(unsigned int)> callback)
89128
{
90129
m_analogSensorBindings.pushBack({pin, callback});
91130
}
92131

132+
/**
133+
* @brief Update all the bindings and call the required callbacks
134+
*
135+
*/
93136
void update()
94137
{
95-
//For each frame, verify which button are pressed and call the corresponding methods
96-
//Digital Bindings verification
138+
// For each frame, verify which button are pressed and call the corresponding methods
139+
140+
// Digital Bindings verification
97141
for (int i = 0; i < m_digitalBindings.getSize(); i++)
98142
{
99143
m_digitalBindings[i].callback(
100144
Crc::CrcLib::ReadDigitalChannel(m_digitalBindings[i].buttonID));
101145
}
102146

103-
//Analog Bindings verification
147+
// Analog Bindings verification
104148
for (int i = 0; i < m_analogBindings.getSize(); i++)
105149
{
106150
m_analogBindings[i].callback(
107151
Crc::CrcLib::ReadAnalogChannel(m_analogBindings[i].analogID));
108152
}
109153

110-
//Toggle Bindings verification
154+
// Toggle Bindings verification
111155
for (int i = 0; i < m_toggleBindings.getSize(); i++)
112156
{
113157
bool status = Crc::CrcLib::ReadDigitalChannel(m_toggleBindings[i].buttonID);
@@ -120,14 +164,14 @@ class Controller
120164
m_toggleBindings[i].lastValue = status;
121165
}
122166

123-
//Digital Sensor Bindings verification
167+
// Digital Sensor Bindings verification
124168
for (int i = 0; i < m_digitalSensorBindings.getSize(); i++)
125169
{
126170
m_digitalSensorBindings[i].callback(
127171
(Crc::CrcLib::GetDigitalInput(m_digitalSensorBindings[i].pin) == HIGH));
128172
}
129173

130-
//Analog Sensor Bindings verification
174+
// Analog Sensor Bindings verification
131175
for (int i = 0; i < m_analogSensorBindings.getSize(); i++)
132176
{
133177
m_analogSensorBindings[i].callback(
@@ -136,12 +180,11 @@ class Controller
136180
}
137181

138182
private:
139-
//Vector arrays
140-
aex::Vector<DigitalBinding> m_digitalBindings; //Create a vector array of type DigitalBinding
141-
aex::Vector<ToggleBinding> m_toggleBindings; //Create a vector array of type ToggleBinding
142-
aex::Vector<AnalogBinding> m_analogBindings; //Create a vector array of type AnalogBinding
143-
aex::Vector<DigitalSensorBinding> m_digitalSensorBindings; //Create a vector array of type DigitalSensorBinding
144-
aex::Vector<AnalogSensorBinding> m_analogSensorBindings; //Create a vector array of type AnalogBinding
183+
aex::Vector<DigitalBinding> m_digitalBindings; ///< Vector of DigitalBinding's which were created
184+
aex::Vector<ToggleBinding> m_toggleBindings; ///< Vector of ToggleBinding's which were created
185+
aex::Vector<AnalogBinding> m_analogBindings; ///< Vector of AnalogBinding's which were created
186+
aex::Vector<DigitalSensorBinding> m_digitalSensorBindings; ///< Vector of DigitalSensorBinding's which were created
187+
aex::Vector<AnalogSensorBinding> m_analogSensorBindings; ///< Vector of AnalogSensorBinding's which were created
145188
};
146189

147190
} // rou

RobotUtils/Handle.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
/**
22
* @file Handle.h
33
* @author Jiucheng Zang
4-
* @brief Handle class
4+
* @brief Base Handle class
55
*
66
* @copyright Copyright (c) 2023 Vanier Robotics (MIT License)
77
*/
8-
98
#ifndef _INCLUDE_ROU_HANDLE_H_
109
#define _INCLUDE_ROU_HANDLE_H_
1110

@@ -15,7 +14,7 @@ namespace rou
1514
class HandleManager;
1615

1716
/**
18-
* @brief Handle class
17+
* @brief Base Handle class
1918
*
2019
*/
2120
class Handle
@@ -24,19 +23,21 @@ class Handle
2423
friend class HandleManager;
2524

2625
/**
27-
* @brief Check if Handle is available for now
26+
* @brief Check if Handle is currently available
2827
*
29-
* @return bool m_available value if available
28+
* @return true the handle is available
29+
* @return false the handle has already been used
3030
*/
3131
bool isAvailable()
3232
{
3333
return m_isAvailable;
3434
}
3535

3636
/**
37-
* @brief Check if this handle be used. If not add it up and return true, else return false do nothing.
37+
* @brief Check if this handle be used. If not, switch it to unavailable return true, else return false do nothing.
3838
*
39-
* @return bool temp_available value if use success
39+
* @return true the handle can be used
40+
* @return false the handle has been previously used and is no longer avaiable
4041
*/
4142
bool use()
4243
{
@@ -47,7 +48,7 @@ class Handle
4748
}
4849

4950
/**
50-
* @brief Release this handle
51+
* @brief Release this handle, making it available again
5152
*
5253
*/
5354
void release()
@@ -58,14 +59,14 @@ class Handle
5859
protected:
5960
/**
6061
* @brief Setup the handle (ie. initialize the pin, etc.)
61-
*
62+
*
6263
* Some handles do not require any setup, which is why the base defaults to an empty method
6364
*/
6465
virtual void setup()
6566
{
6667
}
6768

68-
bool m_isAvailable = true;
69+
bool m_isAvailable = true; ///< stores whether the handle can be used or has already been used
6970
};
7071

7172
} // namespace rou

RobotUtils/HandleManager.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
/**
22
* @file HandleManager.h
33
* @author Jiucheng Zang
4-
* @brief Handle Manager class
4+
* @brief Manages the use of all handles
55
*
66
* @copyright Copyright (c) 2023 Vanier Robotics (MIT License)
77
*/
8-
98
#ifndef _INCLUDE_ROU_HANDLE_MANAGER_H_
109
#define _INCLUDE_ROU_HANDLE_MANAGER_H_
1110

@@ -16,15 +15,14 @@ namespace rou
1615
{
1716

1817
/**
19-
* @brief Handle Manager class
18+
* @brief HandleManager class, which controls the use of all individual handles
2019
*
21-
* @extends Handle class
2220
*/
2321
class HandleManager
2422
{
2523
public:
2624
/**
27-
* @brief Release all the Handle in the Handle Manager
25+
* @brief Release all the handles stored in the handle manager
2826
*
2927
*/
3028
void releaseAll()
@@ -38,7 +36,9 @@ class HandleManager
3836
/**
3937
* @brief Add different Handle into Handle Manager Class
4038
*
41-
* @param handle Different types of handle
39+
* @param handle a pointer to any handle
40+
*
41+
* All handles must be added to the handle manager
4242
*/
4343
void addHandle(Handle* handle)
4444
{
@@ -47,7 +47,7 @@ class HandleManager
4747
}
4848

4949
private:
50-
aex::Vector<Handle*> m_handles;
50+
aex::Vector<Handle*> m_handles; ///< Vector of ALL handles used by the robot
5151
};
5252

5353
} // namespace rou

RobotUtils/Handles.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*
66
* @copyright Copyright (c) 2023 Vanier Robotics (MIT License)
77
*/
8-
98
#ifndef _INCLUDE_ROU_HANDLES_H_
109
#define _INCLUDE_ROU_HANDLES_H_
1110

0 commit comments

Comments
 (0)