### Sensor Configuration Enums Source: https://github.com/dfrobot/dfrobot_c4001/blob/master/README.md Defines enumerations for sensor working modes, micromotion detection switches, and operational commands like start, stop, and reset. ```C++ typedef enum{ eExitMode = 0x00, eSpeedMode = 0x01, }eMode_t; typedef enum{ eStartSen = 0x55, eStopSen = 0x33, eResetSen = 0xCC, eRecoverSen = 0xAA, eSaveParams = 0x5C, eChangeMode = 0x3B, }eSetMode_t; ``` -------------------------------- ### Get PWM Settings - DFRobot C4001 Source: https://github.com/dfrobot/dfrobot_c4001/blob/master/README.md Retrieves the current PWM settings, including the duty cycles for when no target is detected (pwm1) and when a target is detected (pwm2), as well as the timer value that governs the transition speed between these states. The timer value ranges from 0 to 255, with each unit representing 64ms. ```C++ /** * @fn getPwm * @brief Get the Pwm object * @return sPwmData_t * @retval pwm1 When no target is detected, the duty cycle of the output signal of the OUT pin ranges from 0 to 100 * @retval pwm2 After the target is detected, the duty cycle of the output signal of the OUT pin ranges from 0 to 100 * @retval timer The value ranges from 0 to 255, corresponding to timer x 64ms * @n For example, timer=20, it takes 20*64ms=1.28s for the duty cycle to change from pwm1 to pwm2. */ sPwmData_t getPwm(void); ``` -------------------------------- ### GET /getTargetData Source: https://github.com/dfrobot/dfrobot_c4001/blob/master/README.md Retrieves real-time data regarding detected targets including speed, range, and energy. ```APIDOC ## GET /getTargetData ### Description Retrieves current metrics from the sensor including target count, speed, range, and energy levels. ### Method GET ### Endpoint /getTargetData ### Response #### Success Response (200) - **number** (uint8_t) - Number of targets detected. - **speed** (float) - Current target speed. - **range** (float) - Current target distance. - **energy** (uint32_t) - Signal energy level. ``` -------------------------------- ### Manage Sensor Status and Control Source: https://context7.com/dfrobot/dfrobot_c4001/llms.txt Retrieves the current operational status of the radar and sends control commands like start, stop, reset, or save configuration. ```cpp #include "DFRobot_C4001.h" DFRobot_C4001_I2C radar(&Wire, DEVICE_ADDR_0); void setup() { Serial.begin(115200); radar.begin(); sSensorStatus_t status = radar.getStatus(); Serial.print("Work status: "); Serial.println(status.workStatus ? "Running" : "Stopped"); radar.setSensor(eStartSen); } ``` -------------------------------- ### Get Detection Threshold - DFRobot C4001 Source: https://github.com/dfrobot/dfrobot_c4001/blob/master/README.md Retrieves the target detection threshold setting of the sensor. This function returns a `uint16_t` value representing the threshold. ```C++ /** * @fn getThresRange * @brief Get the Thres Range object * @return uint16_t */ uint16_t getThresRange(void); ``` -------------------------------- ### Get Target Speed - DFRobot C4001 Source: https://github.com/dfrobot/dfrobot_c4001/blob/master/README.md Retrieves the speed of the detected target. This function returns a `float` value representing the target's speed. ```C++ /** * @fn getTargetSpeed * @brief Get the Target Speed object * @return float */ float getTargetSpeed(void); ``` -------------------------------- ### Get Target Energy - DFRobot C4001 Source: https://github.com/dfrobot/dfrobot_c4001/blob/master/README.md Retrieves the energy value associated with the detected target. This function returns a `uint32_t` value representing the target's energy. ```C++ /** * @fn getTargetEnergy * @brief Get the Target Energy object * @return uint32_t */ uint32_t getTargetEnergy(void); ``` -------------------------------- ### Get Target Range - DFRobot C4001 Source: https://github.com/dfrobot/dfrobot_c4001/blob/master/README.md Retrieves the range (distance) of the detected target. This function returns a `float` value representing the distance to the target. ```C++ /** * @fn getTargetRange * @brief Get the Target Range object * @return float */ float getTargetRange(void); ``` -------------------------------- ### Get IO Polarity - DFRobot C4001 Source: https://github.com/dfrobot/dfrobot_c4001/blob/master/README.md Retrieves the current I/O polarity setting for the sensor. This function returns the configured level of the signal output by the pin after the I/O port detects a target. ```C++ /** * @fn getIoPolaity * @brief Get the Io Polaity object * @return uint8_t The level of the signal output by the pin after the configured I/O port detects the target */ uint8_t getIoPolaity(void); ``` -------------------------------- ### Get Target Number - DFRobot C4001 Source: https://github.com/dfrobot/dfrobot_c4001/blob/master/README.md Retrieves the number of targets currently detected by the sensor. This function returns a `uint8_t` value representing the count of detected targets. ```C++ /** * @fn getTargetNumber * @brief Get the Target Number object * @return uint8_t */ uint8_t getTargetNumber(void); ``` -------------------------------- ### Get Fretting Detection Status - DFRobot C4001 Source: https://github.com/dfrobot/dfrobot_c4001/blob/master/README.md Retrieves the current status of the fretting detection feature. This function returns an enumeration type `eSwitch_t` indicating whether fretting detection is enabled or disabled. ```C++ /** * @fn getFrettingDetection * @brief Get the Fretting Detection object * @return eSwitch_t */ eSwitch_t getFrettingDetection(void); ``` -------------------------------- ### Get Minimum Detection Range - DFRobot C4001 Source: https://github.com/dfrobot/dfrobot_c4001/blob/master/README.md Retrieves the minimum detection range setting of the sensor. This function returns a `uint16_t` value representing the minimum distance in centimeters. ```C++ /** * @fn getTMinRange * @brief get speed Min Range * @return uint16_t */ uint16_t getTMinRange(void); ``` -------------------------------- ### Get Maximum Detection Range - DFRobot C4001 Source: https://github.com/dfrobot/dfrobot_c4001/blob/master/README.md Retrieves the maximum detection range setting of the sensor. This function returns a `uint16_t` value representing the maximum distance in centimeters. ```C++ /** * @fn getTMaxRange * @brief get speed Max Range * @return uint16_t */ uint16_t getTMaxRange(void); ``` -------------------------------- ### Initialize and Configure Sensor Source: https://github.com/dfrobot/dfrobot_c4001/blob/master/python/raspberrypi/README.md Methods to initialize the sensor and set basic operational modes such as sensor mode and trigger sensitivity. ```python def begin(self): pass def set_sensor_mode(self, mode): pass def set_trig_sensitivity(self, sensitivity): pass ``` -------------------------------- ### Configure Human Presence Detection with DFRobot C4001 Source: https://context7.com/dfrobot/dfrobot_c4001/llms.txt Demonstrates how to initialize the C4001 radar in presence detection mode. It configures sensitivity, detection range, and timing parameters, then polls for human presence in the main loop. ```cpp #include "DFRobot_C4001.h" DFRobot_C4001_I2C radar(&Wire, DEVICE_ADDR_0); void setup() { Serial.begin(115200); while(!Serial); while(!radar.begin()) { Serial.println("NO Devices!"); delay(1000); } Serial.println("Device connected!"); radar.setSensorMode(eExitMode); radar.setDetectionRange(30, 1000, 1000); radar.setTrigSensitivity(1); radar.setKeepSensitivity(2); radar.setDelay(100, 4); radar.setPwm(50, 0, 10); } void loop() { if(radar.motionDetection()) { Serial.println(">>> Human presence detected! <<<"); } delay(100); } ``` -------------------------------- ### Initialize C4001 Sensor via UART Source: https://context7.com/dfrobot/dfrobot_c4001/llms.txt Initializes the sensor using UART serial communication at a fixed baud rate of 9600. ```cpp #include "DFRobot_C4001.h" #if defined(ARDUINO_AVR_UNO) || defined(ESP8266) SoftwareSerial mySerial(4, 5); DFRobot_C4001_UART radar(&mySerial, 9600); #elif defined(ESP32) DFRobot_C4001_UART radar(&Serial1, 9600, /*rx*/D2, /*tx*/D3); #else DFRobot_C4001_UART radar(&Serial1, 9600); #endif void setup() { Serial.begin(115200); while(!radar.begin()) { Serial.println("NO Devices!"); delay(1000); } } ``` ```python from DFRobot_C4001 import * radar = DFRobot_C4001_UART(9600) while radar.begin() == False: print("Sensor initialize failed!!") time.sleep(1) print("Device connected!") ``` -------------------------------- ### Compatibility Information Source: https://github.com/dfrobot/dfrobot_c4001/blob/master/python/raspberrypi/README.md Details on compatibility with different Raspberry Pi and Python versions. ```APIDOC ## Compatibility ### Raspberry Pi Version | Board | Work Well | Work Wrong | Untested | Remarks | |--------------|-----------|------------|----------|---------| | RaspberryPi2 | | | √ | | | RaspberryPi3 | √ | | | | | RaspberryPi4 | | | √ | | ### Python Version | Python | Work Well | Work Wrong | Untested | Remarks | |---------|-----------|------------|----------|---------| | Python2 | √ | | | | | Python3 | √ | | | | ``` -------------------------------- ### Initialize C4001 Sensor via I2C Source: https://context7.com/dfrobot/dfrobot_c4001/llms.txt Initializes the sensor using the I2C interface. This requires specifying the I2C bus or wire object and the device address. ```cpp #include "DFRobot_C4001.h" DFRobot_C4001_I2C radar(&Wire, DEVICE_ADDR_0); void setup() { Serial.begin(115200); while(!radar.begin()) { Serial.println("NO Devices!"); delay(1000); } Serial.println("Device connected!"); } ``` ```python from DFRobot_C4001 import * I2C_BUS = 0x01 I2C_ADDR = 0x2A radar = DFRobot_C4001_I2C(I2C_BUS, I2C_ADDR) while radar.begin() == False: print("Sensor initialize failed!!") time.sleep(1) print("Device connected!") ``` -------------------------------- ### Configure Sensor Operating Mode Source: https://context7.com/dfrobot/dfrobot_c4001/llms.txt Sets the sensor to either Presence Detection (eExitMode/EXIST_MODE) or Speed Measurement (eSpeedMode/SPEED_MODE) and verifies the status. ```cpp radar.setSensorMode(eExitMode); sSensorStatus_t status = radar.getStatus(); Serial.print("Work mode: "); Serial.println(status.workMode); ``` ```python radar.set_sensor_mode(EXIST_MODE) status = radar.get_status() print(f"Work mode: {status.work_mode}") ``` -------------------------------- ### Sensor Control and Configuration Methods Source: https://github.com/dfrobot/dfrobot_c4001/blob/master/README.md Provides methods to control the sensor state, set detection ranges, and adjust sensitivity levels for motion detection. ```C++ bool motionDetection(void); void setSensor(eSetMode_t mode); bool setDelay(uint8_t trig , uint16_t keep); bool setDetectionRange(uint16_t min, uint16_t max); bool setTrigSensitivity(uint8_t sensitivity); bool setKeepSensitivity(uint8_t sensitivity); ``` -------------------------------- ### Configure Detection Range and Timing Source: https://github.com/dfrobot/dfrobot_c4001/blob/master/python/raspberrypi/README.md Methods to define detection boundaries and set timing delays for trigger and keep states. ```python def set_detection_range(self, min, max): pass def set_delay(self, trig, keep): pass ``` -------------------------------- ### Manage PWM and IO Polarity Source: https://github.com/dfrobot/dfrobot_c4001/blob/master/python/raspberrypi/README.md Methods to configure the output signal behavior, including PWM duty cycle transitions and IO pin polarity settings. ```python def set_io_polaity(self, value): pass def set_pwm(self, pwm1, pwm2, timer): pass ``` -------------------------------- ### Implement Speed and Range Tracking with DFRobot C4001 Source: https://context7.com/dfrobot/dfrobot_c4001/llms.txt Shows how to set the sensor to speed measurement mode to track target speed, distance, and signal energy. It includes enabling micro-motion detection for enhanced tracking accuracy. ```cpp #include "DFRobot_C4001.h" DFRobot_C4001_I2C radar(&Wire, DEVICE_ADDR_0); void setup() { Serial.begin(115200); while(!Serial); while(!radar.begin()) { Serial.println("NO Devices!"); delay(1000); } radar.setSensorMode(eSpeedMode); radar.setDetectThres(11, 1200, 10); radar.setFrettingDetection(eON); } void loop() { uint8_t targetCount = radar.getTargetNumber(); if(targetCount > 0) { Serial.print("Speed: "); Serial.print(radar.getTargetSpeed()); Serial.println(" m/s"); Serial.print("Distance: "); Serial.print(radar.getTargetRange()); Serial.println(" m"); } delay(100); } ``` -------------------------------- ### Configure PWM Output Signals Source: https://context7.com/dfrobot/dfrobot_c4001/llms.txt Configures PWM duty cycles for target detected and not-detected states. Includes a transition timer to control the speed of output state changes. ```cpp #include "DFRobot_C4001.h" DFRobot_C4001_I2C radar(&Wire, DEVICE_ADDR_0); void setup() { Serial.begin(115200); radar.begin(); if(radar.setPwm(50, 0, 20)) { Serial.println("PWM configured!"); } sPwmData_t pwmData = radar.getPwm(); Serial.print("PWM1 (no target): "); Serial.print(pwmData.pwm1); Serial.println("%"); } ``` -------------------------------- ### Configure Presence Detection Parameters Source: https://context7.com/dfrobot/dfrobot_c4001/llms.txt Configures the detection range (minimum, maximum, and trigger distance in cm) and sensitivity for presence detection mode. It also sets a delay for detection events. ```cpp #include "DFRobot_C4001.h" DFRobot_C4001_I2C radar(&Wire, DEVICE_ADDR_0); void setup() { Serial.begin(115200); radar.begin(); // Configure detection range (min, max, trig in cm) radar.setDetectionRange(30, 1000, 1000); radar.setTrigSensitivity(1); radar.setKeepSensitivity(1); radar.setDelay(100, 4); } void loop() { if (radar.motionDetection() == 1) { Serial.println("Human presence detected!"); } else { Serial.println("No presence"); } delay(100); } ``` -------------------------------- ### Sensitivity Configuration API Source: https://github.com/dfrobot/dfrobot_c4001/blob/master/README.md Configures and retrieves the sensitivity settings for triggering and detection. ```APIDOC ## setTrigSensitivity ### Description Sets the sensitivity for triggering detection. ### Method POST ### Endpoint /sensor/sensitivity/trig ### Parameters #### Request Body - **sensitivity** (uint8_t) - Required - Sensitivity level, range 0~9. ### Request Example ```json { "sensitivity": 5 } ``` ### Response #### Success Response (200) - **status** (boolean) - True if the sensitivity was set successfully, false otherwise. #### Response Example ```json { "status": true } ``` ## setKeepSensitivity ### Description Sets the sensitivity for maintaining detection. ### Method POST ### Endpoint /sensor/sensitivity/keep ### Parameters #### Request Body - **sensitivity** (uint8_t) - Required - Sensitivity level, range 0~9. ### Request Example ```json { "sensitivity": 5 } ``` ### Response #### Success Response (200) - **status** (boolean) - True if the sensitivity was set successfully, false otherwise. #### Response Example ```json { "status": true } ``` ## getTrigSensitivity ### Description Gets the current trigger sensitivity setting. ### Method GET ### Endpoint /sensor/sensitivity/trig ### Parameters None ### Request Example None ### Response #### Success Response (200) - **sensitivity** (uint8_t) - The current trigger sensitivity level. #### Response Example ```json { "sensitivity": 5 } ``` ## getKeepSensitivity ### Description Gets the current keep sensitivity setting. ### Method GET ### Endpoint /sensor/sensitivity/keep ### Parameters None ### Request Example None ### Response #### Success Response (200) - **sensitivity** (uint8_t) - The current keep sensitivity level. #### Response Example ```json { "sensitivity": 5 } ``` ``` -------------------------------- ### Delay Configuration API Source: https://github.com/dfrobot/dfrobot_c4001/blob/master/README.md Configures and retrieves delay parameters for sensor triggering and detection. ```APIDOC ## setDelay ### Description Sets the trigger delay and keep timeout for the sensor. ### Method POST ### Endpoint /sensor/delay ### Parameters #### Request Body - **trig** (uint8_t) - Required - Trigger delay, unit 0.01s, range 0~2s (0~200). - **keep** (uint16_t) - Required - Maintain the detection timeout, unit 0.5s, range 2~1500 seconds (4~3000). ### Request Example ```json { "trig": 50, "keep": 1000 } ``` ### Response #### Success Response (200) - **status** (boolean) - True if the delay parameters were set successfully, false otherwise. #### Response Example ```json { "status": true } ``` ## getTrigDelay ### Description Gets the current trigger delay setting. ### Method GET ### Endpoint /sensor/delay/trig ### Parameters None ### Request Example None ### Response #### Success Response (200) - **delay** (uint8_t) - The current trigger delay value. #### Response Example ```json { "delay": 50 } ``` ## getKeepTimerout ### Description Gets the current keep timeout setting. ### Method GET ### Endpoint /sensor/delay/keep ### Parameters None ### Request Example None ### Response #### Success Response (200) - **timeout** (uint16_t) - The current keep timeout value. #### Response Example ```json { "timeout": 1000 } ``` ``` -------------------------------- ### POST /setPwm Source: https://github.com/dfrobot/dfrobot_c4001/blob/master/README.md Configures the PWM output duty cycle and transition timing for the sensor's OUT pin. ```APIDOC ## POST /setPwm ### Description Sets the PWM duty cycle for target and non-target states, and the transition time. ### Method POST ### Endpoint /setPwm ### Parameters #### Request Body - **pwm1** (uint8_t) - Required - Duty cycle (0-100) when no target is detected. - **pwm2** (uint8_t) - Required - Duty cycle (0-100) when target is detected. - **timer** (uint8_t) - Required - Transition time in 64ms increments (0-255). ### Request Example { "pwm1": 0, "pwm2": 100, "timer": 20 } ### Response #### Success Response (200) - **result** (boolean) - Returns true if successful. ``` -------------------------------- ### Perform Motion Detection Source: https://context7.com/dfrobot/dfrobot_c4001/llms.txt Configures detection parameters and continuously checks for human presence within the sensor's field of view. ```cpp radar.setDetectionRange(30, 1000, 1000); radar.setTrigSensitivity(1); radar.setDelay(100, 4); void loop() { if(radar.motionDetection()) { Serial.println("Human presence detected!"); } delay(100); } ``` -------------------------------- ### Configure Detection Range for Presence Mode Source: https://context7.com/dfrobot/dfrobot_c4001/llms.txt Sets the minimum, maximum, and trigger detection distances in centimeters for Presence Mode. It also demonstrates how to read back these configured values. ```cpp #include "DFRobot_C4001.h" DFRobot_C4001_I2C radar(&Wire, DEVICE_ADDR_0); void setup() { Serial.begin(115200); radar.begin(); radar.setSensorMode(eExitMode); // Set detection range: min=30cm (0.3m), max=1000cm (10m), trig=1000cm // min: 30-2000 cm, max: 240-2000 cm, trig: 240-2000 cm // Trigger distance determines when "no presence" changes to "presence detected" if(radar.setDetectionRange(30, 1000, 1000)) { Serial.println("Detection range configured successfully!"); } // Read back configuration Serial.print("Min range: "); Serial.print(radar.getMinRange()); Serial.println(" cm"); Serial.print("Max range: "); Serial.print(radar.getMaxRange()); Serial.println(" cm"); Serial.print("Trigger range: "); Serial.print(radar.getTrigRange()); Serial.println(" cm"); } ``` -------------------------------- ### Version History Source: https://github.com/dfrobot/dfrobot_c4001/blob/master/python/raspberrypi/README.md Chronological record of the project's versions. ```APIDOC ## History - 2024/02/26 - Version 1.0.0 released. ``` -------------------------------- ### Configure Detection Thresholds for Speed Mode Source: https://context7.com/dfrobot/dfrobot_c4001/llms.txt Sets the minimum range, maximum range, and sensitivity threshold for Speed Mode. It also shows how to retrieve these configured threshold values. ```cpp #include "DFRobot_C4001.h" DFRobot_C4001_I2C radar(&Wire, DEVICE_ADDR_0); void setup() { Serial.begin(115200); radar.begin(); radar.setSensorMode(eSpeedMode); // Set detection thresholds: min=11cm, max=1200cm, threshold=10 // min: 0-2500 cm, max: 0-2500 cm, threshold: 0-65535 (dimensionless, unit 0.1) if(radar.setDetectThres(11, 1200, 10)) { Serial.println("Detection threshold configured!"); } // Read back configuration Serial.print("Min range: "); Serial.println(radar.getTMinRange()); Serial.print("Max range: "); Serial.println(radar.getTMaxRange()); Serial.print("Threshold: "); Serial.println(radar.getThresRange()); } ``` -------------------------------- ### Set PWM Duty Cycle and Timer - DFRobot C4001 Source: https://github.com/dfrobot/dfrobot_c4001/blob/master/README.md Sets the PWM output for the OUT pin, controlling the duty cycle based on target detection. It takes two duty cycle values (pwm1 for no target, pwm2 for target detected) and a timer value to control the transition speed between these duty cycles. The timer value ranges from 0 to 255, where each unit corresponds to 64ms. ```C++ /** * @fn setPwm * @brief Set the Pwm object * @param pwm1 When no target is detected, the duty cycle of the output signal of the OUT pin ranges from 0 to 100 * @param pwm2 After the target is detected, the duty cycle of the output signal of the OUT pin ranges from 0 to 100 * @param timer timer The value ranges from 0 to 255, corresponding to timer x 64ms * @n For example, timer=20, it takes 20*64ms=1.28s for the duty cycle to change from pwm1 to pwm2. * @return true or false */ bool setPwm(uint8_t pwm1 , uint8_t pwm2, uint8_t timer); ``` -------------------------------- ### POST /setDetectThres Source: https://github.com/dfrobot/dfrobot_c4001/blob/master/README.md Sets the detection range and sensitivity threshold for the sensor. ```APIDOC ## POST /setDetectThres ### Description Configures the minimum and maximum detection distances and the target detection sensitivity threshold. ### Method POST ### Endpoint /setDetectThres ### Parameters #### Request Body - **min** (uint16_t) - Required - Min distance in cm (30-2000). - **max** (uint16_t) - Required - Max distance in cm (240-2000). - **thres** (uint16_t) - Required - Sensitivity threshold (0-65535). ### Request Example { "min": 30, "max": 2000, "thres": 1000 } ### Response #### Success Response (200) - **result** (boolean) - Returns true if successful. ``` -------------------------------- ### Motion and Target Data Retrieval Source: https://github.com/dfrobot/dfrobot_c4001/blob/master/python/raspberrypi/README.md Methods to detect motion and retrieve specific target data including speed, range, energy, and target count. ```python def motion_detection(self): return status def get_target_number(self): return target_number def get_target_speed(self): return target_speed def get_target_range(self): return target_range ``` -------------------------------- ### Set IO Polarity - DFRobot C4001 Source: https://github.com/dfrobot/dfrobot_c4001/blob/master/README.md Configures the I/O polarity for target detection. It accepts a value where 0 sets low level for target detection and high level otherwise, while 1 (default) sets high level for target detection and low level otherwise. Returns true on success, false otherwise. ```C++ /** * @brief Set the Io Polaity object * @n 0:Output low level when there is a target, output high level when there is no target * @n 1: Output high level when there is a target, output low level when there is no target (default) * @return true or false */ bool setIoPolaity(uint8_t value); ``` -------------------------------- ### Presence Detection API Source: https://context7.com/dfrobot/dfrobot_c4001/llms.txt Configures the radar for human presence detection and retrieves status. ```APIDOC ## POST /sensor/mode/presence ### Description Sets the radar sensor to presence detection mode and configures sensitivity and range parameters. ### Method POST ### Endpoint /sensor/mode/presence ### Parameters #### Request Body - **mode** (enum) - Required - Set to eExitMode for presence detection. - **range_min** (int) - Required - Minimum detection distance in cm. - **range_max** (int) - Required - Maximum detection distance in cm. - **trig_sensitivity** (int) - Required - Sensitivity level (0-9). ### Request Example { "mode": "eExitMode", "range_min": 30, "range_max": 1000, "trig_sensitivity": 1 } ### Response #### Success Response (200) - **status** (object) - Current sensor configuration status. #### Response Example { "status": "success", "mode": "presence" } ``` -------------------------------- ### Measure Target Speed, Range, and Energy in Speed Mode Source: https://context7.com/dfrobot/dfrobot_c4001/llms.txt Enables Speed Mode and configures detection thresholds. It then continuously retrieves and prints the number of targets, their speed (m/s), range (m), and signal energy. ```cpp #include "DFRobot_C4001.h" DFRobot_C4001_I2C radar(&Wire, DEVICE_ADDR_0); void setup() { Serial.begin(115200); radar.begin(); // Enable Speed Mode radar.setSensorMode(eSpeedMode); // Configure speed mode parameters radar.setDetectThres(11, 1200, 10); // min=11cm, max=1200cm, threshold=10 radar.setFrettingDetection(eON); // Enable micro-motion detection } void loop() { uint8_t targets = radar.getTargetNumber(); // Must call first to update buffer Serial.print("Target count: "); Serial.println(targets); Serial.print("Target speed: "); Serial.print(radar.getTargetSpeed()); Serial.println(" m/s"); Serial.print("Target range: "); Serial.print(radar.getTargetRange()); Serial.println(" m"); Serial.print("Target energy: "); Serial.println(radar.getTargetEnergy()); delay(100); } ``` ```python from DFRobot_C4001 import * import time rada r = DFRobot_C4001_I2C(0x01, 0x2A) rada r.begin() # Enable Speed Mode rada r.set_sensor_mode(SPEED_MODE) # Configure speed mode parameters rada r.set_detect_thres(11, 1200, 11) # min, max, threshold rada r.set_fretting_detection(FRETTING_ON) while True: targets = rada r.get_target_number() # Must call first speed = rada r.get_target_speed() distance = rada r.get_target_range() energy = rada r.get_target_energy() print(f"Targets: {targets}") print(f"Speed: {speed} m/s") print(f"Range: {distance} m") print(f"Energy: {energy}") time.sleep(0.1) ``` -------------------------------- ### Define Sensor Data Structures Source: https://github.com/dfrobot/dfrobot_c4001/blob/master/README.md Defines the core data structures used by the C4001 sensor, including status, response data, and PWM configuration parameters. ```C++ typedef struct{ uint8_t number; float speed; float range; uint32_t energy; }sPrivateData_t; typedef struct{ bool status; float response1; float response2; float response3; }sResponseData_t; typedef struct{ uint8_t pwm1; uint8_t pwm2; uint8_t timer; }sPwmData_t; ``` -------------------------------- ### Presence Detection Configuration Source: https://context7.com/dfrobot/dfrobot_c4001/llms.txt Configures the radar sensor for presence detection, setting detection ranges and sensitivities. ```APIDOC ## Presence Detection Configuration ### setDetectionRange Configure the minimum, maximum, and trigger detection distances for Presence Mode. Distances are in centimeters. ### Method `setDetectionRange(min_cm, max_cm, trig_cm)` ### Parameters - **min_cm** (int) - Required - Minimum detection distance in centimeters (30-2000). - **max_cm** (int) - Required - Maximum detection distance in centimeters (240-2000). - **trig_cm** (int) - Required - Trigger distance in centimeters (240-2000). This determines when 'no presence' changes to 'presence detected'. ### Request Example (C++) ```cpp #include "DFRobot_C4001.h" DFRobot_C4001_I2C radar(&Wire, DEVICE_ADDR_0); void setup() { Serial.begin(115200); radar.begin(); radar.setSensorMode(eExitMode); // Set detection range: min=30cm, max=1000cm, trig=1000cm if(radar.setDetectionRange(30, 1000, 1000)) { Serial.println("Detection range configured successfully!"); } } ``` ### setTrigSensitivity and setKeepSensitivity Configure trigger sensitivity (how easily presence is detected) and keep sensitivity (how easily presence is maintained). Values range from 0-9. ### Method `setTrigSensitivity(sensitivity)` `setKeepSensitivity(sensitivity)` ### Parameters - **sensitivity** (int) - Required - Sensitivity level (0-9). Higher values indicate greater sensitivity. ### Request Example (C++) ```cpp #include "DFRobot_C4001.h" DFRobot_C4001_I2C radar(&Wire, DEVICE_ADDR_0); void setup() { Serial.begin(115200); radar.begin(); radar.setSensorMode(eExitMode); // Set trigger sensitivity (0-9, higher = more sensitive) if(radar.setTrigSensitivity(1)) { Serial.println("Trigger sensitivity set!"); } // Set keep sensitivity (0-9, higher = more sensitive) if(radar.setKeepSensitivity(2)) { Serial.println("Keep sensitivity set!"); } } ``` ### Python Presence Detection Example ```python from DFRobot_C4001 import * import time rada = DFRobot_C4001_I2C(0x01, 0x2A) rada.begin() # Configure detection parameters rada.set_detection_range(30, 1000, 1000) # min, max, trig in cm rada.set_trig_sensitivity(1) rada.set_keep_sensitivity(1) while True: if rada.motion_detection() == 1: print("Human presence detected!") else: print("No presence") time.sleep(0.1) ``` ``` -------------------------------- ### DFRobot C4001 Sensor API Methods Source: https://github.com/dfrobot/dfrobot_c4001/blob/master/python/raspberrypi/README.md This section details the various methods available for controlling and querying the DFRobot C4001 sensor. ```APIDOC ## DFRobot C4001 Sensor API Methods ### Description This section details the various methods available for controlling and querying the DFRobot C4001 sensor. ### Methods #### `begin()` * **Description**: Initializes the sensor. * **Method**: `void` #### `get_status()` * **Description**: Retrieves the current status of the sensor. * **Return**: `status` (type depends on implementation, likely int or bool) #### `motion_detection()` * **Description**: Checks for motion detection. * **Return**: `status` (int) * `0`: No motion detected * `1`: Motion detected #### `set_sensor_mode(mode)` * **Description**: Sets the operating mode of the sensor. * **Parameters**: * **mode** (enum/string) - The desired sensor mode. Possible values: `SPEED_MODE`, `EXIST_MODE`. #### `set_trig_sensitivity(sensitivity)` * **Description**: Sets the trigger sensitivity for motion detection. * **Parameters**: * **sensitivity** (int) - Sensitivity level from 0 to 9. #### `get_trig_sensitivity()` * **Description**: Retrieves the current trigger sensitivity setting. * **Return**: `sensitivity` (int) - The current sensitivity level (0-9). #### `set_keep_sensitivity(sensitivity)` * **Description**: Sets the sensitivity for maintaining detection. * **Parameters**: * **sensitivity** (int) - Sensitivity level from 0 to 9. #### `get_keep_sensitivity()` * **Description**: Retrieves the current keep sensitivity setting. * **Return**: `sensitivity` (int) - The current keep sensitivity level (0-9). #### `set_delay(trig, keep)` * **Description**: Configures the trigger and keep delay timers. * **Parameters**: * **trig** (int) - Trigger delay in units of 10ms (0-200, corresponding to 0s-2.0s). * **keep** (int) - Keep timeout in seconds (4-3000, corresponding to 2s-1500s). #### `get_trig_delay()` * **Description**: Retrieves the current trigger delay setting. * **Return**: `trig` (int) - The current trigger delay value. #### `get_keep_timerout()` * **Description**: Retrieves the current keep timeout setting. * **Return**: `keep timerout` (int) - The current keep timeout value. #### `set_detection_range(min, max)` * **Description**: Sets the minimum and maximum detection range for the sensor. * **Parameters**: * **min** (int) - Minimum detection range (30-2000). * **max** (int) - Maximum detection range (240-2000). * **Note**: `min` must not be greater than `max`. #### `get_trig_range()` * **Description**: Retrieves the current trigger range setting. * **Return**: `trig range` (int) - The current trigger range value. #### `get_max_range()` * **Description**: Retrieves the maximum detection range setting. * **Return**: `max range` (int) - The maximum detection range value. #### `get_min_range()` * **Description**: Retrieves the minimum detection range setting. * **Return**: `min range` (int) - The minimum detection range value. #### `get_target_number()` * **Description**: Retrieves the number of detected targets. * **Return**: `target number` (int) #### `get_target_speed()` * **Description**: Retrieves the speed of the detected target. * **Return**: `target speed` (float/int) #### `get_target_range()` * **Description**: Retrieves the range of the detected target. * **Return**: `target range` (int) #### `get_target_energy()` * **Description**: Retrieves the energy signature of the detected target. * **Return**: `target energy` (int/float) #### `set_detect_thres(min, max, thres)` * **Description**: Sets the detection thresholds. * **Parameters**: * **min** (int) - Minimum threshold value (0-2500). * **max** (int) - Maximum threshold value (0-2500). * **thres** (int) - General threshold value (0-65535). #### `set_io_polaity(value)` * **Description**: Configures the polarity of the sensor's output signal. * **Parameters**: * **value** (int) - Polarity setting. * `0`: Low output when target present, high when absent. * `1`: High output when target present, low when absent (default). #### `get_io_polaity()` * **Description**: Retrieves the current IO polarity setting. * **Return**: `io status` (int) - The current polarity setting (0 or 1). #### `set_pwm(pwm1, pwm2, timer)` * **Description**: Configures PWM output settings for the OUT pin. * **Parameters**: * **pwm1** (int) - Duty cycle (%) when no target is detected (0-100). * **pwm2** (int) - Duty cycle (%) after a target is detected (0-100). * **timer** (int) - Transition time from pwm1 to pwm2 (0-255, where each unit is 64ms). * **Example**: `timer=20` results in a 1.28s transition time. #### `get_pwm()` * **Description**: Retrieves the current PWM settings. * **Return**: `pwm value` (tuple/dict) - Contains pwm1, pwm2, and timer values. #### `get_tmin_range()` * **Description**: Retrieves the minimum range for speed mode. * **Return**: `speed mode min range` (int) #### `get_tmax_range()` * **Description**: Retrieves the maximum range for speed mode. * **Return**: `speed mode max range` (int) #### `get_thres_range()` * **Description**: Retrieves the threshold range for speed mode. * **Return**: `speed mode thres range` (int) #### `set_fretting_detection(status)` * **Description**: Enables or disables fretting detection. * **Parameters**: * **status** (enum/string) - Fretting detection status. Possible values: `FRETTING_ON`, `FRETTING_OFF`. #### `get_fretting_detection()` * **Description**: Retrieves the current status of fretting detection. * **Return**: `status` (enum/string) - The current fretting detection status. ``` -------------------------------- ### setDelay Source: https://context7.com/dfrobot/dfrobot_c4001/llms.txt Configures the trigger delay and keep timeout for presence detection. ```APIDOC ## setDelay ### Description Configures the trigger delay (time before presence is confirmed) and keep timeout (time before absence is confirmed). ### Method void setDelay(uint8_t trig, uint16_t keep) ### Parameters - **trig** (uint8_t) - Required - Trigger delay (0-200, unit 0.01s) - **keep** (uint16_t) - Required - Keep timeout (4-3000, unit 0.5s) ### Request Example radar.setDelay(100, 4); ``` -------------------------------- ### Configure Radar Trigger and Keep Delays Source: https://context7.com/dfrobot/dfrobot_c4001/llms.txt Sets the trigger delay for presence confirmation and the keep timeout for absence detection. Inputs include the trigger delay (0-200 units) and keep timeout (4-3000 units). ```cpp #include "DFRobot_C4001.h" DFRobot_C4001_I2C radar(&Wire, DEVICE_ADDR_0); void setup() { Serial.begin(115200); radar.begin(); radar.setSensorMode(eExitMode); if(radar.setDelay(100, 4)) { Serial.println("Delay parameters configured!"); } Serial.print("Trigger delay: "); Serial.println(radar.getTrigDelay()); Serial.print("Keep timeout: "); Serial.println(radar.getKeepTimerout()); } ``` -------------------------------- ### Range Configuration API Source: https://github.com/dfrobot/dfrobot_c4001/blob/master/README.md Manages the detection range and trigger distance for the sensor. ```APIDOC ## setDetectionRange ### Description Sets the minimum, maximum, and trigger detection ranges for the sensor. ### Method POST ### Endpoint /sensor/range ### Parameters #### Request Body - **min** (uint16_t) - Required - Minimum detection range, unit cm, range 30~2000. - **max** (uint16_t) - Required - Maximum detection range, unit cm, range 240~2000. - **trig** (uint16_t) - Required - Trigger distance, unit cm, range 240~2000. ### Request Example ```json { "min": 30, "max": 2000, "trig": 600 } ``` ### Response #### Success Response (200) - **status** (boolean) - True if the range parameters were set successfully, false otherwise. #### Response Example ```json { "status": true } ``` ## getTrigRange ### Description Gets the current trigger range setting. ### Method GET ### Endpoint /sensor/range/trig ### Parameters None ### Request Example None ### Response #### Success Response (200) - **range** (uint16_t) - The current trigger range in cm. #### Response Example ```json { "range": 600 } ``` ## getMaxRange ### Description Gets the maximum detection range of the sensor. ### Method GET ### Endpoint /sensor/range/max ### Parameters None ### Request Example None ### Response #### Success Response (200) - **range** (uint16_t) - The maximum detection range in cm. #### Response Example ```json { "range": 2000 } ``` ## getMinRange ### Description Gets the minimum detection range of the sensor. ### Method GET ### Endpoint /sensor/range/min ### Parameters None ### Request Example None ### Response #### Success Response (200) - **range** (uint16_t) - The minimum detection range in cm. #### Response Example ```json { "range": 30 } ``` ``` -------------------------------- ### Speed Measurement API Source: https://context7.com/dfrobot/dfrobot_c4001/llms.txt Configures the radar for speed and range tracking of moving targets. ```APIDOC ## POST /sensor/mode/speed ### Description Sets the radar sensor to speed measurement mode and enables target tracking features. ### Method POST ### Endpoint /sensor/mode/speed ### Parameters #### Request Body - **mode** (enum) - Required - Set to eSpeedMode. - **fretting_detection** (bool) - Required - Enable or disable micro-motion detection. ### Request Example { "mode": "eSpeedMode", "fretting_detection": true } ### Response #### Success Response (200) - **target_count** (int) - Number of detected targets. - **speed** (float) - Speed of the target in m/s. - **distance** (float) - Distance of the target in meters. #### Response Example { "target_count": 1, "speed": 1.5, "distance": 2.4 } ``` -------------------------------- ### Sensor Control API Source: https://github.com/dfrobot/dfrobot_c4001/blob/master/README.md Allows for controlling the sensor's operational state and mode. ```APIDOC ## setSensor ### Description Sets the operational mode or state of the sensor. ### Method POST ### Endpoint /sensor/control ### Parameters #### Request Body - **mode** (eSetMode_t) - Required - The mode to set the sensor to. Possible values: - eStartSen: start collect - eStopSen: stop collect - eResetSen: reset sensor - eRecoverSen: recover params - eSaveParams: save config - eChangeMode: change mode ### Request Example ```json { "mode": "eStartSen" } ``` ### Response #### Success Response (200) - **status** (boolean) - Indicates if the operation was successful. #### Response Example ```json { "status": true } ``` ``` -------------------------------- ### Credits Source: https://github.com/dfrobot/dfrobot_c4001/blob/master/python/raspberrypi/README.md Information about the authors and contributors. ```APIDOC ## Credits Written by ZhixinLiu(zhixin.liu@dfrobot.com), 2022. (Welcome to our website) ``` -------------------------------- ### Motion Detection API Source: https://github.com/dfrobot/dfrobot_c4001/blob/master/README.md Provides functionality to check if motion is detected by the sensor. ```APIDOC ## motionDetection ### Description Checks if motion is detected by the sensor. ### Method GET ### Endpoint /sensor/motion ### Parameters None ### Request Example None ### Response #### Success Response (200) - **detected** (boolean) - True if motion is detected, false otherwise. #### Response Example ```json { "detected": true } ``` ```