OpenEL 3.0.0

sample.c
Go to the documentation of this file.
1
12 /*
13
14 Copyright (c) 2017, Japan Embedded Systems Technology Association(JASA)
15 All rights reserved.
16
17 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
18
19 Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
20 Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
21 Neither the name of the Association nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25 #include "openEL.h"
26 #include <stdint.h>
27 #include <stdlib.h>
28 #include <stdio.h>
29 #include <unistd.h>
30
31 void motor_notify_event(HALCOMPONENT_T *halComponent, int32_t event_id)
32 {
33 printf("motor_notify_event\n");
34 // printf("vendorId=%x productId=%x instanceId=%x event_id=%d\n", halId.vendorId, halId.productId, halId.instanceId, event_id);
35 }
36
37 void motor_notify_error(HALCOMPONENT_T *halComponent, int32_t error_id)
38 {
39 printf("motor_notify_error\n");
40 // printf("vendorId=%x productId=%x instanceId=%x error_id=%d\n", halId.vendorId, halId.productId, halId.instanceId, error_id);
41 }
42
43 void motor_notify_timer(EVENTTIMER_T *eventTimer)
44 {
45 printf("motor_notify_timer\n");
46 }
47
48 int main()
49 {
50 HALCOMPONENT_T motor_1;
51 // HALCOMPONENT_T motor_2;
52 // POSITIONCONTROLACTUATOR_T motor_1;
53 // VELOCITYCONTROLACTUATOR_T motor_2;
54 // TORQUECONTROLACTUATOR_T motor_3;
55 HALCOMPONENT_T sensor_1;
56 // TORQUESENSOR sensor_1;
57 /* 初期設定 */
58 motor_1.positionControlActuator.halId.deviceKindId=0x00000010;
59 motor_1.positionControlActuator.halId.vendorId=0x00000000;
60 motor_1.positionControlActuator.halId.productId=0x12345678;
61 motor_1.positionControlActuator.halId.instanceId=0x00000001;
62
63 // motor_1.halId.deviceKindId=0x00000010;
64 // motor_1.halId.vendorId=0x00000000;
65 // motor_1.halId.productId=0x12345678;
66 // motor_1.halId.instanceId=0x00000001;
67
68 // motor_2.halId.deviceKindId=0x00000010;
69 // motor_2.halId.vendorId=0x00000000;
70 // motor_2.halId.productId=0x12345678;
71 // motor_2.halId.instanceId=0x00000002;
72
73 sensor_1.torqueSensor.halId.deviceKindId=0x00000020;
74 sensor_1.torqueSensor.halId.vendorId=0x00000000;
75 sensor_1.torqueSensor.halId.productId=0x80000001;
76 sensor_1.torqueSensor.halId.instanceId=0x00000001;
77
78 HALOBSERVER_T motor_1_observer_1;
79 motor_1_observer_1.notify_event = motor_notify_event;
80 motor_1_observer_1.notify_error = motor_notify_error;
81 // HalAddObserver(&motor_1.halComponent, &motor_1_observer_1);
82
83 TIMEROBSERVER_T timerObserver_1;
84 timerObserver_1.notify_timer = motor_notify_timer;
85
86 EVENTTIMER_T eventTimer_1;
87 // HalEventTimerAddObserver(&eventTimer_1, &timerObserver_1);
88 // HalEventTimerSetEventPeriod(&eventTimer_1, 100);
89 // HalEventTimerStartTimer(&eventTimer_1);
90
91 // if(HAL_OK == HalInit((HALCOMPONENT*)&motor_1))
92 if(HAL_OK == HalInit(&motor_1))
93 printf("HAL_OK\n");
94 else
95 printf("HAL_ERROR\n");
96 #if 0
97 if(HAL_OK == HalInit(&motor_2))
98 printf("HAL_OK\n");
99 else
100 printf("HAL_ERROR\n");
101 #endif
102 if(HAL_OK == HalInit(&sensor_1))
103 printf("HAL_OK\n");
104 else
105 printf("HAL_ERROR\n");
106 #if 0
107 if(HAL_OK == HalReInit(&motor_1))
108 printf("HAL_OK\n");
109 else
110 printf("HAL_ERROR\n");
111 #endif
112 float32_t position=123;
113 float32_t value=0;
114 int32_t timer_value=0;
115
116 if(HAL_OK == HalSetPosition(&motor_1, position))
117 printf("HAL_OK\n");
118 else
119 printf("HAL_ERROR\n");
120
121 if(HAL_OK == HalGetPosition(&motor_1, &position))
122 printf("HAL_OK\n");
123 else
124 printf("HAL_ERROR\n");
125
126 printf("position=%f\n", position);
127 #if 0
128 if(HAL_OK == HalFinalize(&motor_1))
129 printf("HAL_OK\n");
130 else
131 printf("HAL_ERROR\n");
132 #endif
133 if(HAL_OK == HalTorqueSensorGetValue(&sensor_1, &value))
134 printf("HAL_OK\n");
135 else
136 printf("HAL_ERROR\n");
137 printf("value=%f\n", value);
138
139 if(HAL_OK == HalTorqueSensorGetTimedValue(&sensor_1, &value, &timer_value))
140 printf("HAL_OK\n");
141 else
142 printf("HAL_ERROR\n");
143 printf("value=%f, timer_value=%d\n", value, timer_value);
144
145 #if 0
146 if(HAL_OK == HalFinalize(&motor_1.halComponent)) /* 2回コールした場合 */
147 printf("HAL_OK\n");
148 else
149 printf("HAL_ERROR\n");
150 #endif
151 /*
152 float32_t xyz[3]={10,20,30};
153 if(HAL_OK == motor_1.SynchronizedSetPosition(xyz))
154 printf("HAL_OK\n");
155 else
156 printf("HAL_ERROR\n");
157
158 if(HAL_OK == motor_1.SynchronizedGetPosition(&xyz[0]))
159 printf("HAL_OK\n");
160 else
161 printf("HAL_ERROR\n");
162
163 printf("position_x = %f\n", xyz[0]);
164 printf("position_y = %f\n", xyz[1]);
165 printf("position_z = %f\n", xyz[2]);
166
167 if(HAL_OK == motor_1.ReInit())
168 printf("HAL_OK\n");
169 else
170 printf("HAL_ERROR\n");
171
172 if(HAL_OK == motor_1.Finalize())
173 printf("HAL_OK\n");
174 else
175 printf("HAL_ERROR\n");
176
177 if(HAL_OK == sensor_1.Init())
178 printf("HAL_OK\n");
179 else
180 printf("HAL_ERROR\n");
181
182 if(HAL_OK == sensor_1.Start())
183 printf("HAL_OK\n");
184 else
185 printf("HAL_ERROR\n");
186
187 float32_t value[3];
188 int32_t t;
189 if(HAL_OK == sensor_1.GetTimedValue(&value[0], &t))
190 printf("HAL_OK\n");
191 else
192 printf("HAL_ERROR\n");
193 printf("value[0]=%f, time=%d\n", value[0], t);
194
195 if(HAL_OK == sensor_1.Stop())
196 printf("HAL_OK\n");
197 else
198 printf("HAL_ERROR\n");
199
200 if(HAL_OK == sensor_1.Finalize())
201 printf("HAL_OK\n");
202 else
203 printf("HAL_ERROR\n");
204 */
205 exit(EXIT_SUCCESS);
206 }
HALObserver::notify_error
void(* notify_error)(HALCOMPONENT_T *halComponent, int32_t error_id)
Definition: openEL.h:75
HalSetPosition
enum ReturnCode HalSetPosition(HALCOMPONENT_T *positionControlActuator, halfloat position)
Definition: openEL_motor.c:41
value
halfloat value
Definition: openEL_0000000080000001.c:72
openEL.h
OpenEL Common Header File 3.0.0.
motor_notify_timer
void motor_notify_timer(EVENTTIMER_T *eventTimer)
Definition: sample.c:43
HalTorqueSensorGetTimedValue
enum ReturnCode HalTorqueSensorGetTimedValue(HALCOMPONENT_T *torqueSensor, halfloat *list, int32_t *timer)
Definition: openEL_sensor.c:46
HALObserver
Definition: openEL.h:73
float32_t
float float32_t
Definition: openEL.h:50
HalTorqueSensorGetValue
enum ReturnCode HalTorqueSensorGetValue(HALCOMPONENT_T *torqueSensor, halfloat *list)
Definition: openEL_sensor.c:30
motor_notify_error
void motor_notify_error(HALCOMPONENT_T *halComponent, int32_t error_id)
Definition: sample.c:37
HalGetPosition
enum ReturnCode HalGetPosition(HALCOMPONENT_T *positionControlActuator, halfloat *position)
Definition: openEL_motor.c:69
HalInit
enum ReturnCode HalInit(HALCOMPONENT_T *halComponent)
Definition: openEL.c:75
main
int main()
Definition: sample.c:48
HalComponent
Definition: openEL.h:162
HalFinalize
enum ReturnCode HalFinalize(HALCOMPONENT_T *halComponent)
Definition: openEL.c:130
TimerObserver::notify_timer
void(* notify_timer)(EVENTTIMER_T *eventTimer)
Definition: openEL.h:102
motor_notify_event
void motor_notify_event(HALCOMPONENT_T *halComponent, int32_t event_id)
Definition: sample.c:31
HAL_OK
Definition: openEL.h:45
HalComponent::positionControlActuator
POSITIONCONTROLACTUATOR_T positionControlActuator
Definition: openEL.h:164
HalReInit
enum ReturnCode HalReInit(HALCOMPONENT_T *halComponent)
Definition: openEL.c:114
TimerObserver
Definition: openEL.h:101
EventTimer
Definition: openEL.h:105
HalComponent::torqueSensor
TORQUESENSOR_T torqueSensor
Definition: openEL.h:167
HALObserver::notify_event
void(* notify_event)(HALCOMPONENT_T *halComponent, int32_t event_id)
Definition: openEL.h:74