tmirob-robot-status
v2.1.0
Published
Made with create-react-library
Downloads
104
Keywords
Readme
tmirob-robot-status
Made with create-react-library
Install
npm install --save tmirob-robot-status
Development
cd tmirob-robot-status
yarn install && yarn run start
cd example
yarn install && yarn run start
Usage
api
// robotApi
static getRobotStatusData(robotId) {
const url = `${Config.serverUrl}rest/details/getRobotSections?serialNo=${robotId}`;
return getApi(url);
}
demo
import React, {useState, useEffect} from 'react'
import TmirobRobotStatus from 'tmirob-robot-status'
import 'tmirob-robot-status/dist/index.css'
import robotsApi from '../../api/robotsApi'
const TestStatus = (props) => {
const [robotId, setRobotId] = useState('SN1901B12101')
const [robotInfo, setRobotInfo] = useState({})
const [basicInfo, setBasicInfo] = useState({})
const [pluginInfo, setPluginInfo] = useState({})
const [funcInfo, setFuncInfo] = useState({})
const [appStateInfo, setAppStateInfo] = useState({})
const mapStatusData = (statusData) => {
let resp = {}
Object.keys(statusData).forEach((key) => {
let data = statusData[key].map(item => {
return {
value: item.status,
abnormal: item.errorCode !== '',
abnormalMsg: item.msg
}
})
resp[key] = data
})
return resp
}
const mapAppStateData = (appState) => {
let resp = {}
if(!isEmpty(appState)){
Object.keys(appState).forEach((key) => {
let data = appState[key].map(item => {
return {
value: item.msg,
abnormal: item.status === 'error',
abnormalMsg: ''
}
})
resp[key] = data
})
}
return resp
}
useEffect(() => {
robotsApi.getRobotStatusData(robotId).then(res => {
if(res.retval === 0) {
const {basic_status, funtion_status,peripherals_status, Status } = res.result
const {robot_id,robotType,current_floor,current_position,collision,is_offline, ...basicRest} = basic_status
setRobotInfo({
robot_id: robot_id[0].status,
robotType: robotType[0].status,
current_floor: current_floor[0].status,
current_position: current_position[0].status,
is_crash: collision[0].status,
is_offline: is_offline[0].status,
})
let basicData = mapStatusData(basicRest)
basicData['battery_level'][0]['charging'] = basicRest.charging[0].status
basicData['rssi'][0]['ssid'] = basicRest.wifi_ssid[0].status
setBasicInfo(basicData)
let pluginData = mapStatusData(peripherals_status)
setPluginInfo(pluginData)
let moduleData = mapStatusData(funtion_status)
setFuncInfo(moduleData)
let stateData = mapAppStateData(Status)
setAppStateInfo(stateData)
}
})
},[robotId])
return (
<TmirobRobotStatus
goBack={() => console.log('goBack')}
robotInfo={robotInfo}
basicInfo={basicInfo}
pluginInfo={pluginInfo}
funcInfo={funcInfo}
appStateInfo={appStateInfo}
/>
)
}
export default TestStatus
Props
- robotInfo
const robotInfo = {
robot_id: 'SN1901B12101',
robotType: 'IdentityRobot',
current_floor: '第二层',
current_position: '1.0,2.0,2.3',
is_crash: 'true',
is_offline: 'false',
}
- basicInfo
const basicInfo = {
emergency_stop: [{
value: 'normal',
abnormal: false,
abnormalMsg: 'emergency stopped'
}],
paused: [{
value: 'normal',
abnormal: true,
abnormalMsg: '机器人被暂停'
}],
control_mode: [{
value: 'self_nav',
abnormal: false,
abnormalMsg: ''
}],
slave_connection: [{
value: 'normal',
abnormal: true,
abnormalMsg: '无法连接从机'
}],
// charging
battery_level: [{
charging: false,
value: '3',
abnormal: true,
abnormalMsg: '电量过低'
}],
charge_current: [{
value: '1000',
abnormal: false,
abnormalMsg: ''
}],
discharge_current: [{
value: '1000',
abnormal: false,
abnormalMsg: ''
}],
cpu_occupation: [{
value: '95',
abnormal: true,
abnormalMsg: 'CPU占用率过高'
}],
// ssid
rssi: [{
value: '3',
ssid: 'tmirob-5G',
abnormal: true,
abnormalMsg: '无线信号强度过低'
}],
linear_velocity: [{
value: '5.5',
abnormal: false,
abnormalMsg: ''
}],
cpu_temperature: [{
value: '70',
abnormal: true,
abnormalMsg: 'CPU占用率过高'
}],
}
- pluginInfo
const pluginInfo = {
lidar: [{
value: 'normal',
abnormal: false,
abnormalMsg: ''
}],
motor_control_driver: [{
// 同上,省略...
}],
agv_serial_board: [{
// ...
}],
main_control: [{
// ...
}],
sensor_driver: [{
// ...
}],
power_manager: [{
// ...
}],
auto_charging_ir: [{
// ...
}],
disinfecting_driver: [{
// ...
}],
motor_adapter: [{
// ...
}],
realsense: [{
value: 'normal',
abnormal: false,
abnormalMsg: ''
},{
value: 'normal',
abnormal: false,
abnormalMsg: ''
}]
}
- appStateInfo / funcInfo
const funcInfo = {
localization: [{
value: 'normal',
abnormal: false,
abnormalMsg: ''
}],
navigation: [{
// 同上,省略...
}],
map_server: [{
// ...
}]
}
Tips
- 机器人离线时显示的状态数据是最近一次的状态
- basicInfo下的机器人电量battery_level不只表示当前电量,还会显示是否为充电状态,由basic_status里的battery_level与charging共同控制。
- basicInfo下的wifi状态rssi不只表示 WiFi 强度(由basic_status里的rssi值决定),同时还可以显示 WiFi 名称(由basic_status里的wifi_ssid值决定)。