Skip to content
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ docs/_build/doctrees

.pre-commit-config.yaml
.vscode/
build
build
.gitignore
59 changes: 59 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,62 @@ Please notice that this wrapper is still a work in progress. While we aim to mak

`psdk_ros2` wrapper is under the [Mozilla Public License Version 2.0](https://github.com/umdlife/psdk_ros2/blob/main/LICENSE.md). \
Please note that the [DJI Payload-SDK](https://github.com/dji-sdk/Payload-SDK) libraries which are needed to run this wrapper use MIT License.


---

Here's the step-by-step instructions for running the PSDK wrapper as a non-root user without requiring a password.


## Running PSDK Wrapper as a Non-Root User

To run the PSDK wrapper as a non-root user, switch to the `non_root_user` branch and configure it according to the instructions provided in the [PSDK ROS 2 Wiki](https://umdlife.github.io/psdk_ros2/index.html). However, running the wrapper in this way will still prompt for a password.

To avoid entering the password each time, follow the instructions below to modify the sudoers file so that specific commands can be executed without a password.

### Step-by-Step Instructions

1. **Backup the sudoers File**
Before making any changes, back up the existing sudoers file as a precaution:
```bash
sudo cp /etc/sudoers /etc/sudoers.bak
```

2. **Edit the sudoers File**
You should never edit the sudoers file directly with a regular text editor. Instead, use `visudo`, which checks for syntax errors before saving:
```bash
sudo visudo
```

3. **Modify the File**
Inside the editor, find the section that looks like this:
```bash
# Allow members of group sudo to execute any command
sudo ALL=(ALL:ALL) ALL
```
Replace it with the following line to allow members of the sudo group to run commands without a password:
```bash
sudo ALL=(ALL:ALL) NOPASSWD: ALL
```

4. **Save and Exit**
- If `visudo` opens with Vim (default editor), press `Esc`, type `:wq`, and press Enter to save and exit.
- If `visudo` opens with Nano, press `Ctrl + O` to save, then Enter, and `Ctrl + X` to exit.


5. **Testing the Configuration**
Open a new terminal and run a command that typically requires a password, such as:
```bash
sudo whoami
```
If the command runs without prompting for a password, the configuration is correct.

6. **Run the PSDK Wrapper**
Now, try launching the PSDK wrapper. It should initialize as a non-root user without requiring a password.
```bash
ros2 launch psdk_wrapper wrapper.launch.py
```

---

This configuration allows members of the sudo group to execute commands without needing to enter a password, streamlining the process of running the PSDK wrapper. If you encounter any issues, revert to the backed-up sudoers file (`/etc/sudoers.bak`) and review the changes.
4 changes: 2 additions & 2 deletions psdk_wrapper/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ include(FetchContent)
# Declare the content to fetch
FetchContent_Declare(
Payload_SDK
GIT_REPOSITORY https://github.com/dji-sdk/Payload-SDK.git
GIT_TAG 3.8.1
GIT_REPOSITORY https://github.com/bitcurious/Payload-SDK.git
GIT_TAG non-root-user
Comment on lines +42 to +43
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bitcurious we cannot fetch a Payload-SDK repository which is not the main one from DJI. This will complicate a lot things whenever we would like to upgrade the Payload-SDK versions to the latest ones. I think we can add instructions on how users could run the code with non-root settings, but that is as much as we can do as this depends on the official DJI codebase. Another way would be to open an issue to the Payload-SDK from DJI and request these changes.

I hope you understand the reasons why we cannot add this here.

Copy link
Contributor Author

@bitcurious bitcurious Sep 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood. I will updated it in my forked repository.

)

FetchContent_GetProperties(Payload_SDK)
Expand Down
43 changes: 41 additions & 2 deletions psdk_wrapper/include/psdk_wrapper/modules/flight_control.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,8 @@ class FlightControlModule : public rclcpp_lifecycle::LifecycleNode
* @brief Callback function to exposing a generic control method of the
* aircraft.The type of commands as well as the reference frame is specified
* in a flag within the msg.
* @param msg sensor_msgs::msg::Joy. Axes represent the x, y, z and yaw
* @param msg sensor_msgs::msg::Joy. Axes represent the x, y, z, yaw and flag
* command.
* @note This type of control is not implemented at this moment.
*/
void flight_control_generic_cb(const sensor_msgs::msg::Joy::SharedPtr msg);

Expand Down Expand Up @@ -390,6 +389,26 @@ class FlightControlModule : public rclcpp_lifecycle::LifecycleNode
const std::shared_ptr<GetObstacleAvoidance::Request> request,
const std::shared_ptr<GetObstacleAvoidance::Response> response);

/**
*@brief Sets horizontal control mode as per flag, updates x, y, and z
* values and sets Joystick mode.
*/
void set_horizontal_mode(float x_cmd, float y_cmd, float z_cmd, float yaw_cmd,
uint8_t flag);

/**
* @brief Sets vertical control mode as per, flag updates x, y, and z
* values and sets Joystick mode.
*/
void set_vertical_mode(float x_cmd, float y_cmd, float z_cmd, float yaw_cmd,
uint8_t flag);
/**
*@brief Sets yaw control mode as per flag, updates yaw
* value and sets Joystick mode.
*/
void set_yaw_mode(float x_cmd, float y_cmd, float z_cmd, float yaw_cmd,
uint8_t flag);

/* ROS 2 Subscribers */
rclcpp::Subscription<sensor_msgs::msg::Joy>::SharedPtr
flight_control_generic_sub_;
Expand Down Expand Up @@ -440,6 +459,26 @@ class FlightControlModule : public rclcpp_lifecycle::LifecycleNode
get_horizontal_radar_obstacle_avoidance_srv_;

bool is_module_initialized_{false};

T_DjiFlightControllerJoystickMode joystick_mode;
float x_cmd, y_cmd, z_cmd, yaw_cmd;

// Decode values for control flag.
enum Control
{
FRAME_GROUND = 0x00,
FRAME_BODY = 0x02,
HORIZONTAL_VELOCITY = 0x40,
HORIZONTAL_POSITION = 0x80,
HORIZONTAL_ANGLE = 0x00,
VERTICAL_VELOCITY = 0x00,
VERTICAL_POSITION = 0x10,
VERTICAL_THRUST = 0x20,
YAW_ANGLE = 0x00,
YAW_RATE = 0x08,
};

uint8_t flag;
};

} // namespace psdk_ros2
Expand Down
Loading