事前に Detector model が使用するロールを作成します。
IAM にて、この Detectior model から AWS IoT Core の MQTT トピックに Publish できるように、以下のポリシーを持つロールを作成します。ここではロール名を role-0001 とします。
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "iot:Publish",
"Resource": "arn:aws:iot:ap-northeast-1:<account_id>:topic/notification"
}
]
}
Detector models で Action から「Import detector model」を選択し、以下のモデル Squat_challenge をインポートします。
{
"detectorModelDefinition": {
"states": [
{
"stateName": "Ready",
"onInput": {
"events": [],
"transitionEvents": [
{
"eventName": "Down",
"condition": "$input.pose_input.pos.left_hip.y > $input.pose_input.pos.left_knee.y",
"actions": [
{
"setVariable": {
"variableName": "cnt",
"value": "$variable.cnt + 1"
}
}
],
"nextState": "SquatDown"
},
{
"eventName": "RightHandUp",
"condition": "$input.pose_input.pos.right_elbow.y < $input.pose_input.pos.nose.y ",
"actions": [],
"nextState": "CounterReset"
},
{
"eventName": "TimeUp",
"condition": "timeout(\"timer\")",
"actions": [],
"nextState": "Done"
}
]
},
"onEnter": {
"events": [
{
"eventName": "Message",
"condition": "true",
"actions": [
{
"setVariable": {
"variableName": "msg",
"value": "\"👏 頑張りましょう!\""
}
}
]
},
{
"eventName": "TimeStamp",
"condition": "true",
"actions": [
{
"setVariable": {
"variableName": "ts",
"value": "$input.pose_input.ts"
}
}
]
},
{
"eventName": "Timer",
"condition": "true",
"actions": [
{
"setTimer": {
"timerName": "timer",
"seconds": 60,
"durationExpression": null
}
}
]
},
{
"eventName": "Notification",
"condition": "true",
"actions": [
{
"iotTopicPublish": {
"mqttTopic": "notification"
}
}
]
}
]
},
"onExit": {
"events": []
}
},
{
"stateName": "SquatDown",
"onInput": {
"events": [],
"transitionEvents": [
{
"eventName": "Up",
"condition": "$input.pose_input.pos.left_hip.y < $input.pose_input.pos.left_knee.y",
"actions": [],
"nextState": "Ready"
},
{
"eventName": "Bad",
"condition": "$input.pose_input.pos.left_wrist.y - $input.pose_input.pos.left_shoulder.y > 10 || $input.pose_input.pos.left_knee.y - $input.pose_input.pos.left_shoulder.y < 10",
"actions": [
{
"setVariable": {
"variableName": "bct",
"value": "$variable.bct + 1"
}
}
],
"nextState": "BadPose"
}
]
},
"onEnter": {
"events": [
{
"eventName": "Message",
"condition": "true",
"actions": [
{
"setVariable": {
"variableName": "msg",
"value": "\"💪🏼 いいフォームです!\""
}
}
]
},
{
"eventName": "TimeStamp",
"condition": "true",
"actions": [
{
"setVariable": {
"variableName": "ts",
"value": "$input.pose_input.ts"
}
}
]
},
{
"eventName": "Notification",
"condition": "true",
"actions": [
{
"iotTopicPublish": {
"mqttTopic": "notification"
}
}
]
}
]
},
"onExit": {
"events": []
}
},
{
"stateName": "BadPose",
"onInput": {
"events": [],
"transitionEvents": [
{
"eventName": "Good",
"condition": "$input.pose_input.pos.left_wrist.y - $input.pose_input.pos.left_shoulder.y < 10 && $input.pose_input.pos.left_knee.y - $input.pose_input.pos.left_shoulder.y > 10",
"actions": [],
"nextState": "SquatDown"
}
]
},
"onEnter": {
"events": [
{
"eventName": "Message",
"condition": "true",
"actions": [
{
"setVariable": {
"variableName": "msg",
"value": "\"👎 フォームが崩れています\""
}
}
]
},
{
"eventName": "TimeStamp",
"condition": "true",
"actions": [
{
"setVariable": {
"variableName": "ts",
"value": "$input.pose_input.ts"
}
}
]
},
{
"eventName": "Notification",
"condition": "true",
"actions": [
{
"iotTopicPublish": {
"mqttTopic": "notification"
}
}
]
}
]
},
"onExit": {
"events": []
}
},
{
"stateName": "CounterReset",
"onInput": {
"events": [],
"transitionEvents": [
{
"eventName": "RightHandDown",
"condition": "$input.pose_input.pos.right_elbow.y > $input.pose_input.pos.nose.y ",
"actions": [],
"nextState": "Ready"
}
]
},
"onEnter": {
"events": [
{
"eventName": "TimeStamp",
"condition": "true",
"actions": [
{
"setVariable": {
"variableName": "ts",
"value": "$input.pose_input.ts"
}
}
]
},
{
"eventName": "Counter",
"condition": "true",
"actions": [
{
"setVariable": {
"variableName": "cnt",
"value": "0"
}
},
{
"setVariable": {
"variableName": "bct",
"value": "0"
}
}
]
},
{
"eventName": "Message",
"condition": "true",
"actions": [
{
"setVariable": {
"variableName": "msg",
"value": "\"👌 カウントをリセットします\""
}
}
]
},
{
"eventName": "Notification",
"condition": "true",
"actions": [
{
"iotTopicPublish": {
"mqttTopic": "notification"
}
}
]
}
]
},
"onExit": {
"events": []
}
},
{
"stateName": "Done",
"onInput": {
"events": [],
"transitionEvents": [
{
"eventName": "LeftHandUp",
"condition": "$input.pose_input.pos.left_elbow.y < $input.pose_input.pos.nose.y",
"actions": [],
"nextState": "Ready"
}
]
},
"onEnter": {
"events": [
{
"eventName": "Message",
"condition": "true",
"actions": [
{
"setVariable": {
"variableName": "msg",
"value": "\"🙌 おつかれさまでした!\""
}
}
]
},
{
"eventName": "TimeStamp",
"condition": "true",
"actions": [
{
"setVariable": {
"variableName": "ts",
"value": "$input.pose_input.ts"
}
}
]
},
{
"eventName": "Notification",
"condition": "true",
"actions": [
{
"iotTopicPublish": {
"mqttTopic": "notification"
}
}
]
}
]
},
"onExit": {
"events": []
}
},
{
"stateName": "CounterInit",
"onInput": {
"events": [],
"transitionEvents": [
{
"eventName": "Start",
"condition": "true",
"actions": [],
"nextState": "Ready"
}
]
},
"onEnter": {
"events": [
{
"eventName": "InitCounter",
"condition": "true",
"actions": [
{
"setVariable": {
"variableName": "cnt",
"value": "0"
}
},
{
"setVariable": {
"variableName": "bct",
"value": "0"
}
}
]
}
]
},
"onExit": {
"events": []
}
}
],
"initialStateName": "CounterInit"
},
"detectorModelDescription": "Remove variable cal",
"detectorModelName": "Squat_challenge",
"evaluationMethod": "SERIAL",
"key": null,
"roleArn": "arn:aws:iam::<account_id>:role/service-role/role-0001"
}