Powering a motor from a separate device's analog output

Hey All,

I have the following code. It is currently imcomplete and the step I am working on right now involves using an analog signal from another device to move a linear actuator. The analog value is called travel_val and the motor moves using the move_pos function. When I plug it in nothing moves. I think this is due to the rapidly changing analog value. How do I narrow that value down? It could also be because I am trying to read two analog values.
links to individual parts

linear actuator

dynamixel shield

UR-10E robot
https://www.universal-robots.com/download/manuals-e-series/user/ur10e/59/user-manual-ur10e-e-series-sw-59-english-international-en/

power hub board
https://www.reichelt.com/be/en/dynamixel-u2d2-power-hub-u2s2-phb-p263262.html?&nbc=1

#include "CytronMotorDriver.h"
 #include <DynamixelShield.h>
const float DXL_PROTOCOL_VERSION = 2.0;
const uint8_t Pan_Motor = 1;
const uint8_t Left_Tilt = 2;
const uint8_t Right_Tilt = 3; 
CytronMD motor(PWM_DIR, 3, 4);  // PWM = Pin 3, DIR = Pin 4.
DynamixelShield dxl;

//relay variables
int relay=8;
volatile byte relayState = LOW;

// connect to ur10e
int UR10pin = A2;
int travel_val = analogRead(UR10pin);

// potentiometer variables
int analogPin = A0; // potentiometer wiper (middle terminal) connected to analog pin 3
int pos_val = 0;  // variable to store the value read
int sum = 0;
int dead_zone = 2;
//int max_extend = 670; //not used
//int max_retract = 358; // not used
//int travel_val =511; // analog val read from ur10e control box

int current_speed(int curr_dist, int max_speed){
  int curr_speed = 8*abs(curr_dist);
  if (curr_speed > max_speed) {
    curr_speed = max_speed;
  }
  return curr_speed;
}

void move_pos(int travel_val){

  sum = 0; //for loop to average results of analog reading due to deviation in resistance
  int act_speed =0;
  /*
  if (abs(travel_val-pos_val) <= 17){
      act_speed=112;
    }
  else{
    act_speed=225;
  }
  */
 
  for (int i=0; i<15; i = i+1){
    sum += analogRead(analogPin);
    }
  pos_val=sum/15;

  act_speed = current_speed(abs(511-pos_val), 225);
  
  if (pos_val  <=  travel_val && pos_val >= travel_val)
  {motor.setSpeed(0);}
  else if (travel_val<pos_val - dead_zone)
  {motor.setSpeed(act_speed);}
  else if (travel_val>pos_val + dead_zone)
  {motor.setSpeed(-act_speed);}
  }


  



void setup() {// put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(relay, OUTPUT);
  dxl.begin(1000000);//begin communication to motors,Trossen set baud rate to 1000000
  dxl.ping(Pan_Motor);// get motor info
  dxl.ping(Left_Tilt);
  dxl.ping(Right_Tilt);

  dxl.torqueOff(Pan_Motor);
  dxl.setOperatingMode(Pan_Motor, OP_POSITION);
  dxl.torqueOn(Pan_Motor);

  dxl.torqueOff(Left_Tilt);
  dxl.setOperatingMode(Left_Tilt, OP_POSITION);
  dxl.torqueOn(Left_Tilt);
  
  dxl.torqueOff(Right_Tilt);
  dxl.setOperatingMode(Right_Tilt, OP_POSITION);
  dxl.torqueOn(Right_Tilt);
}

void loop() {
  
move_pos(travel_val);
}

Show us a good schematic of your proposed circuit.
Show us a good image of your ‘actual’ wiring.
Give links to components.

attached a rough outline of my wiring. I've doubled check that every thing is in the pin positions that are shown.

Your sketch says 3 is PWM, 4 is direction.

The diagram is the opposite.

No such attachment to be seen! :roll_eyes: Where is it?

I am not sure if your code will run correctly; the underlying main() function may not have initialised the ADC as of this line of code.
In addition, I do not see any other reading of the UR10 pin value. You may want to move this line to loop:

travel_val = analogRead(UR10pin);

Perhaps simplify this?

the pins were in the correct pins on the robot just flipped in the diagram

apologies, the attachment is now in the post.

I am sorry, I cannot see anything resembling what @LarryD requested in #2. :roll_eyes:

oh you mean the picture. I was confused because the wiring diagram was already up. The wiring is a little messy at the moment. Coming out of the snake skin wrapping is the actuator power ground and the 3 wires for the potentiometer.

Well, it's a little difficult to see much on that blurry picture.

Larry asked for a schematic diagram (and we do not particularly like "Fritzing" pictorials) detailing the connections to the various parts, and a specification (Web links) of the parts - other than the UNO which we well know.

Otherwise we cannot know what each part requires to operate.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.