You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by "leducp (via GitHub)" <gi...@apache.org> on 2023/10/15 08:14:32 UTC

[PR] Add stepper example [nuttx-apps]

leducp opened a new pull request, #2118:
URL: https://github.com/apache/nuttx-apps/pull/2118

   ## Summary
   Add a stepper example.
   
   ## Impact
   
   ## Testing
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add stepper example [nuttx-apps]

Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 merged PR #2118:
URL: https://github.com/apache/nuttx-apps/pull/2118


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add stepper example [nuttx-apps]

Posted by "raiden00pl (via GitHub)" <gi...@apache.org>.
raiden00pl commented on PR #2118:
URL: https://github.com/apache/nuttx-apps/pull/2118#issuecomment-1764952674

   > Thank you for correction @raiden00pl
   In fact only the libs are there, the examples still in apps/examples. Maybe we could separate examples by type.
   
   good idea.  `examples/foc` is quite a large app now (and will be bigger) and it's more like the reference design of the FOC motor controller based on NuttX than just a simple example. So it should be moved somewhere else anyway. When I find a moment, I'll create and issue to discuss the problem.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add stepper example [nuttx-apps]

Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on PR #2118:
URL: https://github.com/apache/nuttx-apps/pull/2118#issuecomment-1770233112

   please rebase your patch, ci break is fixed with the recent patch.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add stepper example [nuttx-apps]

Posted by "acassis (via GitHub)" <gi...@apache.org>.
acassis commented on PR #2118:
URL: https://github.com/apache/nuttx-apps/pull/2118#issuecomment-1764916053

   > > @leducp I think it is a good idea to move this example to apps/industrial as there is already the foc/ example. Categorizing the example makes things easier to users.
   > 
   > that's not true :) `industrial/foc` is FOC library that can be used to build custom FOC applications. FOC example is still in `example/foc`
   
   Thank you for correction @raiden00pl
   In fact only the libs are there, the examples still in apps/examples. Maybe we could separate examples by type.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add stepper example [nuttx-apps]

Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on PR #2118:
URL: https://github.com/apache/nuttx-apps/pull/2118#issuecomment-1768584058

   @leducp please rebase your change, the ci break is fixed by: https://github.com/apache/nuttx-apps/pull/2131


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add stepper example [nuttx-apps]

Posted by "leducp (via GitHub)" <gi...@apache.org>.
leducp commented on code in PR #2118:
URL: https://github.com/apache/nuttx-apps/pull/2118#discussion_r1363480378


