<root>
<document scada='0' projtype='1' schema='103' license='1,79829088,Q2XNNM' title='New Embedded Project' description='' fcversion='720896' target='ESP.ESP32.ESP32_WROOM_32' >
	<config data='' clkspd='240000000' simspd='0' usewdt='0' constif='0' commport='6' Use3V3='0' />
	<plugins >
		<dll_models enabled='1' />
	</plugins>
	<supplement use='1' head='#include &quot;driver/ledc.h&quot;
#include &quot;driver/uart.h&quot;
#include &quot;driver/gpio.h&quot;

#define MOTOR_PWM_PIN       (GPIO_NUM_22) // Map to your specific P4 GPIO
#define MOTOR_PWM_CHANNEL   LEDC_CHANNEL_0
#define MOTOR_PWM_TIMER     LEDC_TIMER_0

#define LIDAR_UART_PORT      UART_NUM_1
#define LIDAR_TX_PIN         (GPIO_NUM_16)  // Change based on your wiring
#define LIDAR_RX_PIN         (GPIO_NUM_17)  // Change based on your wiring
#define RX_BUF_SIZE             (2048)

void init_lidar_uart();
void init_lidar_motor_pwm();
void set_lidar_rpm(uint32_t duty_cycle);
void lidar_rx_task();
void lidar_tx(char *, int len);' body='void init_lidar_uart() {
    const uart_config_t uart_config = {
        .baud_rate = 230400,
        .data_bits = UART_DATA_8_BITS,
        .parity    = UART_PARITY_DISABLE,
        .stop_bits = UART_STOP_BITS_1,
        .flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
        .source_clk = UART_SCLK_DEFAULT,
    };

    // We use a large RX buffer because LiDAR data comes in high-frequency bursts
    uart_driver_install(LIDAR_UART_PORT, RX_BUF_SIZE * 2, 0, 0, NULL, 0);
    uart_param_config(LIDAR_UART_PORT, &amp;uart_config);
    uart_set_pin(LIDAR_UART_PORT, LIDAR_TX_PIN, LIDAR_RX_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
}

void init_lidar_motor_pwm() {
    // 1. Timer Configuration
    ledc_timer_config_t ledc_timer = {
        .speed_mode       = LEDC_LOW_SPEED_MODE,
        .timer_num        = MOTOR_PWM_TIMER,
        .duty_resolution  = LEDC_TIMER_10_BIT, // 0 to 1023
        .freq_hz          = 10000,             // 10kHz frequency
        .clk_cfg          = LEDC_AUTO_CLK
    };
    ledc_timer_config(&amp;ledc_timer);

    // 2. Channel Configuration
    ledc_channel_config_t ledc_channel = {
        .speed_mode     = LEDC_LOW_SPEED_MODE,
        .channel        = MOTOR_PWM_CHANNEL,
        .timer_sel      = MOTOR_PWM_TIMER,
        .intr_type      = LEDC_INTR_DISABLE,
        .gpio_num       = MOTOR_PWM_PIN,
        .duty           = 0, // Start at 0% (stopped)
        .hpoint         = 0
    };
    ledc_channel_config(&amp;ledc_channel);
}

void set_lidar_rpm(uint32_t duty_cycle) {
    // duty_cycle range 0 to 1023 for 10-bit resolution
    ledc_set_duty(LEDC_LOW_SPEED_MODE, MOTOR_PWM_CHANNEL, duty_cycle);
    ledc_update_duty(LEDC_LOW_SPEED_MODE, MOTOR_PWM_CHANNEL);
}


void lidar_rx_task() {
    // 1. Allocate a temporary buffer for incoming data chunks
    uint8_t *data = (uint8_t *) malloc(RX_BUF_SIZE);
   while (1) {
        // 2. Read bytes from UART Driver Buffer
        // uart_read_bytes(port, buffer, max_length, timeout)
        // This function BLOCKS (waits) until data arrives or timeout (10ms) expires.
        int len = uart_read_bytes(LIDAR_UART_PORT, data, RX_BUF_SIZE, 20 / portTICK_PERIOD_MS);
        // 3. If we received data, feed the parser
        if (len &gt; 0) {
            for (int i = 0; i &lt; len; i++) {
                FCM_RxLIDAR(data[i]);              // call state machine
            }
        }
    }
}

void lidar_tx(char *cmd, int len) {
   uart_write_bytes(LIDAR_UART_PORT, cmd, len);
} ' />
	<debug />
	<traces />
	<ghost >
		<FK2 >
			<data name='FK2D0' port='4294967295' pin='4294967295' />
			<data name='FK2D1' port='4294967295' pin='4294967295' />
			<data name='FK2D2' port='4294967295' pin='4294967295' />
			<data name='FK2D3' port='4294967295' pin='4294967295' />
			<data name='FK2D4' port='4294967295' pin='4294967295' />
			<data name='FK2D5' port='4294967295' pin='4294967295' />
			<data name='FK2D6' port='4294967295' pin='4294967295' />
			<data name='FK2D7' port='4294967295' pin='4294967295' />
			<data name='FK2D8' port='4294967295' pin='4294967295' />
			<data name='FK2D9' port='4294967295' pin='4294967295' />
			<data name='FK2D10' port='4294967295' pin='4294967295' />
			<data name='FK2D11' port='4294967295' pin='4294967295' />
			<data name='FK2D12' port='4294967295' pin='4294967295' />
			<data name='FK2D13' port='4294967295' pin='4294967295' />
			<data name='FK2D14' port='4294967295' pin='4294967295' />
			<data name='FK2D15' port='4294967295' pin='4294967295' />
			<data name='FK2A0' port='4294967295' pin='4294967295' />
			<data name='FK2A1' port='4294967295' pin='4294967295' />
			<data name='FK2A2' port='4294967295' pin='4294967295' />
			<data name='FK2A3' port='4294967295' pin='4294967295' />
			<data name='FK2A4' port='4294967295' pin='4294967295' />
			<data name='FK2A5' port='4294967295' pin='4294967295' />
		</FK2>
		<ICD >
			<data name='AnalogPrescaleValue' value='19' />
			<data name='DigitalSampleRate' value='100000' />
			<data name='BreakpointCount' value='8' />
			<data name='CallStackDepthCount' value='8' />
			<data name='ClockPort' value='1' />
			<data name='ClockPin' value='6' />
			<data name='DataPort' value='1' />
			<data name='DataPin' value='7' />
			<data name='UseDefaultPins' value='1' />
			<data name='WrapEnabled' value='1' />
			<data name='CommsDelayOverridden' value='0' />
			<data name='CommsDelay' value='1' />
			<data name='CalculatedCommsDelay' value='1' />
			<data name='AnalogEB2PrescaleValue' value='2' />
			<data name='DigitalEB2SampleRate' value='100000' />
		</ICD>
		<pins >
			<digital A='0' B='0' C='0' D='0' E='0' F='0' G='0' H='0' I='0' J='0' K='0' L='0' M='0' N='0' O='0' P='0' Q='0' R='0' S='0' T='0' U='0' V='0' W='0' X='0' Y='0' Z='0' />
			<analog A='0' B='0' C='0' D='0' E='0' F='0' G='0' H='0' I='0' J='0' K='0' L='0' M='0' N='0' O='0' P='0' Q='0' R='0' S='0' T='0' U='0' V='0' W='0' X='0' Y='0' Z='0' />
		</pins>
	</ghost>
	<components >
		<settings autoimg='0' center='1' unitscale='0' fixedscale='0' fixedx='25' fixedy='25' fixedz='25' headcode='0' />
		<definition guid='ef176e15-dd33-43d9-a7aa-e3ccb1734228' vstate='40' vmin='0' vmaj='1' srcleaf='' visiblename='' description='' category='' category2='' category3='' bIs2dOnly='0' bIs3dOnly='0' bIsWysiwyg='0' catenable='1' author='' manuname='' manucode='' sysinfo='0' keywords='' dynamic='1' scadaCompatible='0' embeddedCompatible='1' showmacros='1' iconpath='' />
		<component class_type='root' codename='ComponentRoot' panelId='-1' x='0' y='0' z='0' xsz='1' ysz='1' zsz='1' xang='0' yang='0' zang='0' xquat='0' yquat='0' zquat='0' wquat='1' visible='1' scadavisible='1' interactive='1' solid='1' layer='0' poslock='0' ancTop='0' ancBottom='0' ancLeft='0' ancRight='0' ancMinX='0' ancMinY='0' comp2dType='0' >
			<resources />
			<properties >
				<property name='MCtrl' target='mctrl' typeid='5' hidden='0' locked='0' info='' />
			</properties>
			<values >
				<value target='mctrl' data='$PORTA.22' />
			</values>
			<events />
			<apis />
			<variables >
				<variable public='0' >
					<def class_type='variable' name='health' type='u8' description='' isconst='1' isHidden='0' isinit='1' usrinit='&quot; 0xa5, 0x92 &quot;' setinit='{0xa5, 0x92}' >
						<array size='2' />
					</def>
				</variable>
				<variable public='0' >
					<def class_type='variable' name='data_queue' type='u32' description='' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='stop' type='u8' description='' isconst='1' isHidden='0' isinit='1' usrinit='&quot; 0xa5, 0x65 &quot;' setinit='{0xa5, 0x65}' >
						<array size='2' />
					</def>
				</variable>
				<variable public='0' >
					<def class_type='variable' name='header' type='u32' description='' isconst='1' isHidden='0' isinit='1' usrinit='2' setinit='2' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='payload' type='u32' description='' isconst='1' isHidden='0' isinit='1' usrinit='3' setinit='3' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='info' type='u8' description='' isconst='1' isHidden='0' isinit='1' usrinit='&quot; 0xa5, 0x90 &quot;' setinit='{0xa5, 0x90}' >
						<array size='2' />
					</def>
				</variable>
				<variable public='0' >
					<def class_type='variable' name='points' type='u32' description='' isconst='0' isHidden='0' isinit='1' usrinit='0' setinit='0' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='false' type='b1' description='' isconst='1' isHidden='0' isinit='1' usrinit='0' setinit='0' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='state' type='u32' description='' isconst='0' isHidden='0' isinit='1' usrinit='0' setinit='0' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='n_laps' type='u32' description='Process every &apos;n&apos; laps - so if n = 2 every 2nd lap 3 = every third etc' isconst='1' isHidden='0' isinit='1' usrinit='2' setinit='2' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='idx' type='u32' description='' isconst='0' isHidden='0' isinit='1' usrinit='0' setinit='0' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='buffer' type='u32' description='' isconst='0' isHidden='0' isinit='1' usrinit='0' setinit='0' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='start' type='u8' description='' isconst='1' isHidden='0' isinit='1' usrinit='&quot; 0xA5, 0x60 &quot;' setinit='{0xA5, 0x60}' >
						<array size='2' />
					</def>
				</variable>
				<variable public='0' >
					<def class_type='variable' name='sync2' type='u32' description='' isconst='1' isHidden='0' isinit='1' usrinit='1' setinit='1' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='sync1' type='u32' description='' isconst='1' isHidden='0' isinit='1' usrinit='0' setinit='0' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='ProcessDataTask' type='u32' description='' isconst='0' isHidden='0' isinit='1' usrinit='0' setinit='0' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='single' type='u8' description='' isconst='1' isHidden='0' isinit='1' usrinit='&quot; 0xa5, 0x64 &quot;' setinit='{0xa5, 0x64}' >
						<array size='2' />
					</def>
				</variable>
				<variable public='0' >
					<def class_type='variable' name='data_header' type='u8' description='' isconst='0' isHidden='0' isinit='0' usrinit='&quot;&quot;' setinit='' >
						<array size='10' />
					</def>
				</variable>
				<variable public='0' >
					<def class_type='variable' name='true' type='b1' description='' isconst='1' isHidden='0' isinit='1' usrinit='1' setinit='1' />
				</variable>
			</variables>
			<macros >
				<macro >
					<flowline name='CorrectionAngle' description='' statediag='0' >
						<return name='Return' type='f32' description='' isconst='0' isHidden='0' isinit='0' usrinit='0.0' setinit='' />
						<param name='dist' type='u32' description='' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<local name='ca' type='f32' description='' isconst='0' isHidden='0' isinit='1' usrinit='0.0' setinit='0' />
						<local name='num' type='f32' description='' isconst='0' isHidden='0' isinit='1' usrinit='0.0' setinit='0' />
						<local name='den' type='f32' description='' isconst='0' isHidden='0' isinit='1' usrinit='0.0' setinit='0' />
						<command class_type='calculation' title='Calculation' >
							<exp exp='.num = 21.8 * (155.3 - .dist)' />
							<exp exp='.den = 155.3 * .dist' />
							<exp exp='.ca = atan(.num / .den)' />
							<exp exp='.Return = .ca * 57.2957795' />
						</command>
					</flowline>
				</macro>
				<macro >
					<flowline name='ProcessData' description='' statediag='0' >
						<return name='Return' type='v0' description='' isconst='0' isHidden='0' isinit='0' usrinit='' setinit='' />
						<local name='i' type='u32' description='' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<local name='j' type='u32' description='' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<local name='points' type='u32' description='' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<local name='diff' type='f32' description='' isconst='0' isHidden='0' isinit='0' usrinit='0.0' setinit='' />
						<local name='start' type='f32' description='' isconst='0' isHidden='0' isinit='0' usrinit='0.0' setinit='' />
						<local name='end' type='f32' description='' isconst='0' isHidden='0' isinit='0' usrinit='0.0' setinit='' />
						<local name='end_raw' type='u16' description='' isconst='0' isHidden='0' isinit='1' usrinit='0' setinit='0' />
						<local name='start_raw' type='u16' description='' isconst='0' isHidden='0' isinit='1' usrinit='0' setinit='0' />
						<local name='quality' type='u8' description='' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<local name='angle' type='f32' description='' isconst='0' isHidden='0' isinit='1' usrinit='0.0' setinit='0' />
						<local name='distance' type='u16' description='' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<local name='y' type='s16' description='' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<local name='x' type='s16' description='' isconst='0' isHidden='0' isinit='1' usrinit='0' setinit='0' />
						<local name='dist' type='f32' description='' isconst='0' isHidden='0' isinit='0' usrinit='0.0' setinit='' />
						<local name='end_angle' type='f32' description='' isconst='0' isHidden='0' isinit='1' usrinit='0.0' setinit='0' />
						<local name='buf' type='u32' description='' isconst='0' isHidden='0' isinit='1' usrinit='0' setinit='0' />
						<local name='data' type='u32' description='' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<local name='rad' type='f32' description='' isconst='0' isHidden='0' isinit='0' usrinit='0.0' setinit='' />
						<local name='ct' type='u8' description='' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<local name='process_lap' type='b1' description='' isconst='0' isHidden='0' isinit='1' usrinit='1' setinit='true' />
						<local name='output' type='s16' description='' isconst='0' isHidden='0' isinit='1' usrinit='0' setinit='{0xAA55}' >
							<array size='512' />
						</local>
						<local name='out_pos' type='u32' description='' isconst='0' isHidden='0' isinit='1' usrinit='1' setinit='1' />
						<local name='lap_buf' type='u16' description='' isconst='0' isHidden='0' isinit='1' usrinit='0' setinit='{0xAA55, 0}' >
							<array size='2' />
						</local>
						<local name='lap_count' type='u32' description='' isconst='0' isHidden='0' isinit='1' usrinit='0' setinit='0' />
						<command class_type='loop' title='Loop' type='3' exp='1' >
							<flowline >
								<command class_type='native' title='Code' ccode='MX_UINT8 *buffer;  // Data buffer memory allocated by RxLIDAR
xQueueReceive(FCV_DATA_QUEUE, &amp;buffer, portMAX_DELAY);
FCL_CT = buffer[0];   // Get the block type
int idx = 8;' language='C' />
								<command class_type='decision' title='Start of &apos;rotation&apos; by LiDAR scanner' exp='.ct == 1' swap='0' >
									<flowline >
										<command class_type='calculation' title='Calculation' >
											<exp exp='.lap_count += 1' />
										</command>
										<command class_type='decision' title='Process alternate (or other) laps?' exp='(.lap_count % n_laps) == 0' swap='0' >
											<flowline >
												<command class_type='calculation' title='Calculation' >
													<exp exp='.process_lap = true' />
												</command>
												<command class_type='call' title='Component Macro' component='UART1' macro='SendINTArray' >
													<argument exp='.lap_buf' />
													<argument exp='2' />
													<argument exp='true' />
												</command>
											</flowline>
											<flowline >
												<command class_type='calculation' title='Calculation' >
													<exp exp='.process_lap = false' />
												</command>
											</flowline>
										</command>
									</flowline>
									<flowline >
										<command class_type='decision' title='Decision' exp='.process_lap' swap='0' >
											<flowline >
												<command class_type='native' title='Code' ccode='FCL_POINTS = buffer[1];    // Number of points in data
FCL_START_RAW = buffer[2] + (buffer[3] &lt;&lt; 8);
FCL_END_RAW = buffer[4] + (buffer[5] &lt;&lt; 8);
' language='C' />
												<command class_type='calculation' title='Calculation' >
													<exp exp='.start = (.start_raw &gt;&gt; 1) / 64.0' />
													<exp exp='.end = (.end_raw &gt;&gt; 1) / 64.0' />
													<exp exp='' />
												</command>
												<command class_type='calculation' title='Calculation' >
													<exp exp='.out_pos = 2 // Allowing for block header' />
												</command>
												<command class_type='decision' title='Get the difference between start and end angles - allowing for w' exp='.end &gt; .start' swap='0' >
													<flowline >
														<command class_type='calculation' title='Calculation' >
															<exp exp='.diff = .end - .start' />
														</command>
													</flowline>
													<flowline >
														<command class_type='calculation' title='Calculation' >
															<exp exp='.diff = .end + 360.0 - .start' />
														</command>
													</flowline>
												</command>
												<command class_type='calculation' title='Angle increment of each point' >
													<exp exp='.diff = .diff / (.points - 1)' />
												</command>
												<command class_type='loop' title='Process all the points in current block' type='2' forvar='.i' exp='.points' >
													<flowline >
														<command class_type='native' title='Code' ccode='FCL_DISTANCE = buffer[idx]; idx++;
FCL_DISTANCE += (buffer[idx] &lt;&lt; 8); idx++;' language='C' />
														<command class_type='calculation' title='Calculation' >
															<exp exp='.angle = .start + .diff * .i' />
														</command>
														<command class_type='decision' title='Has &apos;wrapped&apos; around?' exp='.angle &gt;= 360.0' swap='0' >
															<flowline >
																<command class_type='calculation' title='Calculation' >
																	<exp exp='.angle = .angle - 360.0' />
																</command>
															</flowline>
															<flowline />
														</command>
														<command class_type='decision' title='Maybe should be if distance &gt; min?' exp='.distance' swap='0' >
															<flowline >
																<command class_type='calculation' title='Calculation' >
																	<exp exp='.dist = .distance / 4.0' />
																	<exp exp='.rad = .angle * (3.1415926 / 180.0)' />
																	<exp exp='//.rad = .rad + CorrectionAngle(.dist)' />
																</command>
																<command class_type='calculation' title='Calculation' >
																	<exp exp='.x = .dist * cos(.rad)' />
																	<exp exp='.y = .dist * sin(.rad)' />
																</command>
																<command class_type='calculation' title='Buffer the ouput data' >
																	<exp exp='.output[.out_pos] = .x' />
																	<exp exp='.output[.out_pos + 1] = .y' />
																	<exp exp='.out_pos = .out_pos + 2' />
																</command>
															</flowline>
															<flowline />
														</command>
													</flowline>
												</command>
												<command class_type='calculation' title='Number of points (each is x,y - as XXXXYYYY)' >
													<exp exp='.output[1] = (.out_pos - 2) &gt;&gt; 1' />
												</command>
												<command class_type='call' title='Component Macro' component='UART1' macro='SendINTArray' >
													<argument exp='.output' />
													<argument exp='.out_pos' />
													<argument exp='true' />
												</command>
											</flowline>
											<flowline />
										</command>
									</flowline>
								</command>
								<command class_type='native' title='Free the data buffer memory' ccode='free(buffer);
' language='C' />
							</flowline>
						</command>
					</flowline>
				</macro>
				<macro >
					<flowline name='RxLIDAR' description='' statediag='0' >
						<return name='Return' type='v0' description='' isconst='0' isHidden='0' isinit='0' usrinit='' setinit='' />
						<param name='data' type='u8' description='' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<command class_type='switch' title='Switch' textarea='36,25,36,25' exp='state' >
							<case >
								<flowline />
							</case>
							<case exp='sync1' >
								<flowline >
									<command class_type='decision' title='Decision' exp='.data = 0xAA' swap='0' >
										<flowline >
											<command class_type='calculation' title='Calculation' >
												<exp exp='state = sync2' />
											</command>
										</flowline>
										<flowline />
									</command>
								</flowline>
							</case>
							<case exp='sync2' >
								<flowline >
									<command class_type='decision' title='Decision' exp='.data = 0x55' swap='0' >
										<flowline >
											<command class_type='calculation' title='Calculation' >
												<exp exp='state = header' />
												<exp exp='idx = 0' />
											</command>
										</flowline>
										<flowline >
											<command class_type='calculation' title='Calculation' >
												<exp exp='state = sync1' />
											</command>
										</flowline>
									</command>
								</flowline>
							</case>
							<case exp='header' >
								<flowline >
									<command class_type='calculation' title='Calculation' >
										<exp exp='data_header[idx] = .data' />
										<exp exp='idx += 1' />
									</command>
									<command class_type='decision' title='Decision' exp='idx &gt;= 8' swap='0' >
										<flowline >
											<command class_type='calculation' title='Calculation' >
												<exp exp='points = data_header[1] * 2' />
											</command>
											<command class_type='native' title='Code' ccode='FCV_BUFFER = (MX_UINT8*)malloc(FCV_POINTS + 12);
' language='C' />
											<command class_type='decision' title='Check for out of memory state' exp='buffer' swap='0' >
												<flowline >
													<command class_type='calculation' title='Calculation' >
														<exp exp='state = payload' />
														<exp exp='idx = 8' />
													</command>
													<command class_type='native' title='Code' ccode='memcpy(FCV_BUFFER, FCV_DATA_HEADER, 8);' language='C' />
												</flowline>
												<flowline >
													<command class_type='calculation' title='No memory - we&apos;ll drop data until next block' >
														<exp exp='state = sync1' />
													</command>
												</flowline>
											</command>
										</flowline>
										<flowline />
									</command>
								</flowline>
							</case>
							<case exp='payload' >
								<flowline >
									<command class_type='native' title='Code' ccode='((MX_UINT8*)FCV_BUFFER)[FCV_IDX] = FCL_DATA;' language='C' />
									<command class_type='calculation' title='Calculation' >
										<exp exp='idx += 1' />
									</command>
									<command class_type='decision' title='Decision' exp='idx &gt;= (points + 8)' swap='0' >
										<flowline >
											<command class_type='calculation' title='Calculation' >
												<exp exp='state = sync1' />
												<exp exp='' />
											</command>
											<command class_type='native' title='Push buffer to queue - if fails (pipeline stalled) - free memory' ccode='if(xQueueSend(FCV_DATA_QUEUE, &amp;FCV_BUFFER, 0) == pdFAIL) {
   free(FCV_BUFFER);
}' language='C' />
										</flowline>
										<flowline />
									</command>
								</flowline>
							</case>
						</command>
					</flowline>
				</macro>
				<macro >
					<flowline name='Main' description='' statediag='0' >
						<return name='Return' type='v0' description='' isconst='0' isHidden='0' isinit='0' usrinit='' setinit='' />
						<command class_type='call' title='Component Macro' component='UART1' macro='Initialise' />
						<command class_type='delay' title='Delay' exp='1' type='2' />
						<command class_type='native' title='Code' ccode='init_lidar_motor_pwm();   // Motor control PWM
