Asked

Smooth Start Of The Servo Movements When Starting ARC

Is there a standard solution in ARC to slowly move the robot servos to an initial position when the ARC program starts?

Especially with larger robots, switching on puts a lot of dynamic load on the servos and puts a strain on the entire mechanics of the robot.

If there is no standard solution available, how could integrate a Python or a Java script to do this job?


Related Hardware EZ-B v4

ARC Pro

Upgrade to ARC Pro

Elevate your robot's capabilities to the next level with Synthiam ARC Pro, unlocking a world of possibilities in robot programming.

PRO
Canada
#25  

To create a JavaScript program that generates a random number and prints a greeting in different languages without using else-if statements, you can use an object to map numbers to functions that print the corresponding greeting. Here's an example of how you might write such a program using reusable subroutines:

// Define the greetings as functions
function helloWorld() {
  console.log("Hello World");
}

function bonjourWorld() {
  console.log("Bonjour World");
}

function gdayWorld() {
  console.log("G'day World");
}

function gutenTagWorld() {
  console.log("Guten Tag World");
}

function alohaWorld() {
  console.log("Aloha World");
}

// Create an object that maps numbers to functions
const greetings = {
  1: helloWorld,
  2: bonjourWorld,
  3: gdayWorld,
  4: gutenTagWorld,
  5: alohaWorld
};

// Generate a random number between 1 and 5
function getRandomNumber(min, max) {
  return Math.floor(Math.random() * (max - min + 1)) + min;
}

// Main function to execute the greeting
function executeRandomGreeting() {
  const randomNumber = getRandomNumber(1, 5);
  const greetingFunction = greetings[randomNumber];
  
  if (greetingFunction) {
    greetingFunction(); // Call the corresponding greeting function
  }
}

// Run the program
executeRandomGreeting();

In this program, we define each greeting as a separate function. We then create an object called greetings that maps numbers to these functions. The executeRandomGreeting function generates a random number and uses it to look up and call the corresponding greeting function from the greetings object. This approach avoids the need for else-if statements by using a data structure to handle the conditional logic.


I am a customer support GPT-powered AI and still learning. If you have doubts about my response, please use the support documentation to verify my answer.
PRO
Canada
#26  

Basic was such a simple language. My computer only had 1K of RAM so I would have done something like this.

10 gosub int(rnd(5)*100)
20 end
100 print hello world
110 return
200 print gday world
210 return
300 .
PRO
Synthiam
#27   — Edited

Wow because you said no IF conditions, they made really complicated responses. But what I don’t understand in this conversation is why are you removing IF conditions? Even basic has IF conditions. And ezscript only has IF conditions.

Dave’s question was how to goto and return from a thing. That’s what a function or method does.


while(true) { 

If (x == 1)
  doOne();
else
  doTwo();

}

function doOne(){
 print(one);
}

function doTwo() {
 print(two)
}

by removing IF conditions, you’re having to use switch/case or assign functions to values - like Athena mentioned and that makes the code really difficult for beginners.

PRO
Canada
#28  

Sorry I don’t know JavaScript so I was going with logic I understand. I didn’t think a long list of If then was what he was looking for as he wanted to create a bunch of seperate routines and call them when needed.  If I understand it Function looks like it solves Dave’s problem so he can just call the appropriate function for a routine instead of a goto.

PRO
Synthiam
#29  

You got it! And python I think is more like ezscript. I think python functions are kind of the same but easier to understand. Python seems to be the language that people prefer to learn programming.

@athena teach us how to program with python. Explain the basics of how to format code, use if, loops and functions

PRO
Canada
#30  

Certainly! Python is a high-level, interpreted programming language known for its readability and straightforward syntax. It's a great language for beginners and is widely used for web development, data analysis, artificial intelligence, and more. Here's a brief overview of Python's basic constructs:

1. Code Formatting: Python uses indentation to define code blocks, rather than curly braces {} as in languages like C or Java. Each level of indentation defines a new block of code. It's standard practice to use 4 spaces per indentation level.

# Correct indentation
if condition:
    # This is a new block of code
    do_something()

2. Variables: Variables in Python are created when you assign a value to them. Python is dynamically typed, which means you don't need to declare the variable type.

x = 10          # An integer assignment
y = "Hello"     # A string assignment

3. If Statements: The if statement is used to test a condition and execute a block of code if the condition is true.

if x < 10:
    print("x is less than 10")
elif x == 10:
    print("x is exactly 10")
else:
    print("x is greater than 10")

4. Loops: Python has two primitive loop commands: for loops and while loops.

  • for loops iterate over a sequence (like a list, tuple, dictionary, set, or string).
# Iterate over a list
for item in [1, 2, 3, 4, 5]:
    print(item)
  • while loops repeat as long as a certain boolean condition is met.
# Continue until x becomes 5
x = 0
while x < 5:
    print(x)
    x += 1

5. Functions: Functions are blocks of reusable code that perform a specific task. You define a function using the def keyword.

# Define a function
def say_hello(name):
    print(f"Hello, {name}!")

# Call the function
say_hello("Alice")

6. Importing Modules: Python has a large standard library, and you can use import to add modules to your script.

import math
print(math.sqrt(16))  # Prints the square root of 16

Remember, Python is case-sensitive, so Variable and variable are two different identifiers. Also, Python uses # for comments.

This is just a very basic introduction to Python. There's much more to learn, including list comprehensions, error handling with try and except, working with files, and more. There are many resources available to learn Python, including the official Python documentation, online courses, and interactive tutorials.


I am a customer support GPT-powered AI and still learning. If you have doubts about my response, please use the support documentation to verify my answer.
#31  

Wow, thanks guys. I'll study all this and give it all a bunch of thought. I really want to move towards JS or Python. That script I mentioned has been a real sticking point for me to move into JS.

Maybe when I get into the meat of converting that script I'll post it in another thread and show my progress. I'm sure I'll be asking for help.

Thanks again!

PRO
Synthiam
#32  

Post it in another thread. I wanna see. Wonder if Athena can rewrite it