##########
examples/stepper/stepper.c:
##########
@@ -0,0 +1,151 @@
+/****************************************************************************
+ * apps/examples/stepper/stepper.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdbool.h>
+
+#include <nuttx/motor/stepper.h>
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+struct stepper_args
+{
+  FAR const char * path;
+  int microstep;
+  int speed;
+  int steps;
+};
+
+static int parse_args(int argc, FAR char *argv[],
+                      FAR struct stepper_args *args)
+{
+  if (argc < 3)
+    {
+      return -1;
+    }
+
+  args->path = argv[1];
+  args->microstep = -1;
+  args->speed = 200;
+
+  for (int i = 2; i < argc; ++i)

Review Comment:
   My bad, old habits



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add stepper example [nuttx-apps]

Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #2118:
URL: https://github.com/apache/nuttx-apps/pull/2118#discussion_r1359891267


##########
examples/stepper/stepper.c:
##########
@@ -0,0 +1,144 @@
+//***************************************************************************

Review Comment:
   change ALL // to c comment



##########
examples/stepper/CMakeLists.txt:
##########
@@ -0,0 +1,31 @@
+# ##############################################################################
+# apps/examples/stepper/CMakeLists.txt
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more contributor
+# license agreements.  See the NOTICE file distributed with this work for
+# additional information regarding copyright ownership.  The ASF licenses this
+# file to you under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License.  You may obtain a copy of
+# the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+# License for the specific language governing permissions and limitations under
+# the License.
+#
+# ##############################################################################
+
+if(CONFIG_EXAMPLES_HELLOXX)
+  nuttx_add_application(
+    NAME
+    stepper
+    STACKSIZE
+    ${CONFIG_DEFAULT_TASK_STACKSIZE}
+    MODULE
+    ${CONFIG_EXAMPLES_STEPPER}
+    SRCS
+    stepper_main.c)

Review Comment:
   ```suggestion
       stepper.c)
   ```



##########
examples/stepper/CMakeLists.txt:
##########
@@ -0,0 +1,31 @@
+# ##############################################################################
+# apps/examples/stepper/CMakeLists.txt
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more contributor
+# license agreements.  See the NOTICE file distributed with this work for
+# additional information regarding copyright ownership.  The ASF licenses this
+# file to you under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License.  You may obtain a copy of
+# the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+# License for the specific language governing permissions and limitations under
+# the License.
+#
+# ##############################################################################
+
+if(CONFIG_EXAMPLES_HELLOXX)

Review Comment:
   ```suggestion
   if(CONFIG_EXAMPLES_STEPPER)
   ```



##########
examples/stepper/Kconfig:
##########
@@ -0,0 +1,11 @@
+#
+# For a description of the syntax of this configuration file,
+# see the file kconfig-language.txt in the NuttX tools repository.
+#
+
+config EXAMPLES_STEPPER
+	tristate "Stepper controller test"
+	default n
+	depends on HAVE_CXX

Review Comment:
   remove



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add stepper example [nuttx-apps]

Posted by "acassis (via GitHub)" <gi...@apache.org>.
acassis commented on code in PR #2118:
URL: https://github.com/apache/nuttx-apps/pull/2118#discussion_r1360825996


##########
examples/stepper/stepper.c:
##########
@@ -0,0 +1,151 @@
+/****************************************************************************
+ * apps/examples/stepper/stepper.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdbool.h>
+
+#include <nuttx/motor/stepper.h>
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+struct stepper_args
+{
+  FAR const char * path;

Review Comment:
   ```suggestion
     FAR const char *path;



##########
examples/stepper/stepper.c:
##########
@@ -0,0 +1,151 @@
+/****************************************************************************
+ * apps/examples/stepper/stepper.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdbool.h>
+
+#include <nuttx/motor/stepper.h>
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+struct stepper_args
+{
+  FAR const char * path;
+  int microstep;
+  int speed;
+  int steps;
+};
+
+static int parse_args(int argc, FAR char *argv[],
+                      FAR struct stepper_args *args)
+{
+  if (argc < 3)
+    {
+      return -1;
+    }
+
+  args->path = argv[1];
+  args->microstep = -1;
+  args->speed = 200;
+
+  for (int i = 2; i < argc; ++i)
+    {
+      if (strncmp("-m", argv[i], 2) == 0)
+        {
+          i++;
+          if (i >= argc)
+            {
+              return -1;
+            }
+
+          args->microstep = atoi(argv[i]);
+          i++;
+        }
+
+      if (strncmp("-s", argv[i], 2) == 0)
+        {
+          i++;
+          if (i >= argc)
+            {
+              return -1;
+            }
+
+          args->speed = atoi(argv[i]);
+          i++;
+        }
+    }
+
+  args->steps = atoi(argv[argc - 1]);
+  return 0;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+int main(int argc, FAR char *argv[])
+{
+  struct stepper_args args;
+  struct stepper_status_s status;
+  struct stepper_job_s job;
+  int fd;
+  int rc;
+
+  if (parse_args(argc, argv, &args) < 0)
+    {
+      printf("usage:\n"
+            "stepper path\n"
+            "              [-m microstep (sticky)]\n"
+            "              [-s speed in steps/s (default 200)]\n"
+            "              steps (positive: CW, negative: CCW)\n");
+      return 1;
+    }
+
+  fd = open(args.path, O_RDWR);
+  if (fd < 0)
+    {
+      printf("Oops: %s\n", strerror(errno));
+      exit(1);
+    }
+
+  if (args.microstep > 0)
+    {
+      printf("Set microstepping to %d\n", args.microstep);
+      rc = ioctl(fd, STEPIOC_MICROSTEPPING, args.microstep);
+      if (rc < 0)
+        {
+          printf("STEPIOC_MICROSTEPPING: %s\n", strerror(errno));
+          exit(2);
+        }
+    }
+
+  job.steps = args.steps;
+  job.speed = args.speed;
+
+  printf("GO -> %ld @ %ld steps/s\n", job.steps, job.speed);
+
+  /* Move the stepper */
+
+  rc = write(fd, &job, sizeof(struct stepper_job_s)); /* blocking */
+  if (rc != sizeof(struct stepper_job_s))
+    {
+      printf("write: %s\n", strerror(errno));
+    }
+
+  /* Retrieve the absolute position since boot */
+
+  rc = read(fd, &status, sizeof(struct stepper_status_s));
+  if (rc != sizeof(struct stepper_status_s))
+    {
+      printf("read: %s\n", strerror(errno));
+    }
+
+  printf("Current position: %ld\n", status.position);

Review Comment:
   Maybe it could be interesting to print the: "Position before stepper motor moving: " and "Position after stepper motor moving: " for diagnostic purposes.



##########
examples/stepper/stepper.c:
##########
@@ -0,0 +1,151 @@
+/****************************************************************************
+ * apps/examples/stepper/stepper.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdbool.h>
+
+#include <nuttx/motor/stepper.h>
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+struct stepper_args
+{
+  FAR const char * path;
+  int microstep;
+  int speed;
+  int steps;
+};
+
+static int parse_args(int argc, FAR char *argv[],
+                      FAR struct stepper_args *args)
+{
+  if (argc < 3)
+    {
+      return -1;
+    }
+
+  args->path = argv[1];
+  args->microstep = -1;
+  args->speed = 200;
+
+  for (int i = 2; i < argc; ++i)

Review Comment:
   Please use C89, don't declare "i" in the for loop, declare it at begging of the function.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add stepper example [nuttx-apps]

Posted by "raiden00pl (via GitHub)" <gi...@apache.org>.
raiden00pl commented on PR #2118:
URL: https://github.com/apache/nuttx-apps/pull/2118#issuecomment-1764737245

   > @leducp I think it is a good idea to move this example to apps/industrial as there is already the foc/ example. Categorizing the example makes things easier to users.
   
   that's not true :) `industrial/foc` is FOC library that can be used to build custom FOC applications. FOC example is still in `example/foc`


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add stepper example [nuttx-apps]

Posted by "acassis (via GitHub)" <gi...@apache.org>.
acassis commented on PR #2118:
URL: https://github.com/apache/nuttx-apps/pull/2118#issuecomment-1764696936

   @leducp I think it is a good idea to move this example to apps/industrial as there is already the foc/ example. Categorizing the example makes things easier to users.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add stepper example [nuttx-apps]

Posted by "leducp (via GitHub)" <gi...@apache.org>.
leducp commented on PR #2118:
URL: https://github.com/apache/nuttx-apps/pull/2118#issuecomment-1770592133

   > please rebase your patch, ci break is fixed with the recent patch.
   
   done :)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org