set_lidar_rpm(0);         // Stop motor  
init_lidar_uart();        // Init the uart

// Create a queue and the tasks to work it
// Should pass queue as a parameter to the tasks - rather than make it a global
// We don&apos;t check for success
FCV_DATA_QUEUE = xQueueCreate(10, sizeof(MX_UINT32));
xTaskCreate(lidar_rx_task, &quot;RxLIDAR&quot;, 4096, NULL,5, NULL);
xTaskCreate(FCM_ProcessData, &quot;Process data&quot;, 4096, NULL, 10, &amp;FCV_PROCESSDATATASK);

lidar_tx(FCV_STOP, 2);' language='C' />
						<command class_type='delay' title='Allow time to spin down' exp='2' type='2' />
						<command class_type='native' title='Code' ccode='set_lidar_rpm(1000);
' language='C' />
						<command class_type='delay' title='Allow time to spin up' exp='2' type='2' />
						<command class_type='native' title='Send the &apos;start&apos; command' ccode='lidar_tx(FCV_START, 2);' language='C' />
						<command class_type='loop' title='Loop' type='3' exp='1' >
							<flowline >
								<command class_type='delay' title='Delay' exp='10' type='1' />
							</flowline>
						</command>
					</flowline>
				</macro>
			</macros>
			<component class_type='ref' guid='c73616d1-7ad0-45d9-aada-69ccfa4c5efc' vmin='0' vmaj='3' codename='UART1' panelId='0' x='115.548' y='-124' z='0' xsz='25.1778' ysz='25.1392' zsz='25' xang='0' yang='0' zang='0' xquat='0' yquat='0' zquat='0' wquat='1' visible='1' scadavisible='1' interactive='1' solid='1' layer='2' poslock='1' ancTop='0' ancBottom='0' ancLeft='0' ancRight='0' ancMinX='0' ancMinY='0' comp2dType='0' >
				<resources />
				<properties />
				<values >
					<value target='cal_uart::CHANNEL' data='001' />
					<value target='cal_uart::BAUD_LIST' data='000' />
					<value target='cal_uart::BAUD' data='921600' />
					<value target='cal_uart::DBITS' data='008' />
					<value target='cal_uart::RETURN' data='001' />
					<value target='cal_uart::ECHO' data='000' />
					<value target='cal_uart::UseTX' data='1' />
					<value target='cal_uart::TX' data='$PORTA.1' />
					<value target='cal_uart::OutputPins' data='000' />
					<value target='cal_uart::TXAlt' data='0' />
					<value target='cal_uart::UseRX' data='1' />
					<value target='cal_uart::RX' data='$PORTA.3' />
					<value target='cal_uart::InputPins' data='001' />
					<value target='cal_uart::RXAlt' data='0' />
					<value target='cal_uart::FLOWEN' data='000' />
					<value target='cal_uart::RTS' data='$PORTB.2' />
					<value target='cal_uart::CTS' data='$PORTB.1' />
					<value target='label' data='UART' />
					<value target='cal_uart::ScopeTraces' data='0' />
					<value target='cal_uart::ConsoleData' data='1' />
					<value target='cal_uart::ConsoleFormat' data='000' />
					<value target='cal_uart::ConsoleColumns' data='64' />
					<value target='cal_uart::DataSource' data='000' />
					<value target='cal_uart::com_port' data='000' />
					<value target='cal_uart::Injector' data='000' />
					<value target='cal_uart::APIUseDDR' data='' />
					<value target='cal_uart::APIDDRPin' data='' />
					<value target='cal_uart::APIDDRRXState' data='' />
					<value target='cal_uart::APIUseFC' data='' />
					<value target='cal_uart::APICTSPin' data='' />
					<value target='cal_uart::APIRTSPin' data='' />
				</values>
				<events />
				<apis />
				<variables />
				<macros />
			</component>
			<component class_type='ref' guid='444fb704-814c-4707-a15c-759ba088505c' vmin='0' vmaj='12' codename='PWM1' panelId='0' x='115.5' y='-125.5' z='1' xsz='25.18' ysz='24.9668' zsz='25' xang='0' yang='0' zang='0' xquat='0' yquat='0' zquat='0' wquat='1' visible='1' scadavisible='1' interactive='1' solid='1' layer='2' poslock='1' ancTop='0' ancBottom='0' ancLeft='0' ancRight='0' ancMinX='0' ancMinY='0' comp2dType='0' >
				<resources />
				<properties />
				<values >
					<value target='channel' data='001' />
					<value target='altpin' data='0' />
					<value target='pwm_pin' data='$PORTA.22' />
					<value target='RemapPin' data='024' />
					<value target='timer' data='000' />
					<value target='period' data='65535' />
					<value target='prescale' data='0' />
					<value target='period_calc' data='100.000000' />
					<value target='frequency_calc2' data='10000' />
					<value target='frequency_calc' data='10.000000' />
					<value target='pwm_prescale' data='1' />
					<value target='ReqFreq' data='100.000000' />
					<value target='OldReqFreq' data='100.000000' />
					<value target='CalcFreq' data='100.004570' />
					<value target='CalcPeriod' data='10936' />
					<value target='CalcScaler' data='64' />
					<value target='Apply' data='0' />
					<value target='ClockSpeed' data='240000000' />
					<value target='SimRep' data='000' />
					<value target='Family' data='ESP' />
					<value target='ModifiedConnection' data='A.22' />
					<value target='IsESP' data='1' />
				</values>
				<events />
				<apis />
				<variables />
				<macros />
			</component>
			<component class_type='ref' guid='cf22f60c-697e-4118-80a1-f29f5a80ed07' vmin='0' vmaj='1' codename='Notify1' panelId='0' x='122.5' y='-122.5' z='2' xsz='25' ysz='25' zsz='25' xang='0' yang='0' zang='0' xquat='0' yquat='0' zquat='0' wquat='1' visible='1' scadavisible='1' interactive='1' solid='1' layer='2' poslock='0' ancTop='0' ancBottom='0' ancLeft='0' ancRight='0' ancMinX='0' ancMinY='0' comp2dType='0' >
				<resources />
				<properties />
				<values />
				<events />
				<apis />
				<variables />
				<macros />
			</component>
		</component>
	</components>
	<scadaresourcelookup />
	<keymap />
	<panel2d shadows='0' lighting='2' brightness='0' >
		<background rgb='7292207' img='' style='0' />
		<camera xe='0' ye='0' ze='849.837' xt='0' yt='0' zt='0' xquat='0' yquat='0' zquat='0' wquat='1' />
		<viewport dx='310' dy='1383' zoom='44.1379' fix_topleft='0' />
		<page x='1000' y='1000' show='0' rgb='7360576' />
		<winpos ID='7005' RectRecentFloat='519,283,1169,733' RectRecentDocked='0,0,310,1433' RecentFrameAlignment='16384' RecentRowIndex='0' IsFloating='0' MRUWidth='32767' PinState='0' IsMaximized='0' IsVisible='0' />
	</panel2d>
	<panel3d shadows='0' lighting='2' brightness='0' perspective='1' >
		<background rgb='8409120' img='' style='0' />
		<table rgb='7360576' img='' style='0' size='0' />
		<camera xe='0' ye='0' ze='781.66' xt='0' yt='0' zt='0' xquat='0' yquat='0' zquat='0' wquat='1' />
		<camerakey0 xe='0' ye='0' ze='300' xt='0' yt='0' zt='0' xquat='0' yquat='0' zquat='0' wquat='1' />
		<camerakey1 xe='-3.67394e-14' ye='0' ze='-300' xt='0' yt='0' zt='0' xquat='0' yquat='1' zquat='0' wquat='6.12323e-17' />
		<camerakey2 xe='0' ye='-300' ze='6.66134e-14' xt='0' yt='0' zt='0' xquat='-0.707107' yquat='0' zquat='0' wquat='0.707107' />
		<camerakey3 xe='-3.67394e-14' ye='300' ze='6.66134e-14' xt='0' yt='0' zt='0' xquat='-4.32978e-17' yquat='0.707107' zquat='0.707107' wquat='4.32978e-17' />
		<camerakey4 xe='-300' ye='-6.66134e-14' ze='6.66134e-14' xt='0' yt='0' zt='0' xquat='-0.5' yquat='0.5' zquat='0.5' wquat='0.5' />
		<camerakey5 xe='300' ye='-6.66134e-14' ze='6.66134e-14' xt='0' yt='0' zt='0' xquat='-0.5' yquat='-0.5' zquat='-0.5' wquat='0.5' />
		<camerakey6 xe='-173.205' ye='-173.205' ze='173.205' xt='0' yt='0' zt='0' xquat='-0.424708' yquat='0.17592' zquat='0.339851' wquat='0.820473' />
		<winpos ID='7004' RectRecentFloat='551,299,1201,749' RectRecentDocked='0,0,546,1043' RecentFrameAlignment='16384' RecentRowIndex='0' IsFloating='0' MRUWidth='32767' PinState='0' IsMaximized='0' IsVisible='0' />
	</panel3d>
	<panels2d count='1' >
		<panel2d_0 id='0' name='2D Panel' type='0' >
			<winpos ID='1171' RectRecentFloat='2379,269,3029,719' RectRecentDocked='3198,328,3840,1727' RecentFrameAlignment='16384' RecentRowIndex='0' IsFloating='1' MRUWidth='32767' PinState='0' IsMaximized='0' IsVisible='0' />
			<background fill='288230376151053813' showgrid='1' gridstyle='1' gridsize='10' gridbrush='71776119075691740' snaptogrid='1' fitcomp='0' disp_x='300' disp_y='400' scale='100' disp_col='16777215' />
		</panel2d_0>
	</panels2d>
	<layout >
		<view type='0' name='RxLIDAR' mode='0' placement='LAAAAAAAAAABAAAA---------------------wUAAAAzAAAAugsAAJUGAAA' zoom='160' scrollx='72' scrolly='0' flags='0' />
		<view type='0' name='ProcessData' mode='0' placement='LAAAAAAAAAABAAAA---------------------wUAAAAzAAAAugsAAJUGAAA' zoom='190' scrollx='0' scrolly='2663' flags='0' />
		<view type='0' name='CorrectionAngle' mode='0' placement='LAAAAAAAAAABAAAA---------------------wUAAAAzAAAAugsAAJUGAAA' zoom='150' scrollx='0' scrolly='0' flags='0' />
	</layout>
</document>
</root>
